all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Conditionalized font-locking?
@ 2012-05-07  8:47 Stephen Berman
  2012-05-07 15:05 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Berman @ 2012-05-07  8:47 UTC (permalink / raw)
  To: emacs-devel

In a certain mode I'd like to fontify date strings where the date is
earlier than current-time-string differently from date strings of later
dates.  I tried to do this with font-lock-keywords by filtering the
output of the regexp search.  It seems to work, but as soon as a
filtered matching string is fontified, Emacs appears to hang (the gdb
backtrace shows thousands of calls to mark_object).  Hitting `C-x k'
followed by rapidly repeating `C-g' many times eventually gets Emacs
back to normal.

The case with date strings is more complicated than necessary to show
the problem; the following code shows the same problem for a simpler
case, fontifying odd numbers (of course, that can be done with just a
regexp and then there's no problem, but I don't think the date string
case is possible just with a regexp):

--8<---------------cut here---------------start------------->8---
(defvar srb-font-lock-keywords
  (list '(srb-number-matcher 1 font-lock-warning-face t)))

(defun srb-number-matcher (lim)
  "Search for odd numbers within LIM for font-locking."
  (re-search-forward "\\<\\([0-9]+\\)\\>" lim t)
  (let ((num (match-string-no-properties 1)))
    (when (eq (logand (string-to-number num) 1) 1) num)))

(define-derived-mode srb-mode nil "SRB" ()
  "Mode for testing font-locking."
  (set (make-local-variable 'font-lock-defaults)
       '(srb-font-lock-keywords t)))
--8<---------------cut here---------------end--------------->8---

Evaluate this code, switch to a new buffer, type `M-x srb-mode' and then
the number `1': the number gets fontified but Emacs appears to hang.

Am I doing something wrong?  If so, what's the right way to do this?  Or
is what I'm trying to do not possible?

Steve Berman




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-05-10 18:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.