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 12:17:16 -0500 (CDT) Message-ID: <200505271717.j4RHHGD07067@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> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1117214314 13582 80.91.229.2 (27 May 2005 17:18:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 27 May 2005 17:18:34 +0000 (UTC) Cc: dominik@science.uva.nl, Michael Mauger , Lute.Kamstra.lists@xs4all.nl, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 27 19:18:30 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DbiSK-0001gz-Ts for ged-emacs-devel@m.gmane.org; Fri, 27 May 2005 19:17:10 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DbiWd-0008A1-Nn for ged-emacs-devel@m.gmane.org; Fri, 27 May 2005 13:21:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DbiVW-0007rf-UL for emacs-devel@gnu.org; Fri, 27 May 2005 13:20:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DbiVP-0007nI-EA for emacs-devel@gnu.org; Fri, 27 May 2005 13:20:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DbiVP-0007nF-1n for emacs-devel@gnu.org; Fri, 27 May 2005 13:20:19 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DbiTm-0006ca-H6 for emacs-devel@gnu.org; Fri, 27 May 2005 13:18:38 -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 j4RHHgCK014677; Fri, 27 May 2005 12:17:42 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j4RHHGD07067; Fri, 27 May 2005 12:17:16 -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: <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:37794 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37794 Here are my proposed changes to easy-mmode.el. Unlike my previous proposed patch, they require some cooperation from the individual minor modes, but this seemed necessary to catch (and attempt to work around) all possible ways to mess up the major mode for which the minor mode is set up. The only two involved modes I could find using grepping were font-lock-mode and cwarn mode. The patches below adapt both. Michael could check whether or not after my patches (the one to cwarn.el is irrelevant for him), just disabling and enabling font-lock is sufficient for him. If not, then I have the impression that I should not even try to correct this, as maybe certain font-lock-face properties might be mode independent. When testing this patch, do not rely on stuff like `C-h v font-lock-set-defaults', because this is currently buggy. Do `M-: font-lock-set-defaults', or similar, instead. To test the error message, one could use something like: (defun foo-mode () (interactive) (outline-mode) (setq major-mode 'foo-mode) (setq mode-name "FOO")) M-x foo-mode I can install the patches below if desired. ===File ~/easy-mmode-diff=================================== *** easy-mmode.el 22 May 2005 16:50:33 -0500 1.63 --- easy-mmode.el 27 May 2005 11:00:47 -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,294 ---- 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 the minor mode's set-up depends on the major mode, the function that ! does the initial set-up should record 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." (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 **** --- 304,311 ---- "-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 **** --- 319,328 ---- (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)))) ;;; --- 339,372 ---- ;; 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 ! (if (or (not ,stored-mode) (eq ,stored-mode major-mode)) ! (,turn-on) ! (let ((old-stored-mode ,stored-mode)) ! (,mode -1) ! (,turn-on) ! (message ! "%s was set up for wrong major mode: %s. ! We tried to correct. This is a bug. Please report it." ! (symbol-name ',mode) old-stored-mode)) ! (sit-for 1))))))) ;; 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-lock-diff==================================== *** font-lock.el 22 May 2005 19:04:51 -0500 1.258 --- font-lock.el 26 May 2005 19:17:56 -0500 *************** *** 1569,1583 **** (t (car keywords)))) ! (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) (let* ((defaults (or font-lock-defaults --- 1569,1585 ---- (t (car keywords)))) ! ;; The mode for which font-lock was initialized, or nil if none. ! (defvar font-lock-set-defaults) ! (defvaralias 'font-lock-set-defaults '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. ! (unless (eq font-lock-set-defaults major-mode) ! (setq font-lock-set-defaults major-mode) (make-local-variable 'font-lock-fontified) (make-local-variable 'font-lock-multiline) (let* ((defaults (or font-lock-defaults ============================================================ ===File ~/cwarn-diff======================================== *** cwarn.el 04 Apr 2005 07:03:09 -0500 1.9 --- cwarn.el 26 May 2005 19:19:59 -0500 *************** *** 234,242 **** --- 234,244 ---- (back-to-indentation) (eq (char-after) ?#))) + (defvar cwarn-mode-stored-mode) (defun cwarn-font-lock-keywords (addp) "Install/Remove keywords into current buffer. If ADDP is non-nil, install else remove." + (when addp (setq cwarn-mode-stored-mode major-mode)) (dolist (pair cwarn-font-lock-feature-keywords-alist) (let ((feature (car pair)) (keywords (cdr pair))) ============================================================