From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: generic buffer parsing cache data Date: Sun, 1 Jul 2007 00:38:22 +0300 Message-ID: <200707010038.23072.pogonyshev@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1183238669 8510 80.91.229.12 (30 Jun 2007 21:24:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 30 Jun 2007 21:24:29 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 30 23:24:23 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I4kQZ-0007dA-EY for ged-emacs-devel@m.gmane.org; Sat, 30 Jun 2007 23:24:23 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4kQY-0004oL-NC for ged-emacs-devel@m.gmane.org; Sat, 30 Jun 2007 17:24:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I4kQV-0004nb-2m for emacs-devel@gnu.org; Sat, 30 Jun 2007 17:24:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I4kQU-0004nD-MM for emacs-devel@gnu.org; Sat, 30 Jun 2007 17:24:18 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4kQU-0004nA-DC for emacs-devel@gnu.org; Sat, 30 Jun 2007 17:24:18 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1I4kQT-0001y9-Tf for emacs-devel@gnu.org; Sat, 30 Jun 2007 17:24:18 -0400 Original-Received: (qmail invoked by alias); 30 Jun 2007 21:24:16 -0000 Original-Received: from unknown (EHLO [80.94.234.178]) [80.94.234.178] by mail.gmx.net (mp053) with SMTP; 30 Jun 2007 23:24:16 +0200 X-Authenticated: #16844820 X-Provags-ID: V01U2FsdGVkX1+oogpP3/moImeSiUWf3+JZXhIVuVGbZPjFhSaSCU WvPPf3DfGtHLz0 User-Agent: KMail/1.7.2 Content-Disposition: inline X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:74074 Archived-At: [ 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