From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.devel Subject: Conditionalized font-locking? Date: Mon, 07 May 2012 10:47:24 +0200 Message-ID: <871umw74yr.fsf@escher.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1336380467 32334 80.91.229.3 (7 May 2012 08:47:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 7 May 2012 08:47:47 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 07 10:47:45 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SRJbd-00087b-Aa for ged-emacs-devel@m.gmane.org; Mon, 07 May 2012 10:47:45 +0200 Original-Received: from localhost ([::1]:56263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRJbc-0003O7-Lv for ged-emacs-devel@m.gmane.org; Mon, 07 May 2012 04:47:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRJbW-0003O1-Cj for emacs-devel@gnu.org; Mon, 07 May 2012 04:47:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRJbU-0001wh-L6 for emacs-devel@gnu.org; Mon, 07 May 2012 04:47:37 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:46696) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRJbU-0001wY-E5 for emacs-devel@gnu.org; Mon, 07 May 2012 04:47:36 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SRJbS-00081C-QV for emacs-devel@gnu.org; Mon, 07 May 2012 10:47:34 +0200 Original-Received: from i59f54790.versanet.de ([89.245.71.144]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 May 2012 10:47:34 +0200 Original-Received: from stephen.berman by i59f54790.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 May 2012 10:47:34 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 38 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: i59f54790.versanet.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150340 Archived-At: 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