From: "A.Politz" <politza@googlemail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: font-lock on variables
Date: Sat, 25 Jul 2009 10:47:12 -0700 (PDT) [thread overview]
Message-ID: <c0ad917d-c397-482e-81d8-c062e8da3301@s31g2000yqs.googlegroups.com> (raw)
In-Reply-To: mailman.3105.1248467286.2239.help-gnu-emacs@gnu.org
On Jul 24, 10:27 pm, Santiago Mejia <me...@uchicago.edu> wrote:
> I am trying to hack a few extensions in emacs that allow one to look for
> words in dictionaries. (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. However, I
> would like to be able to fontify, also, the actual word that I am
> searching. This word is a variable, and changes every time one makes a
> new search. After 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. I 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"
> "Current word that is seeked.")
>
> (defvar xxx-mode-font-lock-keywords ;keyword for buffer display
> '(
> ;; word used
> (my-foo-var . (1 font-lock-type-face))))
>
> I have also tried to use the function font-lock-add-keywords with no
> success. (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. Is there a less brutal way to test the results of one's changes
> to this variable? A way to test one's results without having to exit emacs?
>
> Any help is appreciated.
>
> Santiago.
(info "(elisp)Search-based Fontification")
Use a function:
(defvar my-foo-var "\\_<woman\\_>"
"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 "\\_<man\\_>")
-ap
next parent reply other threads:[~2009-07-25 17:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.3105.1248467286.2239.help-gnu-emacs@gnu.org>
2009-07-25 17:47 ` A.Politz [this message]
2009-07-24 20:27 font-lock on variables Santiago Mejia
2009-07-25 0:50 ` Lennart Borgman
2009-07-25 14:14 ` Drew Adams
2009-07-25 22:12 ` Santiago Mejia
2009-07-25 22:41 ` Santiago Mejia
2009-07-26 14:51 ` Drew Adams
2009-07-25 22:34 ` Santiago Mejia
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c0ad917d-c397-482e-81d8-c062e8da3301@s31g2000yqs.googlegroups.com \
--to=politza@googlemail.com \
--cc=help-gnu-emacs@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).