[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why call font-lock-add-keywords in a mode hook?

From: Michael Heerdegen
Subject: Re: Why call font-lock-add-keywords in a mode hook?
Date: Mon, 25 Jan 2016 15:49:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Marcin Borkowski <> writes:

> Hi list,
> this I found in the manual:
>  -- Function: font-lock-add-keywords mode keywords &optional how
>      This function adds highlighting KEYWORDS, for the current buffer or
>      for major mode MODE.  The argument KEYWORDS should be a list with
>      the same format as the variable ‘font-lock-keywords’.
>      If MODE is a symbol which is a major mode command name, such as
>      ‘c-mode’, the effect is that enabling Font Lock mode in MODE will
>      add KEYWORDS to ‘font-lock-keywords’.  Calling with a non-‘nil’
>      value of MODE is correct only in your ‘~/.emacs’ file.
>      If MODE is ‘nil’, this function adds KEYWORDS to
>      ‘font-lock-keywords’ in the current buffer.  This way of calling
>      ‘font-lock-add-keywords’ is usually used in mode hook functions.
> My question: why would I want to call this function in a hook if I can
> specify the mode in its invocation?  (Assuming that I use it in my
> init.el, of course.)

I can think of two reasons at least:

(1)  If MODE has not yet "been initialized", the HOW argument would not
have any effect.  In particular, if you want to append your keywords to
the generic ones, this will only work before the mode had been defined.

(2)  With MODE -> nil, using the function in a hook is a common use
case, I think.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]