unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* glitches with font-lock-add-keywords
@ 2006-06-03 11:33 ken
  0 siblings, 0 replies; 6+ messages in thread
From: ken @ 2006-06-03 11:33 UTC (permalink / raw)



In my ~/.emacs I have

(defvar my-extra-keywords
  '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
    ("\\<\\(XXX\\|xxx\\|???\\|(sp?)\\)\\>" . font-lock-keyword-face)))

(add-hook 'text-mode-hook
	  (lambda ()
	    (font-lock-add-keywords nil my-extra-keywords)))

(add-hook 'html-helper-mode-hook
	  (lambda ()
	    (font-lock-add-keywords nil my-extra-keywords)))

(add-hook 'emacs-lisp-mode-hook
	  (lambda ()
	    (font-lock-add-keywords nil my-extra-keywords)))

The strings "XXX" and "xxx" are the only ones which are colorized at
all, showing up as magenta.  I would like all of them to be something
more striking, like lime-green.  Is there a table or some sort of
"translation" which can be used to determine what actual color names
correspond to vars like "font-lock-warning-face" and
"font-lock-keyword"?  Or, better, can actual color names be used
instead, and if so, where would I find a table or listing of them?

Secondly: None of the strings containing a '?' are colorized at all
(they're just black, the same as "normal" text); I understand that '?'
is a special character in elisp and so requires some minor syntactical
gymnastics to induce emacs to treat it as a regular character.  So what
is the syntax I should use for that here?


Thanks much,
ken

-- 
As a statistic, the US Unemployment Rate is like saying that no one is
drowning because the flood waters have risen only five inches today.

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

* Re: glitches with font-lock-add-keywords
@ 2006-06-05  6:50 martin rudalics
  2006-06-05 21:54 ` ken
  2006-06-06  3:10 ` glitches with font-lock-add-keywords Johan Bockgård
  0 siblings, 2 replies; 6+ messages in thread
From: martin rudalics @ 2006-06-05  6:50 UTC (permalink / raw)


 > (defvar my-extra-keywords
 >   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
 >     ("\\<\\(XXX\\|xxx\\|???\\|(sp?)\\)\\>" . font-lock-keyword-face)))
 >
 > The strings "XXX" and "xxx" are the only ones which are colorized at
 > all, showing up as magenta.  I would like all of them to be something
 > more striking, like lime-green.  Is there a table or some sort of
 > "translation" which can be used to determine what actual color names
 > correspond to vars like "font-lock-warning-face" and
 > "font-lock-keyword"?  Or, better, can actual color names be used
 > instead, and if so, where would I find a table or listing of them?

(defface my-extra-face '((t (:foreground "LimeGreen")))
   "My extra face.  Pick your favorite group on the next line."
   :group 'basic-faces)

 > Secondly: None of the strings containing a '?' are colorized at all
 > (they're just black, the same as "normal" text); I understand that '?'
 > is a special character in elisp and so requires some minor syntactical
 > gymnastics to induce emacs to treat it as a regular character.  So what
 > is the syntax I should use for that here?

Assuming that the question mark is a symbol constituent and "(" and ")"
are open and close parenthesis characters you can try:

(defvar my-extra-keywords
   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
     ("\\<\\(XXX\\|xxx\\)\\>\\|\\_<\\(\\?\\?\\?\\)\\_>\\|(sp\\?)" . 'my-extra-face)))

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

* Re: glitches with font-lock-add-keywords
  2006-06-05  6:50 glitches with font-lock-add-keywords martin rudalics
@ 2006-06-05 21:54 ` ken
  2006-06-06  6:38   ` martin rudalics
  2006-06-06  3:10 ` glitches with font-lock-add-keywords Johan Bockgård
  1 sibling, 1 reply; 6+ messages in thread
From: ken @ 2006-06-05 21:54 UTC (permalink / raw)




martin rudalics wrote:
>> (defvar my-extra-keywords
>>   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
>>     ("\\<\\(XXX\\|xxx\\|???\\|(sp?)\\)\\>" . font-lock-keyword-face)))
>>
>> The strings "XXX" and "xxx" are the only ones which are colorized at
>> all, showing up as magenta.  I would like all of them to be something
>> more striking, like lime-green.  Is there a table or some sort of
>> "translation" which can be used to determine what actual color names
>> correspond to vars like "font-lock-warning-face" and
>> "font-lock-keyword"?  Or, better, can actual color names be used
>> instead, and if so, where would I find a table or listing of them?
> 
> (defface my-extra-face '((t (:foreground "LimeGreen")))
>   "My extra face.  Pick your favorite group on the next line."
>   :group 'basic-faces)
> 
>> Secondly: None of the strings containing a '?' are colorized at all
>> (they're just black, the same as "normal" text); I understand that '?'
>> is a special character in elisp and so requires some minor syntactical
>> gymnastics to induce emacs to treat it as a regular character.  So what
>> is the syntax I should use for that here?
> 
> Assuming that the question mark is a symbol constituent and "(" and ")"
> are open and close parenthesis characters you can try:
> 
> (defvar my-extra-keywords
>   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
>     ("\\<\\(XXX\\|xxx\\)\\>\\|\\_<\\(\\?\\?\\?\\)\\_>\\|(sp\\?)" .
> 'my-extra-face)))

Thanks, Martin,

The LimeGreen is showing up and the "sp?" inside of "(sp?)".  I'm
thinking that the "()" chars are being overwritten by other, blue
highlighting.  I changed the last line above to:

    ("\\<\\(XXX\\|xxx\\)\\>\\|\\_<\\(\\?\\?\\?\\)\\_>\\|(\\(sp\\?\\))" .
'my-extra-face)))

because I don't want the last three chars of "What's lisp?" to be
highlighted, but only "(sp?)".  So all of that is fine.

However, "???" is not being highlighted.  There's a lot of characters
clustered around the "???"... I'm wondering if they're all supposed to
be there....

Again, I just want ??? to be highlighted, not _<(???)>_ or anything like
that... just "???".


Thanks for any solutions.


-- 
As a statistic, the US Unemployment Rate is like saying that no one is
drowning because the flood waters have risen only five inches today.

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

* Re: glitches with font-lock-add-keywords
  2006-06-05  6:50 glitches with font-lock-add-keywords martin rudalics
  2006-06-05 21:54 ` ken
@ 2006-06-06  3:10 ` Johan Bockgård
  1 sibling, 0 replies; 6+ messages in thread
From: Johan Bockgård @ 2006-06-06  3:10 UTC (permalink / raw)


martin rudalics <rudalics@gmx.at> writes:

> Assuming that the question mark is a symbol constituent and "(" and
> ")" are open and close parenthesis characters you can try:
>
> (defvar my-extra-keywords
>   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
>     ("\\<\\(XXX\\|xxx\\)\\>\\|\\_<\\(\\?\\?\\?\\)\\_>\\|(sp\\?)" . 'my-extra-face)))

The \_< ... \_> construct exists only in Emacs 22.

-- 
Johan Bockgård

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

* Re: glitches with font-lock-add-keywords
  2006-06-05 21:54 ` ken
@ 2006-06-06  6:38   ` martin rudalics
  2006-06-06 12:49     ` glitches with font-lock-add-keywords -- SOLVED ken
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2006-06-06  6:38 UTC (permalink / raw)
  Cc: help-gnu-emacs

 > The LimeGreen is showing up and the "sp?" inside of "(sp?)".  I'm
 > thinking that the "()" chars are being overwritten by other, blue
 > highlighting.  I changed the last line above to:
 >
 >     ("\\<\\(XXX\\|xxx\\)\\>\\|\\_<\\(\\?\\?\\?\\)\\_>\\|(\\(sp\\?\\))" .
 > 'my-extra-face)))
 >
 > because I don't want the last three chars of "What's lisp?" to be
 > highlighted, but only "(sp?)".  So all of that is fine.

"(sp\\?)" will match all occurrences of the character sequence "(sp?)".
It never matches "What's lisp?".  Additional escaped parentheses won't
change anything here.

The blue highlighting you mention probably comes from paren matching
overlays and should disappear as soon as you move the cursor.

 >
 > However, "???" is not being highlighted.  There's a lot of characters
 > clustered around the "???"... I'm wondering if they're all supposed to
 > be there....
 >
 > Again, I just want ??? to be highlighted, not _<(???)>_ or anything like
 > that... just "???".

I couldn't simply change your initial proposal to something like
"\\<\\?\\?\\?\\>" because in most modes "?" doesn't have word syntax
contradicting the use of "\\<" and "\\>".  "\\_<" and "\\_>" force
matches at symbol begin and end but might not work with Emacs 21.

Maybe

(defvar my-extra-keywords
   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
     ("\\<\\(XXX\\|xxx\\)\\>\\|\\?\\?\\?\\|(sp\\?)" . 'my-extra-face)))

is all you need.  Otherwise you would have to specify the semantics of
the word "just" more distinctly.

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

* Re: glitches with font-lock-add-keywords -- SOLVED
  2006-06-06  6:38   ` martin rudalics
@ 2006-06-06 12:49     ` ken
  0 siblings, 0 replies; 6+ messages in thread
From: ken @ 2006-06-06 12:49 UTC (permalink / raw)




martin rudalics wrote:
>> The LimeGreen is showing up and the "sp?" inside of "(sp?)".  I'm
>> thinking that the "()" chars are being overwritten by other, blue
>> highlighting.  ....
>>
>> ....
> 
> The blue highlighting you mention probably comes from paren matching
> overlays and should disappear as soon as you move the cursor.

That's true in elisp-mode, but in html-helper-mode parentheses are
highlighted blue and this overwrites the green.  But that's okay... not
a big deal.


>> ....
>>
>> Again, I just want ??? to be highlighted, not _<(???)>_ or anything like
>> that... just "???".
> 
> I couldn't simply change your initial proposal to something like
> "\\<\\?\\?\\?\\>" because in most modes "?" doesn't have word syntax
> contradicting the use of "\\<" and "\\>".  "\\_<" and "\\_>" force
> matches at symbol begin and end but might not work with Emacs 21.
> 
> Maybe
> 
> (defvar my-extra-keywords
>   '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
>     ("\\<\\(XXX\\|xxx\\)\\>\\|\\?\\?\\?\\|(sp\\?)" . 'my-extra-face)))
> 
> is all you need.  Otherwise you would have to specify the semantics of
> the word "just" more distinctly.

That did it.  Works perfectly now.  On Emacs 21.  Guess I should save
the previous defs for when I upgrade.

(Note: I wanted "???"-- without the quotation marks-- highlighted.
That's what I get now.)


Thanks very much.  I've been wondering about and playing with that for
months.

ken

-- 
As a statistic, the US Unemployment Rate is like saying that no one is
drowning because the flood waters have risen only five inches today.

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

end of thread, other threads:[~2006-06-06 12:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-05  6:50 glitches with font-lock-add-keywords martin rudalics
2006-06-05 21:54 ` ken
2006-06-06  6:38   ` martin rudalics
2006-06-06 12:49     ` glitches with font-lock-add-keywords -- SOLVED ken
2006-06-06  3:10 ` glitches with font-lock-add-keywords Johan Bockgård
  -- strict thread matches above, loose matches on Subject: below --
2006-06-03 11:33 ken

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).