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: Wed, 25 May 2005 22:59:37 -0500 (CDT) Message-ID: <200505260359.j4Q3xbj28809@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> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1117080817 17177 80.91.229.2 (26 May 2005 04:13:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 26 May 2005 04:13:37 +0000 (UTC) Cc: dominik@science.uva.nl, Lute.Kamstra.lists@xs4all.nl, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 26 06:13:35 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Db9k9-0006Xi-SO for ged-emacs-devel@m.gmane.org; Thu, 26 May 2005 06:13:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Db9o9-0003jw-HY for ged-emacs-devel@m.gmane.org; Thu, 26 May 2005 00:17:21 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Db9mX-0002Rd-Vf for emacs-devel@gnu.org; Thu, 26 May 2005 00:15:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Db9mW-0002QZ-63 for emacs-devel@gnu.org; Thu, 26 May 2005 00:15:40 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Db9mV-00026v-Dr for emacs-devel@gnu.org; Thu, 26 May 2005 00:15:39 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Db9Xu-00014J-Kr for emacs-devel@gnu.org; Thu, 26 May 2005 00:00:34 -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 j4Q3xvCK008611; Wed, 25 May 2005 22:59:58 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j4Q3xbj28809; Wed, 25 May 2005 22:59:37 -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: <87hdgrufcl.fsf-monnier+emacs@gnu.org> (message from Stefan Monnier on Wed, 25 May 2005 18:15:50 -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:37665 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37665 Stefan Monnier wrote: W.r.t the code bundled with Emacs, there's often no problem (tho, sometimes there is, because it's not always trivial to fix the code to use define-derived-mode), but for the unbundled packages, the change: 2005-05-22 Luc Teirlinck * emacs-lisp/easy-mmode.el (define-global-minor-mode): Use `after-change-major-mode-hook' instead of `find-file-hook'. introduced a bug where (typically) global-font-lock chooses the wrong keywords (the ones of the parent mode rather than ones of the actual major mode). Well, it fixed one bug, but it created more occurrences of another existing bug. The bug it fixed relates to timers and processes calling mode functions. The other existing bug that it creates more occurrences of is that if _anything_ enables font-lock before the final mode is into place (for instance a function added by a user to a hook) font-lock chooses the wrong keywords. Granted, my change makes this much more likely to happen (of course). But even without my change it can happen. The following changes fix both bugs, by using post-command-hook to check whether font-lock was enabled for the correct mode and adapting the turn-on function to be able to correct it. I still will have to see whether this automatically fixes the second bug for other functions defined with define-global-mode, or whether some of them need a slightly different turn-on function too. ===File ~/font-core-diff==================================== *** font-core.el 22 May 2005 16:46:07 -0500 1.28 --- font-core.el 25 May 2005 21:57:50 -0500 *************** *** 284,291 **** (let (inhibit-quit) (turn-on-font-lock)))) (easy-mmode-define-global-mode ! global-font-lock-mode font-lock-mode turn-on-font-lock-if-enabled :extra-args (dummy)) ;;; End of Global Font Lock mode. --- 284,295 ---- (let (inhibit-quit) (turn-on-font-lock)))) + (defun turn-on-font-lock-as-appropriate () + (let (font-lock-set-defaults) + (turn-on-font-lock-if-enabled))) + (easy-mmode-define-global-mode ! global-font-lock-mode font-lock-mode turn-on-font-lock-as-appropriate :extra-args (dummy)) ;;; End of Global Font Lock mode. ============================================================ ===File ~/easy-mmode-diff=================================== *** easy-mmode.el 22 May 2005 16:50:33 -0500 1.63 --- easy-mmode.el 25 May 2005 22:37:54 -0500 *************** *** 263,268 **** --- 263,271 ---- ;;; make global minor mode ;;; + (defvar easy-mmode-stored-mode nil) + (make-variable-buffer-local 'easy-mmode-stored-mode) + ;;;###autoload (defalias 'easy-mmode-define-global-mode 'define-global-minor-mode) ;;;###autoload *************** *** 278,283 **** --- 281,287 ---- (group nil) (extra-args nil) (buffers (intern (concat global-mode-name "-buffers"))) + (check-buffers (intern (concat "check-" global-mode-name "-buffers"))) (cmmh (intern (concat global-mode-name "-cmmh")))) ;; Check keys. *************** *** 307,314 **** --- 311,320 ---- (if ,global-mode (progn (add-hook 'after-change-major-mode-hook ',buffers) + (add-hook 'find-file-hook ',buffers) (add-hook 'change-major-mode-hook ',cmmh)) (remove-hook 'after-change-major-mode-hook ',buffers) + (remove-hook 'find-file-hook ',buffers) (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)))) ;;; --- 331,360 ---- ;; 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 ! (setq easy-mmode-stored-mode major-mode) ! (,turn-on)))))) ! (put ',buffers 'definition-name ',global-mode) ! ! (defun ,check-buffers () ! (remove-hook 'post-command-hook ',check-buffers) (while ,buffers (let ((buf (pop ,buffers))) (when (buffer-live-p buf) ! (with-current-buffer buf ! (if ,mode ! (unless (eq easy-mmode-stored-mode major-mode) ! (,mode -1) ! (,turn-on)) ! (,turn-on))))))) ;; The function that catches kill-all-local-variables. (defun ,cmmh () (add-to-list ',buffers (current-buffer)) ! (add-hook 'post-command-hook ',check-buffers)) (put ',cmmh 'definition-name ',global-mode)))) ;;; ============================================================