From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Subject: Re: Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch]
Date: Mon, 14 Jan 2013 16:30:03 +0000 [thread overview]
Message-ID: <20130114163003.GC3274@acm.acm> (raw)
In-Reply-To: <20130113192854.GA4853@acm.acm>
Hi, Emacs.
On Sun, Jan 13, 2013 at 07:28:54PM +0000, Alan Mackenzie wrote:
> The situation here is the direct cause of bug #11152, where in CC Mode,
> doc comments whose fontification is specified in a mode hook don't get
> fontified properly, or at all. It would be good to fix this bug for
> Emacs 24.3.
> In define-globalized-minor-mode L72-75, the newly defined -enable-
> function is added to both the following hooks:
> change-major-mode-after-body-hook
> after-change-major-mode-hook
> . (These hooks are run before and after the major mode hook.)
> It seems the hacker who formulated this macro was undecided whether to
> run the -enable- function before or after the mode hooks, so decided
> upon both as a compromise. This isn't harmless.
> In particular, running `global-font-lock-mode-enable-in-buffers' before
> the objc-mode-hook causes a one-time font-lock-keywords initialisation
> to happen before a critical initialisation has been performed by that
> hook.
> Can some means be found so that `font-lock-mode' isn't called twice?
> (For that matter, `global-hi-lock-mode-enable-in-buffers' doesn't need
> calling twice, either.) Such a means might be the addition of another
> parameter to define-globalized-minor-mode specifying when the -enable-
> call should take place.
I propose to amend define-globalized-minor-mode such that the generated
-enable- function gets added to precisely one of the following hooks, not
both:
change-major-mode-after-body-hook
after-change-major-mode-hook
, the latter one by default. To change this default, the new
keyword-parameter :call-before-hook is introduced. I think this
amendment should go into Emacs 24.3 (it "solves" bug #11152).
There are 6 invocations of define-globalized-minor-mode in Emacs,
1 global-visual-line-mode
2 global-hi-lock-mode
3 global-font-lock-mode
4 global-cwarn-mode
5 global-linum-mode
6 global-highlight-changes-mode
. 2 and 3 appear to work fine with the amended macro. I haven't tested
the others.
Here is the patch to the .el file (another will be needed for NEWS):
=== 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-01-14 15:50:50 +0000
***************
*** 329,335 ****
and that should try to turn MODE on if applicable for that buffer.
KEYS is a list of CL-style keyword arguments. As the minor mode
defined by this function is always global, any :global keyword is
! ignored. Other keywords have the same meaning as in `define-minor-mode',
which see. In particular, :group specifies the custom group.
The most useful keywords are those that are passed on to the
`defcustom'. It normally makes no sense to pass the :lighter
--- 329,338 ----
and that should try to turn MODE on if applicable for that buffer.
KEYS is a list of CL-style keyword arguments. As the minor mode
defined by this function is always global, any :global keyword is
! ignored. If :call-before-hook is present with a non-nil argument, TURN-ON
! will be called before running the major mode's hook, otherwise it will be
! called afterwards.
! Other keywords have the same meaning as in `define-minor-mode',
which see. In particular, :group specifies the custom group.
The most useful keywords are those that are passed on to the
`defcustom'. It normally makes no sense to pass the :lighter
***************
*** 346,351 ****
--- 349,355 ----
(pretty-name (easy-mmode-pretty-mode-name mode))
(pretty-global-name (easy-mmode-pretty-mode-name global-mode))
(group nil)
+ (call-before-hook nil)
(extra-keywords nil)
(MODE-buffers (intern (concat global-mode-name "-buffers")))
(MODE-enable-in-buffers
***************
*** 362,367 ****
--- 366,372 ----
(pcase keyw
(`:group (setq group (nconc group (list :group (pop keys)))))
(`:global (setq keys (cdr keys)))
+ (`:call-before-hook (setq call-before-hook (pop keys)))
(_ (push keyw extra-keywords) (push (pop keys) extra-keywords))))
(unless group
***************
*** 394,402 ****
;; Setup hook to handle future mode changes and new buffers.
(if ,global-mode
(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))
--- 399,407 ----
;; Setup hook to handle future mode changes and new buffers.
(if ,global-mode
(progn
! (add-hook ',(if call-before-hook
! 'change-major-mode-after-body-hook
! 'after-change-major-mode-hook)
',MODE-enable-in-buffers)
(add-hook 'find-file-hook ',MODE-check-buffers)
(add-hook 'change-major-mode-hook ',MODE-cmhh))
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2013-01-14 16:30 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 ` Alan Mackenzie [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130114163003.GC3274@acm.acm \
--to=acm@muc.de \
--cc=emacs-devel@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.