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: Sat, 28 May 2005 21:20:38 -0500 (CDT) Message-ID: <200505290220.j4T2Kc010172@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> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1117333292 10025 80.91.229.2 (29 May 2005 02:21:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 29 May 2005 02:21:32 +0000 (UTC) Cc: Lute.Kamstra.lists@xs4all.nl, dominik@science.uva.nl, mmaug@yahoo.com, monnier@iro.umontreal.ca, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 29 04:21:29 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DcDQX-0007Lz-8Q for ged-emacs-devel@m.gmane.org; Sun, 29 May 2005 04:21:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DcDV7-0005RQ-OR for ged-emacs-devel@m.gmane.org; Sat, 28 May 2005 22:26:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DcDUt-0005Pq-PS for emacs-devel@gnu.org; Sat, 28 May 2005 22:25:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DcDUo-0005Mx-FE for emacs-devel@gnu.org; Sat, 28 May 2005 22:25:48 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DcDUo-0005Mn-C8 for emacs-devel@gnu.org; Sat, 28 May 2005 22:25:46 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DcDRV-0005FW-RZ; Sat, 28 May 2005 22:22:22 -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 j4T2L6CK018921; Sat, 28 May 2005 21:21:06 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j4T2Kc010172; Sat, 28 May 2005 21:20:38 -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 Sat, 28 May 2005 07:53:25 -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:37841 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37841 Here are the latest versions of my patches to easy-mmode and font-core. The patch to cwarn remains unchanged from the revised version I sent earlier. The docstring of `define-global-minor-mode' now says that if the minor mode's setup depends on the major mode for which it was enabled, it should first of all try to make sure that dis- and then re-enabling the minor mode corrects for the new major mode, in which case no warning is necessary. Unless I misunderstood, this is already the case for cwarn. For some reason it is apparently impossible to achieve this for Font Lock, which is what causes a lot of the trouble. The new version says that any mode that can not arrange for a reliable correction to the new mode, should warn the user if the problem occurs. Hopefully, we are only talking about Font Lock. The new patch to font-core makes font-lock-mode issue a warning, thereby taking care of Stefan's objection. `define-global-minor-mode' no longer warns, as this would hopefully be unnecessary for most minor modes and we do not want to warn twice about the same problem for Font Lock. The Font Lock problem (and the problem for hypothetical other modes in the same situation) can occur outside of define-global-minor-mode's control, and hence `define-global-minor-mode' can not handle all necessary warnings. ===File ~/easy-mmode-diff=================================== *** easy-mmode.el 22 May 2005 16:50:33 -0500 1.63 --- easy-mmode.el 28 May 2005 17:12:33 -0500 *************** *** 271,284 **** TURN-ON is a function that will be called with no args in every buffer and that should try to turn MODE on if applicable for that buffer. KEYS is a list of CL-style keyword arguments: ! :group to specify the custom group." (let* ((global-mode-name (symbol-name global-mode)) (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) (extra-args nil) (buffers (intern (concat global-mode-name "-buffers"))) ! (cmmh (intern (concat global-mode-name "-cmmh")))) ;; Check keys. (while (keywordp (car keys)) --- 271,306 ---- TURN-ON is a function that will be called with no args in every buffer and that should try to turn MODE on if applicable for that buffer. KEYS is a list of CL-style keyword arguments: ! :group to specify the custom group. ! ! If MODE's set-up depends on the major mode in effect when it ! was enabled., then enabling MODE should store the value of ! the variable `major-mode' in the variable MODE-stored-mode. ! If `define-global-minor-mode' notices that MODE is configured ! for the wrong major mode, it disables and then reenables MODE. ! Normally, you should write MODE in such a way that this will ! make MODE work correctly with the current major mode. If this is ! impossible, then enabling the MODE should check the value of ! MODE-stored-mode and warn the user if it is not the current major mode. ! ! The above is important to make MODE work correctly with \"derived\" ! major modes, that is major modes that call another major mode in their body. ! When switching major modes interactively, `kill-local-variables' ! should eliminate the old major mode's setup. ! ! `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 in effect when it ! was enabled, the value of the variable should stay nil." (let* ((global-mode-name (symbol-name global-mode)) (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) (extra-args nil) (buffers (intern (concat global-mode-name "-buffers"))) ! (buffers-check (intern (concat global-mode-name "-check-buffers"))) ! (cmmh (intern (concat global-mode-name "-cmmh"))) ! (stored-mode (intern (concat (symbol-name mode) "-stored-mode")))) ;; Check keys. (while (keywordp (car keys)) *************** *** 294,299 **** --- 316,323 ---- "-mode\\'" "" (symbol-name mode)))))) `(progn + (defvar ,stored-mode nil) + (make-variable-buffer-local ',stored-mode) ;; The actual global minor-mode (define-minor-mode ,global-mode ,(format "Toggle %s in every buffer. *************** *** 307,314 **** --- 331,340 ---- (if ,global-mode (progn (add-hook 'after-change-major-mode-hook ',buffers) + (add-hook 'find-file-hook ',buffers-check) (add-hook 'change-major-mode-hook ',cmmh)) (remove-hook 'after-change-major-mode-hook ',buffers) + (remove-hook 'find-file-hook ',buffers-check) (remove-hook 'change-major-mode-hook ',cmmh)) ;; Go through existing buffers. *************** *** 325,341 **** ;; The function that calls TURN-ON in each buffer. (defun ,buffers () ! (remove-hook 'post-command-hook ',buffers) (while ,buffers (let ((buf (pop ,buffers))) (when (buffer-live-p buf) ! (with-current-buffer buf (,turn-on)))))) ! (put ',buffers 'definition-name ',global-mode) ;; The function that catches kill-all-local-variables. (defun ,cmmh () (add-to-list ',buffers (current-buffer)) ! (add-hook 'post-command-hook ',buffers)) (put ',cmmh 'definition-name ',global-mode)))) ;;; --- 351,378 ---- ;; The function that calls TURN-ON in each buffer. (defun ,buffers () ! (dolist (buf ,buffers) ! (when (buffer-live-p buf) ! (with-current-buffer buf ! (unless ,mode ! (,turn-on)))))) ! (put ',buffers 'definition-name ',global-mode) ! ! (defun ,buffers-check () ! (remove-hook 'post-command-hook ',buffers-check) (while ,buffers (let ((buf (pop ,buffers))) (when (buffer-live-p buf) ! (with-current-buffer buf ! (or (not ,stored-mode) ! (eq ,stored-mode major-mode) ! (,mode -1)) ! (,turn-on)))))) ;; The function that catches kill-all-local-variables. (defun ,cmmh () (add-to-list ',buffers (current-buffer)) ! (add-hook 'post-command-hook ',buffers-check)) (put ',cmmh 'definition-name ',global-mode)))) ;;; ============================================================ ===File ~/font-core-diff==================================== *** font-core.el 22 May 2005 16:46:07 -0500 1.28 --- font-core.el 28 May 2005 19:34: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,172 ---- ;; 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 ! (or (not font-lock-mode-stored-mode) ! (eq font-lock-mode-stored-mode major-mode) ! (message ! "Font Lock was set up for wrong major mode: %s. ! We tried to correct. This is a bug. Please report it." ! font-lock-mode-stored-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 **** --- 185,191 ---- '(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 *************** *** 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 () --- 214,232 ---- (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 mode ! (boundp 'font-lock-set-defaults) ! font-lock-set-defaults ! font-lock-mode-stored-mode ! (not (eq font-lock-mode-stored-mode major-mode)))) ! (and mode ! font-lock-mode-stored-mode ! (not (eq font-lock-mode-stored-mode major-mode)) ! ;; This may not work completely correctly, but it is the best ! ;; we can do in the given situation. We will warn the user ! ;; about the problem later, in the `font-lock-mode' function. ! (setq font-lock-set-defaults nil)) (font-lock-mode-internal mode))) (defun turn-on-font-lock () ============================================================