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: Fri, 27 May 2005 20:58:48 -0500 (CDT) Message-ID: <200505280312.j4S3CY508530@raven.dms.auburn.edu> References: <87psveq60w.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1117250156 2621 80.91.229.2 (28 May 2005 03:15:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 28 May 2005 03:15:56 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 28 05:15:45 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DbrnT-0004Zz-2v for ged-emacs-devel@m.gmane.org; Sat, 28 May 2005 05:15:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dbrrr-0007hZ-9M for ged-emacs-devel@m.gmane.org; Fri, 27 May 2005 23:20:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Dbrrf-0007gq-Jg for emacs-devel@gnu.org; Fri, 27 May 2005 23:19:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Dbrrd-0007fm-TN for emacs-devel@gnu.org; Fri, 27 May 2005 23:19:54 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dbrrd-0007e3-Km for emacs-devel@gnu.org; Fri, 27 May 2005 23:19:53 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Dbrlw-0002Pm-6Z for emacs-devel@gnu.org; Fri, 27 May 2005 23:14:00 -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 j4S3CwCK016096 for ; Fri, 27 May 2005 22:12:58 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j4S3CY508530; Fri, 27 May 2005 22:12:34 -0500 (CDT) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: emacs-devel@gnu.org In-reply-to: <87psveq60w.fsf-monnier+emacs@gnu.org> (message from Stefan Monnier on Thu, 26 May 2005 13:04:36 -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:37814 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37814 My original patch for font-lock.el had problems. It did not work well for modes that only use font-lock for font-lock-face and it did not work for modes with a non-standard font-lock-function. I now propose to leave font-lock.el unchanged and to apply the patch below to font-core.el instead. I also propose a slightly changed second paragraph to the `define-global-minor-mode' docstring. The revised patch to cwarn.el is completely equivalent to my original. It just adapts the changes to the revised `define-global-minor-mode' docstring. Revised second paragraph of `define-global-minor-mode' docstring: If the minor mode's set-up depends on the major mode, then enabling the minor mode should store the value of the variable `major-mode' in the variable MODE-stored-mode. This is used to catch bugs where MODE is set up for the wrong mode. `define-global-minor-mode' provides a defvar for MODE-stored-hook, with initial value nil, and makes it automatically buffer-local. If MODE's set-up is independent of the major mode, the value of the variable should stay nil. New patches to font-core.el and cwarn.el: ===File ~/font-core-diff==================================== *** font-core.el 22 May 2005 16:46:07 -0500 1.28 --- font-core.el 27 May 2005 20:01:05 -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,165 ---- ;; 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. *************** *** 203,209 **** (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,217 ---- (when (or font-lock-defaults (and (boundp 'font-lock-keywords) font-lock-keywords) (with-no-warnings ! (cdr (assq major-mode font-lock-defaults-alist))) ! (and (boundp 'font-lock-set-defaults) ! font-lock-set-defaults ! (not (eq font-lock-mode-stored-mode major-mode)))) ! (unless (eq font-lock-mode-stored-mode major-mode) ! (setq font-lock-set-defaults nil)) (font-lock-mode-internal mode))) (defun turn-on-font-lock () ============================================================ ===File ~/cwarn-diff======================================== *** cwarn.el 04 Apr 2005 07:03:09 -0500 1.9 --- cwarn.el 27 May 2005 20:03:24 -0500 *************** *** 184,189 **** --- 184,190 ---- ;;}}} ;;{{{ The modes + (defvar cwarn-mode-stored-mode) ;;;###autoload (define-minor-mode cwarn-mode "Minor mode that highlights suspicious C and C++ constructions. *************** *** 195,201 **** With ARG, turn CWarn mode on if and only if arg is positive." :group 'cwarn :lighter cwarn-mode-text (cwarn-font-lock-keywords cwarn-mode) ! (if font-lock-mode (font-lock-fontify-buffer))) ;;;###autoload (defun turn-on-cwarn-mode () --- 196,203 ---- With ARG, turn CWarn mode on if and only if arg is positive." :group 'cwarn :lighter cwarn-mode-text (cwarn-font-lock-keywords cwarn-mode) ! (if font-lock-mode (font-lock-fontify-buffer)) ! (when cwarn-mode (setq cwarn-mode-stored-mode major-mode))) ;;;###autoload (defun turn-on-cwarn-mode () ============================================================