all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Koppelman <koppel@ece.lsu.edu>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Chong Yidong <cyd@stupidchicken.com>,
	192@emacsbugs.donarmstrong.com, Bruno Haible <bruno@clisp.org>,
	emacs-devel@gnu.org
Subject: bug#192: regexp does not work as documented
Date: Sun, 11 May 2008 14:09:31 -0500	[thread overview]
Message-ID: <yg5tzh4bqtw.fsf__44383.884946774$1210544376$gmane$org@nested.ece.lsu.edu> (raw)
In-Reply-To: <jwv4p94r8vp.fsf-monnier+emacsbugreports@gnu.org> (Stefan Monnier's message of "Sun, 11 May 2008 14:44:12 -0400")

I've decided against having hi-lock turn on font-lock-multiline or
even apply font-lock-multiline text properties, too much potential to
slow things down to a crawl when an unsuspecting user enters a regexp.

If I understand things correctly, the font-lock-multiline property is
used to extend a region to be fontified, a region to be used for *all*
keywords. This would have disastrous effects when multi-line patterns
span, say, 100's of lines for modes with hundreds of keywords. I had
been toying with the idea of limiting extended regions to something
like 100 lines, but that still seems wasteful when most keywords are
single line (I haven't benchmarked anything yet).

A better solution would be to have font-lock use multi-line extended
regions selectively. Perhaps a hint in the current keyword syntax
(say, explicitly applying the font-lock-multiline property), or a
separate method for providing multi-line keywords to font-lock.
Such keywords would get the multi-line extended regions, the other
just the whole-line extensions (or whatever the hooks do).

Is this something the font-lock maintainers would consider?

What I'll do now is just document the limitations for hi-lock and
perhaps provide a warning when a multiline pattern is used.


> That may not be enough.  You'll probably want to do something like what
> smerge does:
>
>   (while (re-search-forward <RE> nil t)
>     (font-lock-fontify-region (match-beginning 0) (match-end 0)))

I wouldn't do that without suppressing other keywords. 


> If someone wants that, I have a parser that takes a regexp and turns it
> into something like `rx' syntax.  It uses my lex.el library (which
> takes an `rx'-like input syntax).

That sounds useful, either E-mail it to me or let me know
where to find it. 


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> My latest plan is to do what Chong Yidong suggests, setting up text
>> properties so that font-lock DTRT, though it doesn't seem as hard as he
>> suggests (I'm still in the naive enthusiasm stage).
>
> Indeed, it shouldn't be that hard.
>
>> I tried adding the font-lock-multiline property to the face property
>> list passed to font lock and that did the trick, even with the
>> font-lock-multiline variable nil.
>
> That may not be enough.  You'll probably want to do something like what
> smerge does:
>
>   (while (re-search-forward <RE> nil t)
>     (font-lock-fontify-region (match-beginning 0) (match-end 0)))
>
> this will find all the multiline elements.  And the font-lock-multiline
> property you add will make sure that those that were found will not
> disappear accidentally because of some later refontification.
>
>> I rather do that than turn on font-lock-multiline because I'm assuming
>> that font-lock-multiline is set to nil in most cases for
>> a good reason.
>
> Setting the `font-lock-multiline' variable to t has a performance cost.
>
>> I actually thought about properly parsing the regexp, but the effort to
>> do that could be spent on making multi-line patterns work properly, at
>> least if they don't span too many lines.
>
> If someone wants that, I have a parser that takes a regexp and turns it
> into something like `rx' syntax.  It uses my lex.el library (which
> takes an `rx'-like input syntax).
>
>> One more thing, multi-line regexp matches don't work properly even
>> with font-lock-multiline t when jit-lock is being used in a buffer
>> without syntactic fontification and using the default setting of
>> jit-lock-contextually, setting it to t gets multi-line fontification
>> to work.
>
> The `font-lock-multiline' variable only tells font-lock that if it ever
> bumps into a multiline element, it should mark it (with the
> font-lock-multiline property) so that it will not re-fontify it as
> a whole if it ever needs to refontify it.
>
> So it doesn't solve the problem of "how do I make sure that font-lock
> indeed finds the multiline element".  Multiline elements can only be
> found when font-locking a large enough piece of text, which tends to
> only happen during the initial fontification, or during background or
> contextual refontification, or during an explicit call such as in the
> above while loop.
>
>
>         Stefan






  parent reply	other threads:[~2008-05-11 19:09 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-06  4:20 regexp does not work as documented Chong Yidong
2008-05-06 11:35 ` Bruno Haible
2008-05-06 12:12   ` martin rudalics
2008-05-10 19:18     ` David Koppelman
2008-05-10 20:13       ` David Koppelman
2008-05-11  7:40         ` martin rudalics
2008-05-11 14:27           ` bug#192: " Chong Yidong
2008-05-11 14:27           ` Chong Yidong
2008-05-11 15:36             ` bug#192: " David Koppelman
2008-05-11 15:36             ` David Koppelman
2008-05-11 18:44               ` bug#192: " Stefan Monnier
2008-05-11 18:44               ` Stefan Monnier
2008-05-11 19:09                 ` David Koppelman
2008-05-12  1:28                   ` bug#192: " Stefan Monnier
2008-05-12  1:28                   ` Stefan Monnier
2008-05-12 15:03                     ` David Koppelman
2008-05-12 16:29                       ` bug#192: " Stefan Monnier
2008-05-12 16:29                       ` Stefan Monnier
2008-05-12 17:04                         ` bug#192: " David Koppelman
2008-05-12 17:04                         ` David Koppelman
2008-05-12 15:03                     ` bug#192: " David Koppelman
2008-05-11 19:09                 ` David Koppelman [this message]
2008-05-11 18:44             ` Stefan Monnier
2008-05-11 18:44             ` Stefan Monnier
2008-05-11 20:03               ` bug#192: " Thomas Lord
2008-05-11 20:03               ` Thomas Lord
2008-05-12  1:43                 ` bug#192: " Stefan Monnier
2008-05-12  1:43                 ` Stefan Monnier
2008-05-12  3:30                   ` bug#192: " Thomas Lord
2008-05-12  3:30                   ` Thomas Lord
2008-05-12 13:43                     ` bug#192: " Stefan Monnier
2008-05-12 13:43                     ` Stefan Monnier
2008-05-12 15:55                       ` Thomas Lord
2008-05-12 16:18                         ` bug#192: " tomas
2008-05-12 16:18                         ` tomas
2008-05-12 15:55                       ` bug#192: " Thomas Lord
2008-05-11  7:40         ` martin rudalics
2008-05-10 20:13       ` David Koppelman
2008-05-10 19:18     ` David Koppelman
2008-05-06 15:35   ` Stefan Monnier
2008-05-06 21:29     ` Bruno Haible
2008-05-10 20:04     ` Bruno Haible
2008-05-10 20:04     ` bug#192: " Bruno Haible
2008-05-06 15:00 ` David Koppelman
2008-05-06 21:35   ` Bruno Haible
2008-05-07  1:04     ` Stefan Monnier
2008-05-07  1:08     ` Auto-discovery of multi-line font-lock regexps Stefan Monnier
2008-05-07  3:46       ` Chong Yidong
2008-05-07  4:21         ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2008-05-06  1:30 regexp does not work as documented Bruno Haible
2015-12-29 17:48 ` bug#192: " Bruno Haible

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

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

  git send-email \
    --in-reply-to='yg5tzh4bqtw.fsf__44383.884946774$1210544376$gmane$org@nested.ece.lsu.edu' \
    --to=koppel@ece.lsu.edu \
    --cc=192@emacsbugs.donarmstrong.com \
    --cc=bruno@clisp.org \
    --cc=cyd@stupidchicken.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.