From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "A.Politz" Newsgroups: gmane.emacs.help Subject: Re: font-lock on variables Date: Sat, 25 Jul 2009 10:47:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1248547269 14055 80.91.229.12 (25 Jul 2009 18:41:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Jul 2009 18:41:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jul 25 20:40:56 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MUmAx-0006D0-UM for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Jul 2009 20:40:56 +0200 Original-Received: from localhost ([127.0.0.1]:43377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MUmAx-0005z5-1a for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Jul 2009 14:40:55 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!s31g2000yqs.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 68 Original-NNTP-Posting-Host: 84.59.206.121 Original-X-Trace: posting.google.com 1248544032 17663 127.0.0.1 (25 Jul 2009 17:47:12 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 25 Jul 2009 17:47:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s31g2000yqs.googlegroups.com; posting-host=84.59.206.121; posting-account=Cb0eCQoAAADOp8Qt5mU0s83Gs6qJzY70 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061208 Iceweasel/3.0.9 (Debian-3.0.9-1),gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:171194 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:66382 Archived-At: On Jul 24, 10:27=A0pm, Santiago Mejia wrote: > I am trying to hack a few extensions in emacs that allow one to look for > words in dictionaries. =A0(in particular, wordnet.el and sdcv.el (to be > found, respectively, at:http://williamxu.net9.org/ref/wordnet.elandhttp:/= /www.emacswiki.org/emacs/sdcv.el) > > When one looks for a word in, say, wordnet.el, it creates a new buffer, > *WORDNET* which has several of its key terms fontified. =A0However, I > would like to be able to fontify, also, the actual word that I am > searching. =A0This word is a variable, and changes every time one makes a > new search. =A0After going through the manual, and looking around in > google and the mailing lists, I have not been able to figure out how to > achieve such thing. > > My idea so far is to define a global variable, my-foo-var, and add it to > the keywords. =A0I have played with all sorts of small variations of how > to add the variable to the font-lock-keywords, but none has worked. > > Here is the most simple example (which as I said, did not work). > > (defvar my-foo-var "woman" > =A0 "Current word that is seeked.") > > (defvar xxx-mode-font-lock-keywords =A0 =A0;keyword for buffer display > =A0 '( > =A0 =A0 ;; word used > =A0 =A0 (my-foo-var . (1 font-lock-type-face)))) > > I have also tried to use the function font-lock-add-keywords with no > success. =A0(this method, however, strikes me as undesirable, for I would > have to find a way to remove each word that is added, and this might > pose problems if one removes a word that one has looked for, but that is > also a keyword to be fontified (for example, if one looks for the word > "Antonyms", which is a keyword that is also fontified). > > Finally, every time I make a change to the xxx-mode-font-lock-keywords, > I have to close emacs and restart it to make sure that the new changes > work. =A0Is there a less brutal way to test the results of one's changes > to this variable? =A0A way to test one's results without having to exit e= macs? > > Any help is appreciated. > > Santiago. (info "(elisp)Search-based Fontification") Use a function: (defvar my-foo-var "\\_" "Current word that is seeked.") (defun modify-foo (string) (setq my-foo-var (copy-seq string)) (font-lock-fontify-buffer)) (defun search-foo (limit) (when my-foo-var (re-search-forward my-foo-var limit t))) (font-lock-add-keywords nil '((search-foo . 'font-lock-builtin-face))) (modify-foo "\\_") -ap