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: Tue, 31 May 2005 22:50:23 -0500 (CDT) Message-ID: <200506010350.j513oNZ22896@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> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1117598112 8177 80.91.229.2 (1 Jun 2005 03:55:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 1 Jun 2005 03:55:12 +0000 (UTC) Cc: Lute.Kamstra.lists@xs4all.nl, dominik@science.uva.nl, mmaug@yahoo.com, rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 01 05:55:09 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DdKJ4-0000G3-CQ for ged-emacs-devel@m.gmane.org; Wed, 01 Jun 2005 05:54:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DdKOH-0004cJ-Jq for ged-emacs-devel@m.gmane.org; Tue, 31 May 2005 23:59:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DdKN8-00046Q-N6 for emacs-devel@gnu.org; Tue, 31 May 2005 23:58:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DdKN7-00044l-9I for emacs-devel@gnu.org; Tue, 31 May 2005 23:58:25 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DdKN5-00043S-4A for emacs-devel@gnu.org; Tue, 31 May 2005 23:58:23 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DdKHp-0003XS-Vh; Tue, 31 May 2005 23:52:58 -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 j513oxCK001591; Tue, 31 May 2005 22:50:59 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j513oNZ22896; Tue, 31 May 2005 22:50:23 -0500 (CDT) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: monnier@iro.umontreal.ca In-reply-to: (message from Stefan Monnier on Tue, 31 May 2005 15:08:48 -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:37983 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37983 Stefan Monnier wrote: The assumption is that those keywords are added via a function placed on the major mode's hook, i.e. the keywords tweak the major mode and should thus be removed/readded when the major mode changes. Of course in other settings it should behave differently. One solution is making font-lock-set-defaults itself check whether the major mode is correct (as one of my earlier patches already did, but I maybe mistakenly changed it later on). That way, Font Lock gets updated for the current major mode, _before_ any keywords get added. So, any keywords added while hooks are being run at the end of the actual final major mode, or during the body of the final major mode, are not going to be lost. Keywords added passing nil for MODE _while an ancestor mode is running_ are lost. It is not clear at all to me whether or not they are supposed to be lost. The documentation is super-vague and cryptic. (The other solution I proposed earlier would have similar effects, but would be somewhat more complex.) Concrete problem: Suppose child-mode is derived from parent-mode. A program adds a call to font-lock-add-keywords passing nil for MODE to parent-mode-hook. Do you want those keywords to apply to child-mode or not? With the patches below, they would apply to child-mode if parent-mode followed the major mode conventions (but not otherwise). Currently it seems to be nowhere documented whether or not these keywords should apply to child-mode, so that currently the effects of using font-lock-add-keywords passing nil for MODE seem to be undefined in as far as derived modes are concerned. ===File ~/font-core-diff==================================== *** font-core.el 22 May 2005 16:46:07 -0500 1.28 --- font-core.el 31 May 2005 20:32:19 -0500 *************** *** 88,93 **** --- 88,95 ---- It will be passed one argument, which is the current value of `font-lock-mode'.") + ;; The mode for which font-lock was initialized, or nil if none. + (defvar font-lock-mode-stored-mode) (define-minor-mode font-lock-mode "Toggle Font Lock mode. With arg, turn Font Lock mode off if and only if arg is a non-positive *************** *** 156,162 **** ;; Arrange to unfontify this buffer if we change major mode later. (if font-lock-mode (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t) ! (remove-hook 'change-major-mode-hook 'font-lock-change-mode t))) ;; Get rid of fontification for the old major mode. ;; We do this when changing major modes. --- 158,166 ---- ;; Arrange to unfontify this buffer if we change major mode later. (if font-lock-mode (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t) ! (remove-hook 'change-major-mode-hook 'font-lock-change-mode t)) ! (when font-lock-mode ! (setq font-lock-mode-stored-mode major-mode))) ;; Get rid of fontification for the old major mode. ;; We do this when changing major modes. *************** *** 175,180 **** --- 179,185 ---- '(font-lock-face))) (restore-buffer-modified-p modp))) + (defvar font-lock-set-defaults) (defun font-lock-default-function (mode) ;; Turn on Font Lock mode. (when mode *************** *** 201,209 **** ;; Only do hard work if the mode has specified stuff in ;; `font-lock-defaults'. (when (or font-lock-defaults ! (and (boundp 'font-lock-keywords) font-lock-keywords) (with-no-warnings ! (cdr (assq major-mode font-lock-defaults-alist)))) (font-lock-mode-internal mode))) (defun turn-on-font-lock () --- 206,219 ---- ;; Only do hard work if the mode has specified stuff in ;; `font-lock-defaults'. (when (or font-lock-defaults ! (if (boundp 'font-lock-keywords) font-lock-keywords) (with-no-warnings ! (cdr (assq major-mode font-lock-defaults-alist))) ! (and mode ! (boundp 'font-lock-set-defaults) ! font-lock-set-defaults ! font-lock-mode-stored-mode ! (not (eq font-lock-mode-stored-mode major-mode)))) (font-lock-mode-internal mode))) (defun turn-on-font-lock () ============================================================ ===File ~/font-lock-diff==================================== *** font-lock.el 29 May 2005 09:15:38 -0500 1.259 --- font-lock.el 31 May 2005 20:47:50 -0500 *************** *** 704,710 **** (font-lock-update-removed-keyword-alist mode keywords append)) (t ;; Otherwise set or add the keywords now. ! ;; This is a no-op if it has been done already in this buffer. (font-lock-set-defaults) (let ((was-compiled (eq (car font-lock-keywords) t))) ;; Bring back the user-level (uncompiled) keywords. --- 704,711 ---- (font-lock-update-removed-keyword-alist mode keywords append)) (t ;; Otherwise set or add the keywords now. ! ;; This is a no-op if it has been done already in this buffer ! ;; for the correct major mode. (font-lock-set-defaults) (let ((was-compiled (eq (car font-lock-keywords) t))) ;; Bring back the user-level (uncompiled) keywords. *************** *** 1571,1582 **** (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. (defun font-lock-set-defaults () "Set fontification defaults appropriately for this mode. Sets various variables using `font-lock-defaults' (or, if nil, using `font-lock-defaults-alist') and `font-lock-maximum-decoration'." ! ;; Set fontification defaults iff not previously set. ! (unless font-lock-set-defaults (set (make-local-variable 'font-lock-set-defaults) t) (make-local-variable 'font-lock-fontified) (make-local-variable 'font-lock-multiline) --- 1572,1585 ---- (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. + (defvar font-lock-mode-stored-mode) (defun font-lock-set-defaults () "Set fontification defaults appropriately for this mode. Sets various variables using `font-lock-defaults' (or, if nil, using `font-lock-defaults-alist') and `font-lock-maximum-decoration'." ! ;; Set fontification defaults iff not previously set for correct major mode. ! (unless (and font-lock-set-defaults ! (eq font-lock-mode-stored-mode major-mode)) (set (make-local-variable 'font-lock-set-defaults) t) (make-local-variable 'font-lock-fontified) (make-local-variable 'font-lock-multiline) ============================================================