From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: 58888@debbugs.gnu.org
Subject: bug#58888: 28.1.90; font-lock-defaults not respected when hack-local-variables unsafe variable dialogue is displayed before setting the defaults
Date: Wed, 10 Apr 2024 16:34:48 -0400 [thread overview]
Message-ID: <jwv5xwp6jpm.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87sezv3bct.fsf@localhost> (Ihor Radchenko's message of "Mon, 08 Apr 2024 19:25:54 +0000")
[-- Attachment #1: Type: text/plain, Size: 377 bytes --]
>> I pushed that patch to m`aster` because it fixed other cases
>> (e.g. bug#69431) but I think to fix bug#58888 we need the next step,
>> which is the patch below.
>>
>> Can you confirm that it fixes it for you as well?
>
> Yes, after make bootstrap, I am no longer able to reproduce the recipe.
Thanks for confirming.
Eli, any objection to the patch below?
Stefan
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-define-globalized-minor-mode-Require-the-use-of-run-.patch --]
[-- Type: text/x-diff, Size: 5622 bytes --]
From 4fd9a51b4d9f2e2e0c04341eeabb656884059301 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Wed, 10 Apr 2024 16:31:58 -0400
Subject: [PATCH] (define-globalized-minor-mode): Require the use of
`run-mode-hooks`
When `define-globalized-minor-mode` was introduced (Emacs-22),
`run-mode-hooks` was brand new, so we could not expect all major
modes to use it and we had to rely on brittle workarounds to try
and approximate `after-change-major-mode-hook`.
These workarounds have undesirable side effects, and they're not
needed any more now that virtually all major modes have been
changed to use `run-mode-hooks`.
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Rely only on `after-change-major-mode-hook`. Fixes bug#58888.
---
etc/NEWS | 6 ++++
lisp/emacs-lisp/easy-mmode.el | 58 +++--------------------------------
2 files changed, 10 insertions(+), 54 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index a2a3fe494cb..0da59201e55 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1658,6 +1658,12 @@ documentation and examples.
\f
* Incompatible Lisp Changes in Emacs 30.1
+** 'define-globalized-minor-mode' requires that modes use 'run-mode-hooks'.
+Minor modes defined with 'define-globalized-minor-mode', such as
+'global-font-lock-mode', don't work any more with major modes which
+don't use 'run-mode-hooks'. Major modes defined with
+'define-derived-mode' are not affected.
+
---
** Old derived.el functions removed.
The following functions have been deleted because they were only used
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 095bd5faa03..eaad9646985 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -495,11 +495,6 @@ define-globalized-minor-mode
(MODE-buffers (intern (concat global-mode-name "-buffers")))
(MODE-enable-in-buffer
(intern (concat global-mode-name "-enable-in-buffer")))
- (MODE-enable-in-buffers
- (intern (concat global-mode-name "-enable-in-buffers")))
- (MODE-check-buffers
- (intern (concat global-mode-name "-check-buffers")))
- (MODE-cmhh (intern (concat global-mode-name "-cmhh")))
(minor-MODE-hook (intern (concat mode-name "-hook")))
(MODE-set-explicitly (intern (concat mode-name "-set-explicitly")))
(MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
@@ -559,14 +554,9 @@ define-globalized-minor-mode
;; Setup hook to handle future mode changes and new buffers.
(if ,global-mode
- (progn
- (add-hook 'after-change-major-mode-hook
- #',MODE-enable-in-buffer)
- (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-buffer)
- (remove-hook 'find-file-hook #',MODE-check-buffers)
- (remove-hook 'change-major-mode-hook #',MODE-cmhh))
+ (add-hook 'after-change-major-mode-hook
+ #',MODE-enable-in-buffer)
+ (remove-hook 'after-change-major-mode-hook #',MODE-enable-in-buffer))
;; Go through existing buffers.
(dolist (buf (buffer-list))
@@ -623,47 +613,7 @@ define-globalized-minor-mode
(funcall ,turn-on-function))
(funcall ,turn-on-function))))
(setq ,MODE-major-mode major-mode))
- (put ',MODE-enable-in-buffer 'definition-name ',global-mode)
-
- ;; In the normal case, major modes run `after-change-major-mode-hook'
- ;; which will have called `MODE-enable-in-buffer' for us. But some
- ;; major modes don't use `run-mode-hooks' (customarily used via
- ;; `define-derived-mode') and thus fail to run
- ;; `after-change-major-mode-hook'.
- ;; The functions below try to handle those major modes, with
- ;; a combination of ugly hacks to try and catch those corner
- ;; cases by listening to `change-major-mode-hook' to discover
- ;; potential candidates and then checking in `post-command-hook'
- ;; and `find-file-hook' if some of those still haven't run
- ;; `after-change-major-mode-hook'. FIXME: We should try and get
- ;; rid of this ugly hack and rely purely on
- ;; `after-change-major-mode-hook' because they can (and do) end
- ;; up running `MODE-enable-in-buffer' too early (when the major
- ;; isn't yet fully setup) in some cases (see bug#58888).
-
- ;; The function that calls TURN-ON in each buffer.
- (defun ,MODE-enable-in-buffers ()
- (let ((buffers ,MODE-buffers))
- ;; Clear MODE-buffers to avoid scanning the same list of
- ;; buffers in recursive calls to MODE-enable-in-buffers.
- ;; Otherwise it could lead to infinite recursion.
- (setq ,MODE-buffers nil)
- (dolist (buf buffers)
- (when (buffer-live-p buf)
- (with-current-buffer buf
- (,MODE-enable-in-buffer))))))
- (put ',MODE-enable-in-buffers 'definition-name ',global-mode)
-
- (defun ,MODE-check-buffers ()
- (,MODE-enable-in-buffers)
- (remove-hook 'post-command-hook #',MODE-check-buffers))
- (put ',MODE-check-buffers 'definition-name ',global-mode)
-
- ;; The function that catches kill-all-local-variables.
- (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))))
+ (put ',MODE-enable-in-buffer 'definition-name ',global-mode))))
(defun easy-mmode--globalized-predicate-p (predicate)
(cond
--
2.43.0
next prev parent reply other threads:[~2024-04-10 20:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 6:58 bug#58888: 28.1.90; font-lock-defaults not respected when hack-local-variables unsafe variable dialogue is displayed before setting the defaults Ihor Radchenko
2022-10-31 2:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-31 7:11 ` Ihor Radchenko
2024-04-08 12:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 13:15 ` Eli Zaretskii
2024-04-08 13:42 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 19:25 ` Ihor Radchenko
2024-04-10 20:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-04-11 6:20 ` Eli Zaretskii
2024-04-11 13:27 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-11 14:12 ` Eli Zaretskii
2024-04-13 14:32 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-11 13:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-11 14:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=jwv5xwp6jpm.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=58888@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=yantar92@posteo.net \
/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.