From: martin rudalics <rudalics@gmx.at>
Cc: emacs-devel@gnu.org
Subject: Re: diary font-lock issue
Date: Tue, 16 May 2006 23:42:49 +0200 [thread overview]
Message-ID: <446A4759.6070209@gmx.at> (raw)
In-Reply-To: <1hac9hn99k.fsf@fencepost.gnu.org>
>>`foo-font-lock-keywords' will fail to find a match when the end of
>>`font-lock-fontify-region' is positioned as indicated above.
[...]
>
> Just looking at this quickly, it looks to be doing the same job as the
> regexp I originally quoted, but using a function instead to do the
> match. Setting font-lock-multiline to t in the buffer means that it
> gets added as a property to all fontified regions, so yours is more
> elegant (only adding the property where needed), but the two ought to
> be equivalent, right?
Not really, I put a question mark at the end of the regexp. Hence I
also match date lines not followed by a =[=]* line. To handle that very
case - which is the cause of your problem - I use a function. You
probably could do that more elegantly with anchored matches.
> This all seems very complex. According to:
>
> <http://lists.gnu.org/archive/html/emacs-devel/2006-04/msg00881.html>
>
> "the font-lock-multiline property should be enough in all cases to
> make it unnecessary to use an after-change-function hook."
Indeed, it *should*, eventually ...
> That's a long thread, but AFAICS, it seems that for simple keyword
> fontification, setting font-lock-multiline for the buffer ought to be
> enough.
>
> (Though later on I find:
>
> <http://lists.gnu.org/archive/html/emacs-devel/2006-04/msg01130.html>
>
> > (i) The matching of keywords which span line breaks;
> ... setting the font-lock-multiline variable... won't reliably
> take care of (i)
>
> which confuses me.)
You might have to solve the following problem: Suppose you have the
single line
Friday, May 5, 2006
in your buffer and you type a "=" on the next line as in
Friday, May 5, 2006
=
There's no multiline property around before you type the "=" but you
probably want to highlight the date line after. That's what my ugly
after-change-hook is for.
> I'm also confused as to why the initial fontification is not working
> as it should. There are no "changes" involved in this instance.
> (Indeed, the fancy diary buffer is not something one edits, so this is
> about as simple as multiline font-lockign can get.)
I explained that at the very beginning of this message. If you never
edit the buffer you obviously don't need font-lock-multiline and you
don't need the after-change hook either, just use a simplified version
of foo-bar like
(defun foo-bar (bound)
(and (re-search-forward
"\\(\\(?:\\(?:Fri\\|Mon\\|S\\(?:atur\\|un\\)\\|\\(?:T\\(?:hur\\|ue\\)\\|Wedne\\)s\\)day\\)\
, \\(?:A\\(?:pril\\|ugust\\)\\|December\\|February\\|J\\(?:anuary\\|u\\(?:ly\\|ne\\)\\)\
\\|Ma\\(?:rch\\|y\\)\\|\\(?:Novem\\|Octo\\|Septem\\)ber\\) [0-9]+, -?[0-9]+\n\\)\\(=+\n\\)?" bound t)
(or (> (match-end 0) (match-end 1))
(and (= (match-end 1) bound)
(save-match-data
(looking-at "=+\n"))))))
But never try to match things that span two or more lines the way you
did. It will always fail at boundaries of jit-lock chunks.
next prev parent reply other threads:[~2006-05-16 21:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-16 7:22 diary font-lock issue Glenn Morris
2006-05-16 15:50 ` martin rudalics
2006-05-16 17:56 ` Glenn Morris
2006-05-16 21:42 ` martin rudalics [this message]
2006-05-17 15:11 ` Stefan Monnier
2006-05-17 15:05 ` Stefan Monnier
2006-05-17 19:11 ` Glenn Morris
2006-05-17 21:15 ` Stefan Monnier
2006-05-21 10:39 ` martin rudalics
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=446A4759.6070209@gmx.at \
--to=rudalics@gmx.at \
--cc=emacs-devel@gnu.org \
/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).