* font-lock on variables
@ 2009-07-24 20:27 Santiago Mejia
2009-07-25 0:50 ` Lennart Borgman
0 siblings, 1 reply; 8+ messages in thread
From: Santiago Mejia @ 2009-07-24 20:27 UTC (permalink / raw)
To: help-gnu-emacs
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.el and
http://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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: font-lock on variables
2009-07-24 20:27 Santiago Mejia
@ 2009-07-25 0:50 ` Lennart Borgman
2009-07-25 14:14 ` Drew Adams
2009-07-25 22:34 ` Santiago Mejia
0 siblings, 2 replies; 8+ messages in thread
From: Lennart Borgman @ 2009-07-25 0:50 UTC (permalink / raw)
To: Santiago Mejia; +Cc: help-gnu-emacs
On Fri, Jul 24, 2009 at 10:27 PM, Santiago Mejia<mejia@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.el and
> http://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.
Look at how hi-lock.el does it.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: font-lock on variables
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-25 22:34 ` Santiago Mejia
1 sibling, 2 replies; 8+ messages in thread
From: Drew Adams @ 2009-07-25 14:14 UTC (permalink / raw)
To: 'Lennart Borgman', 'Santiago Mejia'; +Cc: help-gnu-emacs
> > 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.el and
> > http://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.
>
> Look at how hi-lock.el does it.
Again (see last week's thread "Text highlighter functiontionality") -
Hi-lock is only one library that offers such highlighting. See the generic wiki
page for this topic: http://www.emacswiki.org/emacs/HighlightTemporarily. That
page compares the various highlighting libraries, including hi-lock, listing
what each is good for.
> > 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.
Please file an Emacs bug, describing how you tried to find this topic in the
Emacs manual. That will help the Emacs maintainers improve access. `M-x
report-emacs-bug'.
Remember too that `i' in Info is your friend. `i highlight' includes the manual
pages that mention hi-lock.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: font-lock on variables
[not found] <mailman.3105.1248467286.2239.help-gnu-emacs@gnu.org>
@ 2009-07-25 17:47 ` A.Politz
0 siblings, 0 replies; 8+ messages in thread
From: A.Politz @ 2009-07-25 17:47 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: font-lock on variables
2009-07-25 14:14 ` Drew Adams
@ 2009-07-25 22:12 ` Santiago Mejia
2009-07-25 22:41 ` Santiago Mejia
1 sibling, 0 replies; 8+ messages in thread
From: Santiago Mejia @ 2009-07-25 22:12 UTC (permalink / raw)
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
>> > 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.
>
> Please file an Emacs bug, describing how you tried to find this topic
> in the Emacs manual. That will help the Emacs maintainers improve
> access. `M-x report-emacs-bug'.
>
> Remember too that `i' in Info is your friend. `i highlight' includes
> the manual pages that mention hi-lock.
My problem was, as dumb as it may seem, that I did not even have the
word `highlight' in my radar. I looked through all the info and wiki
pages that had to do with "font-lock" and "faces", but did not even
thought about giving a try to searching "highlight".
I guess that, despite my dumbness, I will still fill in a report,
suggesting that some sort of link to highlight-mode is placed in at
least one of the font-lock pages.
Santiago.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: font-lock on variables
2009-07-25 0:50 ` Lennart Borgman
2009-07-25 14:14 ` Drew Adams
@ 2009-07-25 22:34 ` Santiago Mejia
1 sibling, 0 replies; 8+ messages in thread
From: Santiago Mejia @ 2009-07-25 22:34 UTC (permalink / raw)
To: help-gnu-emacs
Lennart Borgman <lennart.borgman@gmail.com> writes:
> On Fri, Jul 24, 2009 at 10:27 PM, Santiago Mejia<mejia@uchicago.edu> wrote:
>
> Look at how hi-lock.el does it.
I haven't really looked *inside* hi-lock.el yet. But I have tried using
the functions in hi-lock.el to highlight the words I am searching,
without any success. highligt-regexp, for example, works in most of my
buffers, but not in the buffers of the dictionaries I am trying to hack
(*wordnet* and *sdcv*)
Any idea as to why this happens? (I have, of course, turned off the
read-only behavior of the buffer)
In case this is helpful, the way these two modes fontify their output
buffers roughly in the same way. That is to say, first, they define
something like:
(defvar wordnet-font-lock-keywords
`(,(concat "^\\("
(regexp-opt '(
"Substance" "Part" "Meronyms" "Holonyms"
"Attributes" "Derived" "Domain" "Familiarity"
"Coordinate" "Grep" "Overview" "Similarity"
"Pertainyms"))
"\\).*")
(0 font-lock-keyword-face t t))
"Keywords to highlight in wordnet mode.")
And then, they call:
(setq font-lock-defaults '(wordnet-font-lock-keywords))
Thanks for any help.
Santiago.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: font-lock on variables
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
1 sibling, 1 reply; 8+ messages in thread
From: Santiago Mejia @ 2009-07-25 22:41 UTC (permalink / raw)
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
> Hi-lock is only one library that offers such highlighting. See the generic wiki
> page for this topic: http://www.emacswiki.org/emacs/HighlightTemporarily. That
> page compares the various highlighting libraries, including hi-lock, listing
> what each is good for.
As I just said in an earlier post, hi-lock is not yet working for me. I
have managed, however, to highlight text with other packages in the page
you mentioned (such as highlight.el). So, if anything else works, at
least I have now a solution.
However, it seems that using this procedure is not ideal. highlight.el
does not work in connection with font-lock-mode. It seems to me that it
would be desirable that, when one turned font-lock-mode off, all the
fontified text was unfontified. However, using packets such as
highlight.el entails using two modes to fontify, and therefore the
fontification would not be unified.
Santiago.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: font-lock on variables
2009-07-25 22:41 ` Santiago Mejia
@ 2009-07-26 14:51 ` Drew Adams
0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2009-07-26 14:51 UTC (permalink / raw)
To: 'Santiago Mejia', help-gnu-emacs
> > Hi-lock is only one library that offers such highlighting.
> > See the generic wiki page for this topic:
> > http://www.emacswiki.org/emacs/HighlightTemporarily.
> > That page compares the various highlighting libraries,
> > including hi-lock, listing what each is good for.
>
> As I just said in an earlier post, hi-lock is not yet working
> for me. I have managed, however, to highlight text with
> other packages in the page you mentioned
> (such as highlight.el). So, if anything else works, at
> least I have now a solution.
>
> However, it seems that using this procedure is not ideal.
> highlight.el does not work in connection with font-lock-mode.
> It seems to me that it would be desirable that, when one
> turned font-lock-mode off, all the fontified text was
> unfontified. However, using packets such as highlight.el
> entails using two modes to fontify, and therefore the
> fontification would not be unified.
Decoupling such highlighting from font-lock is a feature (deliberate), not a bug
(missing feature). The problem you ran into with hi-lock is one of the main
reasons: coupling the two means mixing them up - you must take other
font-locking into account at the same time, and each mode defines its own
font-locking. See
http://www.emacswiki.org/emacs/HighLight#PreservingHighlighting.
You can "turn off" highlighting by highlight.el in several ways, depending on
what is meant. Command `hlt-unhighlight-region' turns off all such highlighting
in the buffer, but you can also turn it off selectively: for given faces, a
region, only overlays, or only text-properties.
If you really need to couple turning off highlighting and font-lock for some
reason, just write a function that does both: turn off `font-lock mode' and call
`hlt-unhighlight-region'. Or advise `font-lock-mode' so that it also turns off
highlighting when you turn it off.
Finally, highlight.el and hi-lock.el are complementary - you can use them
together.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-07-26 14:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.3105.1248467286.2239.help-gnu-emacs@gnu.org>
2009-07-25 17:47 ` font-lock on variables A.Politz
2009-07-24 20:27 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
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).