From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: Why call font-lock-add-keywords in a mode hook? Date: Mon, 25 Jan 2016 15:49:56 +0100 Message-ID: <87si1lpvcb.fsf@web.de> References: <878u3ec6xk.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1453733445 10261 80.91.229.3 (25 Jan 2016 14:50:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 Jan 2016 14:50:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 25 15:50:36 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aNiTS-00042d-KW for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Jan 2016 15:50:34 +0100 Original-Received: from localhost ([::1]:39074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNiTS-00042h-1D for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Jan 2016 09:50:34 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNiTB-00040g-Nc for help-gnu-emacs@gnu.org; Mon, 25 Jan 2016 09:50:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNiT7-00008Z-4l for help-gnu-emacs@gnu.org; Mon, 25 Jan 2016 09:50:17 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:53352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNiT6-00007g-TL for help-gnu-emacs@gnu.org; Mon, 25 Jan 2016 09:50:13 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aNiSw-0003kd-2O for help-gnu-emacs@gnu.org; Mon, 25 Jan 2016 15:50:02 +0100 Original-Received: from dslb-092-077-162-209.092.077.pools.vodafone-ip.de ([92.77.162.209]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Jan 2016 15:50:02 +0100 Original-Received: from michael_heerdegen by dslb-092-077-162-209.092.077.pools.vodafone-ip.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Jan 2016 15:50:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 37 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dslb-092-077-162-209.092.077.pools.vodafone-ip.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:/CpKlf8zrTiQY7IBnlPRHD/zklM= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108849 Archived-At: 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. Regards, Michael.