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: Sun, 29 May 2005 20:43:39 -0500 (CDT) Message-ID: <200505300143.j4U1hdj13485@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> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1117417573 23154 80.91.229.2 (30 May 2005 01:46:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 30 May 2005 01:46:13 +0000 (UTC) Cc: emacs-devel@gnu.org, monnier@iro.umontreal.ca, mmaug@yahoo.com, Lute.Kamstra.lists@xs4all.nl, dominik@science.uva.nl Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 30 03:46:01 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DcZLk-0004c4-MB for ged-emacs-devel@m.gmane.org; Mon, 30 May 2005 03:45:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DcZQX-0004FJ-9o for ged-emacs-devel@m.gmane.org; Sun, 29 May 2005 21:50:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DcZPW-0003WW-IB for emacs-devel@gnu.org; Sun, 29 May 2005 21:49:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DcZPO-0003Ru-TX for emacs-devel@gnu.org; Sun, 29 May 2005 21:49:39 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DcZPO-0003RC-1k for emacs-devel@gnu.org; Sun, 29 May 2005 21:49:38 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DcZLX-0001Rs-GD; Sun, 29 May 2005 21:45:39 -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 j4U1iACK023120; Sun, 29 May 2005 20:44:10 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.7p1+Sun/8.11.7) id j4U1hdj13485; Sun, 29 May 2005 20:43:39 -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 Sun, 29 May 2005 08:04:39 -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:37874 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:37874 Here is still another patch to easy-mmode. It gets rid of the new MODE-stored-mode variable, replacing it with the condition that dis- and re-enabling MODE should adapt MODE reliably to the current major mode. That means that one way or the other, we have to take care of Font Lock, which currently does not satisfy this condition. Either we make it satisfy the condition, or we still need a font-lock-mode-stored-hook and an associated error message. Note that even after this patch, there is one potentially troublesome case left. It concerns the case of a major mode that gets enabled by a timer or process for a non-file visiting buffer. (Even in this case it is only likely to occur for major modes that do not follow the new conventions.) It is easy to get rid of this remaining problem. However, it would require that not only the final check by find-file-hook or after-command-hook, but also the check by after-change-major-mode-hook, disables the mode if it already is enabled and then re-enables it. The patch below will sometimes, but only in a _very_ small minority of the cases, _unnecessarily_ disable and re-enable the mode. To get rid of the remaining problem, we would have to do such an unnecessary procedure nearly every time and occasionally we would disable and re-enable unnecessarily more than once. In practice, the remaining case probably only affects autoreverting of non-file buffers, so it means that each time we autorevert an additional non-file type, we would need to check that its usual major mode and its parent modes adhere to the new major mode conventions and do not cause trouble in some other freakish way. Again, if we are willing to pay a price in efficiency, getting rid of the remaining (rare) problem is easy. ===File ~/easy-mmode-diff=================================== *** easy-mmode.el 22 May 2005 16:50:33 -0500 1.63 --- easy-mmode.el 29 May 2005 17:52:33 -0500 *************** *** 271,283 **** 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. --- 271,291 ---- 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 disabling and reenabling MODE should make MODE work ! correctly with the current major mode. This is important to ! prevent problems with derived modes, that is, major modes that ! call another major mode in their body." ! (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")))) ;; Check keys. *************** *** 307,314 **** --- 315,324 ---- (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)))) ;;; --- 335,361 ---- ;; 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 ! (when ,mode (,mode -1)) ! (,turn-on)))))) ! (put ',buffers-check '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-check)) (put ',cmmh 'definition-name ',global-mode)))) ;;; ============================================================