From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "João Távora" <joaotavora@gmail.com>,
"Chong Yidong" <cyd@gnu.org>, "Leo Liu" <sdl.web@gmail.com>,
emacs-devel@gnu.org
Subject: Re: Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch-2]
Date: Fri, 1 Feb 2013 19:53:52 +0000 [thread overview]
Message-ID: <20130201195352.GB23075@acm.acm> (raw)
In-Reply-To: <jwvpq0kovah.fsf-monnier+emacs@gnu.org>
Hi, Stefan.
On Fri, Feb 01, 2013 at 11:28:00AM -0500, Stefan Monnier wrote:
> > I'm not so sure about this. These complicated structures of macros and
> > hooks and generated functions are making my head hurt. ;-( Are you
> > sure there are no ways of invoking this which won't bypass
> > kill-all-local-variables? (That's a real question, not a rhetorical
> > one.)
> Any major mode will have to call kill-all-local-variables, so it's
> pretty sure.
OK, I see it now. I've removed that function, replacing it with a
comment about kill-all-local-variables attending to disable-MODE.
I've also tidied up the new bit of doc-string I added,
Is it OK to commit this change to emacs-24 now, and close bug#11152?
Here's the patch:
=== modified file 'lisp/emacs-lisp/easy-mmode.el'
*** lisp/emacs-lisp/easy-mmode.el 2013-01-01 09:11:05 +0000
--- lisp/emacs-lisp/easy-mmode.el 2013-02-01 19:13:42 +0000
***************
*** 340,348 ****
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."
(declare (doc-string 2))
(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)
--- 340,353 ----
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.
!
! When a major mode is initialized, MODE is actually turned on just
! after running the major mode's hook. However, MODE is not turned
! on if the hook has expllicitly disabled it."
(declare (doc-string 2))
(let* ((global-mode-name (symbol-name global-mode))
+ (mode-name (symbol-name mode))
(pretty-name (easy-mmode-pretty-mode-name mode))
(pretty-global-name (easy-mmode-pretty-mode-name global-mode))
(group nil)
***************
*** 353,358 ****
--- 358,367 ----
(MODE-check-buffers
(intern (concat global-mode-name "-check-buffers")))
(MODE-cmhh (intern (concat global-mode-name "-cmhh")))
+ (MODE-disable-in-buffer
+ (intern (concat global-mode-name "-disable-in-buffer")))
+ (minor-MODE-hook (intern (concat mode-name "-hook")))
+ (disable-MODE (intern (concat "disable-" mode-name)))
(MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
keyw)
***************
*** 396,403 ****
(progn
(add-hook 'after-change-major-mode-hook
',MODE-enable-in-buffers)
- (add-hook 'change-major-mode-after-body-hook
- ',MODE-enable-in-buffers)
(add-hook 'find-file-hook ',MODE-check-buffers)
(add-hook 'change-major-mode-hook ',MODE-cmhh))
(remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers)
--- 405,410 ----
***************
*** 415,420 ****
--- 422,431 ----
;; up-to-here.
:autoload-end
+ ;; A function which checks whether MODE has been disabled in the major
+ ;; mode hook which has just been run.
+ (add-hook ',minor-MODE-hook ',MODE-disable-in-buffer)
+
;; List of buffers left to process.
(defvar ,MODE-buffers nil)
***************
*** 423,436 ****
(dolist (buf ,MODE-buffers)
(when (buffer-live-p buf)
(with-current-buffer buf
! (unless (eq ,MODE-major-mode major-mode)
! (if ,mode
! (progn
! (,mode -1)
! (,turn-on)
! (setq ,MODE-major-mode major-mode))
! (,turn-on)
! (setq ,MODE-major-mode major-mode)))))))
(put ',MODE-enable-in-buffers 'definition-name ',global-mode)
(defun ,MODE-check-buffers ()
--- 434,448 ----
(dolist (buf ,MODE-buffers)
(when (buffer-live-p buf)
(with-current-buffer buf
! (if ,disable-MODE
! (if ,mode (,mode -1))
! (unless (eq ,MODE-major-mode major-mode)
! (if ,mode
! (progn
! (,mode -1)
! (,turn-on))
! (,turn-on))))
! (setq ,MODE-major-mode major-mode)))))
(put ',MODE-enable-in-buffers 'definition-name ',global-mode)
(defun ,MODE-check-buffers ()
***************
*** 443,449 ****
(defun ,MODE-cmhh ()
(add-to-list ',MODE-buffers (current-buffer))
(add-hook 'post-command-hook ',MODE-check-buffers))
! (put ',MODE-cmhh 'definition-name ',global-mode))))
;;;
;;; easy-mmode-defmap
--- 455,468 ----
(defun ,MODE-cmhh ()
(add-to-list ',MODE-buffers (current-buffer))
(add-hook 'post-command-hook ',MODE-check-buffers))
! (put ',MODE-cmhh 'definition-name ',global-mode)
! ;; disable-MODE is set in MODE-disable-in-buffer and cleared by
! ;; kill-all-local-variables.
! (defvar-local ,disable-MODE nil)
! (defun ,MODE-disable-in-buffer ()
! (unless ,mode
! (setq ,disable-MODE t)))
! (put ',MODE-disable-in-buffer 'definition-name ',global-mode))))
;;;
;;; easy-mmode-defmap
> Stefan
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2013-02-01 19:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-13 19:28 Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode Alan Mackenzie
2013-01-13 20:48 ` Dmitry Gutov
2013-01-14 16:30 ` Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch] Alan Mackenzie
2013-01-14 16:52 ` emacs24/auctex bug Camm Maguire
2013-01-14 23:58 ` Xue Fuqiao
2013-01-15 2:12 ` Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch] Stefan Monnier
2013-01-15 14:08 ` Alan Mackenzie
2013-01-17 13:17 ` João Távora
2013-01-17 17:51 ` Alan Mackenzie
2013-01-17 18:31 ` Stefan Monnier
2013-01-18 12:07 ` João Távora
2013-01-18 17:09 ` Alan Mackenzie
2013-01-31 11:04 ` Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch-2] Alan Mackenzie
2013-01-31 14:38 ` Stefan Monnier
2013-02-01 15:44 ` Alan Mackenzie
2013-02-01 16:28 ` Stefan Monnier
2013-02-01 19:53 ` Alan Mackenzie [this message]
2013-02-01 20:09 ` Achim Gratz
2013-02-01 20:15 ` Alan Mackenzie
2013-02-01 23:17 ` Stefan Monnier
2013-02-01 23:16 ` Stefan Monnier
2013-02-03 22:14 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130201195352.GB23075@acm.acm \
--to=acm@muc.de \
--cc=cyd@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=joaotavora@gmail.com \
--cc=monnier@iro.umontreal.ca \
--cc=sdl.web@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).