unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* generic buffer parsing cache data
@ 2007-06-30 21:38 Paul Pogonyshev
  2007-07-01 11:48 ` martin rudalics
  0 siblings, 1 reply; 19+ messages in thread
From: Paul Pogonyshev @ 2007-06-30 21:38 UTC (permalink / raw)
  To: emacs-devel

[ I'm not sure this topic was not discussed yet.  Still, I haven't
  seen this in any of the modes. ]

I propose adding a generic way of caching different kinds of parse
data in a buffer.  Purpose is to speed up parsing when it requires
long trip back in a buffer, by reusing previous results.  And to make
this generic enough, so that modes don't have to reinvent the wheel.

For instance, in `python-indentation-levels' I see:

	  (while (python-beginning-of-block)
	    ...)

This means each time `python-indentaton-levels' is called, it will
temporarily travel back in the buffer until it reaches a block
starting in the first column (toplevel block.)  This is not exactly
fast.  Especially in major modes that need to parse something more
difficult than Python syntax.

I propose that each point position could have "cached parsing data".
This would be an alist indexed with cache data identifier.  For
instance, Python mode could add sth. like

	'python-mode . (def "foo" (8 4 0))

after each line starting a block.  This means block type (def, class,
maybe other types if interesting to the mode), block name if
applicable, and indentation levels.  Then `python-indentation-levels'
could be like this (in pseudocode):

	python-beginning-of-block
	forward-line
	python-ensure-cache-data
	return 3rd element of cache-data

where `python-ensure-cache-data' would be like

	if there is cache data, just return
	else:
	    travel to previous block
	    python-ensure-cache-data
	    build cache data for this block based on the previous

We can either reuse text property machinery or invent something else
for storing cache data.  Difference of cache data is that it should
be automatically invalidated (by Emacs core, without major mode
interaction) from point position X onwards when text at X changes.
Thus, modes can be confident, that if there is some cached data at
some point Y, then it was computed with exactly the same text from
points 0 to Y.

With normal flow of work, when you navigate to some function and
start typing or editing code in it, there will be cache hits for
everything above that functions.  So, reparsing will be needed only
of the function itself, not of anything above.

Does this sound as a good idea?  Is it worth developing it in
more details?  Or even starting with sample code?

Paul

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2007-07-01 21:23 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-30 21:38 generic buffer parsing cache data Paul Pogonyshev
2007-07-01 11:48 ` martin rudalics
2007-07-01 12:16   ` Paul Pogonyshev
2007-07-01 12:38     ` martin rudalics
2007-07-01 13:41       ` Paul Pogonyshev
2007-07-01 15:20         ` martin rudalics
2007-07-01 20:40         ` Richard Stallman
2007-07-01 12:45     ` Thien-Thi Nguyen
2007-07-01 13:10       ` Paul Pogonyshev
2007-07-01 13:16         ` Lennart Borgman (gmail)
2007-07-01 13:43           ` Paul Pogonyshev
2007-07-01 13:28       ` joakim
2007-07-01 12:52     ` Stefan Monnier
2007-07-01 13:49       ` Paul Pogonyshev
2007-07-01 20:08         ` Stefan Monnier
2007-07-01 20:44           ` Paul Pogonyshev
2007-07-01 21:23             ` Stefan Monnier
2007-07-01 16:32     ` Richard Stallman
2007-07-01 16:32     ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).