all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Davis Herring <herring@lanl.gov>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>, emacs-devel@gnu.org
Subject: Re: Conditionalized font-locking?
Date: Thu, 10 May 2012 09:30:17 -0600	[thread overview]
Message-ID: <4FABDF09.7030704@lanl.gov> (raw)
In-Reply-To: <87ipg49i3l.fsf@escher.home>

> (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.

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.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.



  reply	other threads:[~2012-05-10 15:30 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 [this message]
2012-05-10 18:18         ` Stephen Berman

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=4FABDF09.7030704@lanl.gov \
    --to=herring@lanl.gov \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    --cc=stephen.berman@gmx.net \
    /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.