unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Barry OReilly <gundaetiapo@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: parse-partial-sexp to stop at any depth change (and Re: Fontifying outside of region passed to registered JIT lock function)
Date: Fri, 22 Nov 2013 17:14:52 -0500	[thread overview]
Message-ID: <CAFM41H0e2nSt=iaXmmP1NVRJbOfkS5fOpDDEsf-=Ea-6Kka5Fg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2120 bytes --]

> insert a "display only" close-paren (with suitable coloring).

There's probably less potential to cause user confusion if it colors
existing parens rather than color parens that are not really a part of
the file content.

> 1- do add the face on the text before the beginning of the region.
>    The problem there, is to make sure this face is kept up-to-date
>    later on (e.g. removed if you add revert to the previous
>    indentation). For that you'll want to add a jit-lock-multiline
>    text-property.

I found the right colors seem to display at the right times if I:

  • For initial fontification: do add the face outside the region
  • For fontification after changes: rely on a new
    jit-lock-after-change-extend-region-functions hook to expand the
    region

Since that is working, I began investigating the performance.

One issue is my usage of parse-partial-sexp. This function's interface
doesn't make it easy to stop if there's a change of depth either up or
down, so for code simplicity I went one char at a time:

  (parse-partial-sexp (point)
                      (1+ (point))
                      nil
                      nil
                      parse-state
                      nil)

To see if this was responsible for performance degradation, I hacked
the C implementation to allow a caller to specify "stop at a change of
depth either up or down" and used it. The performance improvement was
huge.

Now, I could write code that would do two sexp parses concurrently,
searching for a change of depth up and a change of depth down, saving
the result of the furthest parse so as to not create an O(n*n)
algorithm. Rather than complect my code in this way, what would you
think of extending the parse-partial-sexp in one of two ways:

  • If TARGETDEPTH is t, stop when any change of depth occurs
  • If TARGETDEPTH is a vector of integer depths, stop when any of
    those depths is reached.

I figure I can't be the only one who would want to have
parse-partial-sexp stop at any change of depth. May I prepare a patch
to provide this?

[-- Attachment #2: Type: text/html, Size: 2327 bytes --]

             reply	other threads:[~2013-11-22 22:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-22 22:14 Barry OReilly [this message]
2013-11-23  2:01 ` parse-partial-sexp to stop at any depth change (and Re: Fontifying outside of region passed to registered JIT lock function) Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFM41H0e2nSt=iaXmmP1NVRJbOfkS5fOpDDEsf-=Ea-6Kka5Fg@mail.gmail.com' \
    --to=gundaetiapo@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).