From: Stephen Berman <stephen.berman@gmx.net>
To: Davis Herring <herring@lanl.gov>
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>, emacs-devel@gnu.org
Subject: Re: Conditionalized font-locking?
Date: Thu, 10 May 2012 20:18:50 +0200 [thread overview]
Message-ID: <87ehqraohh.fsf@escher.home> (raw)
In-Reply-To: <4FABDF09.7030704@lanl.gov> (Davis Herring's message of "Thu, 10 May 2012 09:30:17 -0600")
On Thu, 10 May 2012 09:30:17 -0600 Davis Herring <herring@lanl.gov> wrote:
>> (defun srb-date-time-matcher (lim)
>> "Search for date-time strings within LIM for font-locking."
>> (when (re-search-forward (concat "^\\(?1:[0-9][0-9][0-9][0-9]-"
>> "[0-9][0-9]-[0-9][0-9]\\)"
>> " \\(?2:[0-9]?[0-9]:[0-9][0-9]\\)?")
>> lim t)
>> (let* ((date (match-string-no-properties 1))
>> (time (match-string-no-properties 2))
>> ;; days-between needs a non-empty time string.
>> (date-time (concat date " " (or time "00:00"))))
>> (when (< (days-between date-time (current-time-string)) 0)
>> (concat date " " time)))))
>> [...]
>> Fontification will call FUNCTION repeatedly with the same limit,
>> and with point where the previous invocation left it, until
>> FUNCTION fails. On failure, FUNCTION need not reset point in any
>> particular way.
>
> If any of your searches turns up a date you don't like, your function
> fails (returns nil), so font-lock gives up. You need to (unfortunately)
> write much the same loop that font-lock is wrapping around your function
> so that it finds the first date that it cares about rather than
> returning nil.
Thank you, that was the part I didn't quite understand.
> The easy way to do this if you don't have too many dates being fontified
> at one go is just to recursively call yourself when you don't like your
> current match:
>
> (or (< ...) (srb-date-time-matcher lim))
>
> Note that you needn't return any particular non-nil value on success;
> it's the match-data that font-lock uses.
This works perfectly, thanks very much!
Steve Berman
prev parent reply other threads:[~2012-05-10 18:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-07 8:47 Conditionalized font-locking? Stephen Berman
2012-05-07 15:05 ` Stefan Monnier
2012-05-07 15:15 ` Stephen Berman
2012-05-10 15:22 ` Stephen Berman
2012-05-10 15:30 ` Davis Herring
2012-05-10 18:18 ` Stephen Berman [this message]
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=87ehqraohh.fsf@escher.home \
--to=stephen.berman@gmx.net \
--cc=emacs-devel@gnu.org \
--cc=herring@lanl.gov \
--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.