From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: org-mode and mode hooks. Date: Mon, 6 Jun 2005 18:28:49 -0500 (CDT) Message-ID: <200506062328.j56NSnY18148@raven.dms.auburn.edu> References: <87y8a3mnz8.fsf@xs4all.nl> <87ll63weye.fsf-monnier+emacs@gnu.org> <200505252135.j4PLZvt26969@raven.dms.auburn.edu> <87hdgrufcl.fsf-monnier+emacs@gnu.org> <200505260359.j4Q3xbj28809@raven.dms.auburn.edu> <87is16rsid.fsf-monnier+emacs@gnu.org> <200505261501.j4QF17h00246@raven.dms.auburn.edu> <87psveq60w.fsf-monnier+emacs@gnu.org> <200505271717.j4RHHGD07067@raven.dms.auburn.edu> <200505290157.j4T1vus10117@raven.dms.auburn.edu> <200505292354.j4TNsTE13354@raven.dms.auburn.edu> <200505311544.j4VFijq17680@raven.dms.auburn.edu> <200506011911.j51JBR025269@raven.dms.auburn.edu> <87oeap231t.fsf-monnier+emacs@gnu.org> <200506012242.j51MgBj26277@raven.dms.auburn.edu> <87r7flpubg.fs NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1118100629 11506 80.91.229.2 (6 Jun 2005 23:30:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 6 Jun 2005 23:30:29 +0000 (UTC) Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 07 01:30:26 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DfR25-00026D-Qb for ged-emacs-devel@m.gmane.org; Tue, 07 Jun 2005 01:29:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DfR8U-0001ml-KG for ged-emacs-devel@m.gmane.org; Mon, 06 Jun 2005 19:36:02 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DfR80-0001g0-GC for emacs-devel@gnu.org; Mon, 06 Jun 2005 19:35:32 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DfR7z-0001fS-De for emacs-devel@gnu.org; Mon, 06 Jun 2005 19:35:31 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DfR7z-0001ek-5W for emacs-devel@gnu.org; Mon, 06 Jun 2005 19:35:31 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DfR5Z-00017o-LQ; Mon, 06 Jun 2005 19:33:01 -0400 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id j56NTeCK026350; Mon, 6 Jun 2005 18:29:40 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j56NSnY18148; Mon, 6 Jun 2005 18:28:49 -0500 (CDT) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: rms@gnu.org In-reply-to: (message from Richard Stallman on Sun, 05 Jun 2005 05:47:11 -0400) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:38206 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:38206 Richard Stallman wrote: I will add this to the documentation of font-lock-add-keywords. @strong{Warning:} major mode functions must not call @code{font-lock-add-keywords} under any circumstances, either directly or indirectly. (This would lead to incorrect behavior for some minor modes.) They should set up for Font Lock mode by setting @code{font-lock-keywords}. Well, it depends on _how_ they call it indirectly. For instance, if the indirect call adds it to a mode hook everything is fine. I believe that it is better to apply the patch below to modes.texi. (I could not reply earlier due to connection problems.) ===File ~/modes.texi-diff=================================== *** modes.texi 29 May 2005 10:42:38 -0500 1.112 --- modes.texi 06 Jun 2005 18:06:28 -0500 *************** *** 2626,2632 **** You can use @code{font-lock-add-keywords} to add additional search-based fontification rules to a major mode, and ! @code{font-lock-remove-keywords} to removes rules. @defun font-lock-add-keywords mode keywords &optional append This function adds highlighting @var{keywords} for @var{mode}. The --- 2626,2634 ---- You can use @code{font-lock-add-keywords} to add additional search-based fontification rules to a major mode, and ! @code{font-lock-remove-keywords} to remove rules. These two functions ! are meant for user customization and for use in minor mode functions. ! Major mode functions should set @code{font-lock-keywords} instead. @defun font-lock-add-keywords mode keywords &optional append This function adds highlighting @var{keywords} for @var{mode}. The *************** *** 2657,2662 **** --- 2659,2685 ---- @samp{FIXME}, even in comments, and another to fontify the words @samp{and}, @samp{or} and @samp{not} as keywords. + The above example does @emph{not} add the fontification patterns to + major modes derived from C mode, as is usually desired. To add them + to derived modes too, pass @code{nil} for mode and add the call to + @var{mode}'s mode hook. + + For example: + + @smallexample + (add-hook 'c-mode-hook + (lambda () + (font-lock-add-keywords nil + '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend) + ("\\<\\(and\\|or\\|not\\)\\>" . + font-lock-keyword-face))))) + @end smallexample + + The above procedure may fail to add keywords to a derived mode if + @var{mode} or the derived mode do not yet follow the standard + conventions. File a bug report if this happens, so that the offending + major mode can be corrected. + Some modes have specialized support for additional patterns. See the variables @code{c-font-lock-extra-types}, @code{c++-font-lock-extra-types}, @code{objc-font-lock-extra-types} *************** *** 2668,2682 **** in @code{font-lock-add-keywords}, @var{mode} should be a major mode command name or @code{nil}. If @code{nil}, the highlighting @var{keywords} are immediately removed in the current buffer. - @end defun ! @strong{Warning:} Only use a non-@code{nil} @var{mode} argument when ! you use @code{font-lock-add-keywords} or ! @code{font-lock-remove-keywords} in your @file{.emacs} file. When you ! use these functions from a Lisp program (such as a minor mode), we ! recommend that you use @code{nil} for @var{mode} (and place the call ! on a hook) to avoid subtle problems due to the details of the ! implementation. @node Other Font Lock Variables @subsection Other Font Lock Variables --- 2691,2704 ---- in @code{font-lock-add-keywords}, @var{mode} should be a major mode command name or @code{nil}. If @code{nil}, the highlighting @var{keywords} are immediately removed in the current buffer. ! This function does @emph{not} remove the highlighting @var{keywords} ! from derived modes, as is usually desired. To remove them from ! derived modes too, pass @code{nil} for mode and add the call to ! @var{mode}'s hook. This may fail if @var{mode} or a derived mode do ! not yet follow the standard conventions. File a bug report if this ! happens, so that the offending major mode can be corrected. ! @end defun @node Other Font Lock Variables @subsection Other Font Lock Variables ============================================================