all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help with font-lock-add-keywords
@ 2015-03-13  3:20 Marcin Borkowski
  2015-03-13  3:47 ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Marcin Borkowski @ 2015-03-13  3:20 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi all,

I'm trying to grok the font-lock-add-keywords function.  Why doesn't
this work (i.e., turn all foo's into italic ones)?

(font-lock-add-keywords nil '(("foo" . italic)))

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: Help with font-lock-add-keywords
       [not found] <mailman.1931.1426216826.31049.help-gnu-emacs@gnu.org>
@ 2015-03-13  3:33 ` Emanuel Berg
  2015-03-13  3:46   ` Marcin Borkowski
  0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg @ 2015-03-13  3:33 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

> I'm trying to grok the font-lock-add-keywords
> function. Why doesn't this work (i.e., turn all
> foo's into italic ones)?
>
> (font-lock-add-keywords nil '(("foo" . italic)))

Try this - it should look like this after you put
Emacs into emacs-lisp-mode:

    http://user.it.uu.se/~embe8573/cols/www/dumps/emacs_faces.png

(font-lock-add-keywords 'emacs-lisp-mode
  '(
    ("font-lock-builtin-face"              .  font-lock-builtin-face)
    ("font-lock-comment-delimiter-face"    .  font-lock-comment-delimiter-face)
    ("font-lock-comment-face"              .  font-lock-comment-face)
    ("font-lock-constant-face"             .  font-lock-constant-face)
    ("font-lock-doc-face"                  .  font-lock-doc-face)
    ("font-lock-function-name-face"        .  font-lock-function-name-face)
    ("font-lock-keyword-face"              .  font-lock-keyword-face)
    ("font-lock-negation-char-face"        .  font-lock-negation-char-face)
    ("font-lock-preprocessor-face"         .  font-lock-preprocessor-face)
    ("font-lock-reference-face"            .  font-lock-reference-face)
    ("font-lock-string-face"               .  font-lock-string-face)
    ("font-lock-syntactic-face-function"   .  font-lock-syntactic-face-function)
    ("font-lock-type-face"                 .  font-lock-type-face)
    ("font-lock-variable-name-face"        .  font-lock-variable-name-face)
    ("font-lock-warning-face"              .  font-lock-warning-face)
    ("font-lock-regexp-grouping-construct" . 'font-lock-regexp-grouping-construct)
    ("font-lock-regexp-grouping-backslash" . 'font-lock-regexp-grouping-backslash)
    )
  t)

-- 
underground experts united


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

* Re: Help with font-lock-add-keywords
  2015-03-13  3:33 ` Emanuel Berg
@ 2015-03-13  3:46   ` Marcin Borkowski
  0 siblings, 0 replies; 8+ messages in thread
From: Marcin Borkowski @ 2015-03-13  3:46 UTC (permalink / raw)
  To: help-gnu-emacs


On 2015-03-13, at 04:33, Emanuel Berg <embe8573@student.uu.se> wrote:

> Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>
>> I'm trying to grok the font-lock-add-keywords
>> function. Why doesn't this work (i.e., turn all
>> foo's into italic ones)?
>>
>> (font-lock-add-keywords nil '(("foo" . italic)))
>
> Try this - it should look like this after you put
> Emacs into emacs-lisp-mode:
>
>     http://user.it.uu.se/~embe8573/cols/www/dumps/emacs_faces.png
>
> (font-lock-add-keywords 'emacs-lisp-mode
>   '(
>     ("font-lock-builtin-face"              .  font-lock-builtin-face)
>     ("font-lock-comment-delimiter-face"    .  font-lock-comment-delimiter-face)
>     ("font-lock-comment-face"              .  font-lock-comment-face)
>     ("font-lock-constant-face"             .  font-lock-constant-face)
>     ("font-lock-doc-face"                  .  font-lock-doc-face)
>     ("font-lock-function-name-face"        .  font-lock-function-name-face)
>     ("font-lock-keyword-face"              .  font-lock-keyword-face)
>     ("font-lock-negation-char-face"        .  font-lock-negation-char-face)
>     ("font-lock-preprocessor-face"         .  font-lock-preprocessor-face)
>     ("font-lock-reference-face"            .  font-lock-reference-face)
>     ("font-lock-string-face"               .  font-lock-string-face)
>     ("font-lock-syntactic-face-function"   .  font-lock-syntactic-face-function)
>     ("font-lock-type-face"                 .  font-lock-type-face)
>     ("font-lock-variable-name-face"        .  font-lock-variable-name-face)
>     ("font-lock-warning-face"              .  font-lock-warning-face)
>     ("font-lock-regexp-grouping-construct" . 'font-lock-regexp-grouping-construct)
>     ("font-lock-regexp-grouping-backslash" . 'font-lock-regexp-grouping-backslash)
>     )
>   t)

Thanks!

This works - sort of.  First of all, not all faces are set correctly
until I edit something in the respective line.  And M-x
font-lock-fontify-buffer doesn't help - I don't understand this,
actually.  (Tested on emacs -Q.)

Even worse, if I add ("foo" . italic) to the list above, occurrences of
"foo" don't get italicized.  (M-x describe-face italic shows that my
computer /can/ display this face properly.)

What am I doing wrong?

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: Help with font-lock-add-keywords
  2015-03-13  3:20 Help with font-lock-add-keywords Marcin Borkowski
@ 2015-03-13  3:47 ` Michael Heerdegen
  2015-03-13  6:39   ` Marcin Borkowski
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2015-03-13  3:47 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

> (font-lock-add-keywords nil '(("foo" . italic)))

According to the doc of `font-lock-keywords', the FACENAME is actually
an expression that gets evaluated.  So you must probably quote `italic',
or define a variable that is bound to 'italic.  There are lots of
variables in Emacs named xxx-face that are bound to face names.

Michael.




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

* Re: Help with font-lock-add-keywords
  2015-03-13  3:47 ` Michael Heerdegen
@ 2015-03-13  6:39   ` Marcin Borkowski
  2015-03-13 12:31     ` Robert Thorpe
  2015-03-13 14:37     ` Drew Adams
  0 siblings, 2 replies; 8+ messages in thread
From: Marcin Borkowski @ 2015-03-13  6:39 UTC (permalink / raw)
  To: help-gnu-emacs


On 2015-03-13, at 04:47, Michael Heerdegen <michael_heerdegen@web.de> wrote:

> Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>
>> (font-lock-add-keywords nil '(("foo" . italic)))
>
> According to the doc of `font-lock-keywords', the FACENAME is actually
> an expression that gets evaluated.  So you must probably quote `italic',
> or define a variable that is bound to 'italic.  There are lots of
> variables in Emacs named xxx-face that are bound to face names.

Wow.  Just wow!  I thought I tried it, but somehow I must have done
something wrong.  I did what you suggested now and it worked.  Thanks!

For the record: both quoting and defining a variable worked.  Also, the
strange problem I was writing about seems to be fixed now.  I guess what
happened was this: I did not quote the name of the face (since it wasn't
really `italic', it was my custom one), and Emacs tried to evaluate the
unquoted (and undefined) symbol in the midst of fontifying, so there as
an error and the fontifying routine crashed.  (Just my suspicion, but
seems reasonable.)

> Michael.

Thanks again!

PS. Expect a blog post about keyword-based font-lock soon. ;-)

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: Help with font-lock-add-keywords
  2015-03-13  6:39   ` Marcin Borkowski
@ 2015-03-13 12:31     ` Robert Thorpe
  2015-03-13 14:37     ` Drew Adams
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Thorpe @ 2015-03-13 12:31 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: help-gnu-emacs

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>  Also, the
> strange problem I was writing about seems to be fixed now.

Font-lock buries lots of state under the hood.  It marks sections of
buffers as fontified, then only re-fontifies them if the user moves
point there and starts editing.  Tinkering with it's values in a buffer
you're using often doesn't completely work.  Often you have to kill the
buffer and re-open it.

BR,
Robert Thorpe



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

* RE: Help with font-lock-add-keywords
  2015-03-13  6:39   ` Marcin Borkowski
  2015-03-13 12:31     ` Robert Thorpe
@ 2015-03-13 14:37     ` Drew Adams
  2015-03-13 14:52       ` Marcin Borkowski
  1 sibling, 1 reply; 8+ messages in thread
From: Drew Adams @ 2015-03-13 14:37 UTC (permalink / raw)
  To: Marcin Borkowski, help-gnu-emacs

> Emacs tried to evaluate the unquoted (and undefined) symbol in the midst
> of fontifying, so there as an error and the fontifying routine crashed.
> (Just my suspicion, but seems reasonable.)

In general, errors that occur during font locking are swallowed, on
purpose.  Font lock is pretty much an invisible, background genie that
does its thing whenever it feels like it, independently of what else
you might think is going on.

It would generally be inappropriate for such an error to be raised,
so font lock just gives up at that point, instead of raising it.



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

* Re: Help with font-lock-add-keywords
  2015-03-13 14:37     ` Drew Adams
@ 2015-03-13 14:52       ` Marcin Borkowski
  0 siblings, 0 replies; 8+ messages in thread
From: Marcin Borkowski @ 2015-03-13 14:52 UTC (permalink / raw)
  To: help-gnu-emacs


On 2015-03-13, at 15:37, Drew Adams <drew.adams@oracle.com> wrote:

>> Emacs tried to evaluate the unquoted (and undefined) symbol in the midst
>> of fontifying, so there as an error and the fontifying routine crashed.
>> (Just my suspicion, but seems reasonable.)
>
> In general, errors that occur during font locking are swallowed, on
> purpose.  Font lock is pretty much an invisible, background genie that
> does its thing whenever it feels like it, independently of what else
> you might think is going on.
>
> It would generally be inappropriate for such an error to be raised,
> so font lock just gives up at that point, instead of raising it.

Of course.  Still, this seems to explain the behavior I saw.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

end of thread, other threads:[~2015-03-13 14:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-13  3:20 Help with font-lock-add-keywords Marcin Borkowski
2015-03-13  3:47 ` Michael Heerdegen
2015-03-13  6:39   ` Marcin Borkowski
2015-03-13 12:31     ` Robert Thorpe
2015-03-13 14:37     ` Drew Adams
2015-03-13 14:52       ` Marcin Borkowski
     [not found] <mailman.1931.1426216826.31049.help-gnu-emacs@gnu.org>
2015-03-13  3:33 ` Emanuel Berg
2015-03-13  3:46   ` Marcin Borkowski

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.