From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Brian Leung <leungbk@posteo.net>, 67795@debbugs.gnu.org
Subject: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode
Date: Tue, 12 Dec 2023 11:02:43 -0500 [thread overview]
Message-ID: <jwvo7eve83e.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83plzbtt2w.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 12 Dec 2023 16:04:55 +0200")
[-- Attachment #1: Type: text/plain, Size: 668 bytes --]
> Thanks, but if we want to integrate major-mode-remap-alist better, I'd
> rather we did that in some lower-level place, so that we wouldn't need
> to sprinkle these alist-get calls all over Emacs.
>
> Also, if we do this, there will be no way for specifying a particular
> mode in file-local variables. Do we really want that?
>
> Stefan, WDYT?
I agree that we should try to keep it in "one place", but I don't think
it can be done right now without some code reorganization :-(
I can't wrap my head around what `hack-local-variables--find-variables`
is supposed to do, but for the other part of the change, maybe the patch
below is a good start?
Stefan
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mode-remap.patch --]
[-- Type: text/x-diff, Size: 3425 bytes --]
diff --git a/lisp/files.el b/lisp/files.el
index f87e7807301..1935e4dbb4b 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3428,12 +3451,9 @@ set-auto-mode
(if modes
(catch 'nop
(dolist (mode (nreverse modes))
- (if (not (functionp mode))
- (message "Ignoring unknown mode `%s'" mode)
- (setq done t)
- (or (set-auto-mode-0 mode keep-mode-if-same)
- ;; continuing would call minor modes again, toggling them off
- (throw 'nop nil))))))
+ (or (setq done (set-auto-mode-0 mode keep-mode-if-same))
+ ;; continuing would call minor modes again, toggling them off
+ (throw 'nop nil)))))
;; Check for auto-mode-alist entry in dir-locals.
(unless done
(with-demoted-errors "Directory-local variables error: %s"
@@ -3445,10 +3465,7 @@ set-auto-mode
(and (not done)
(setq mode (hack-local-variables t (not try-locals)))
(not (memq mode modes)) ; already tried and failed
- (if (not (functionp mode))
- (message "Ignoring unknown mode `%s'" mode)
- (setq done t)
- (set-auto-mode-0 mode keep-mode-if-same)))
+ (setq done (set-auto-mode-0 mode keep-mode-if-same)))
;; If we didn't, look for an interpreter specified in the first line.
;; As a special case, allow for things like "#!/bin/env perl", which
;; finds the interpreter anywhere in $PATH.
@@ -3490,7 +3507,7 @@ set-auto-mode
(error
"Problem in magic-mode-alist with element %s"
re))))))))
- (set-auto-mode-0 done keep-mode-if-same)))
+ (setq done (set-auto-mode-0 done keep-mode-if-same))))
;; Next compare the filename against the entries in auto-mode-alist.
(unless done
(setq done (set-auto-mode--apply-alist auto-mode-alist
@@ -3515,7 +3532,7 @@ set-auto-mode
(error
"Problem with magic-fallback-mode-alist element: %s"
re))))))))
- (set-auto-mode-0 done keep-mode-if-same)))
+ (setq done (set-auto-mode-0 done keep-mode-if-same))))
(unless done
(set-buffer-major-mode (current-buffer)))))
@@ -3539,17 +3556,22 @@ set-auto-mode-0
If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of
any aliases and compared to current major mode. If they are the
same, do nothing and return nil."
- (unless (and keep-mode-if-same
- (or (eq (indirect-function mode)
+ (let ((modefun (alist-get mode major-mode-remap-alist mode)))
+ (unless (and keep-mode-if-same
+ (or (eq (indirect-function mode)
(indirect-function major-mode))
(and set-auto-mode--last
(eq mode (car set-auto-mode--last))
(eq major-mode (cdr set-auto-mode--last)))))
- (when mode
- (funcall (alist-get mode major-mode-remap-alist mode))
- (unless (eq mode major-mode)
- (setq set-auto-mode--last (cons mode major-mode)))
- mode)))
+ (when mode
+ (if (not (functionp modefun))
+ (progn
+ (message "Ignoring unknown mode `%s'" mode)
+ nil)
+ (funcall modefun)
+ (unless (eq mode major-mode)
+ (setq set-auto-mode--last (cons mode major-mode)))
+ mode)))))
(defvar file-auto-mode-skip "^\\(#!\\|'\\\\\"\\)"
"Regexp of lines to skip when looking for file-local settings.
next prev parent reply other threads:[~2023-12-12 16:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 13:52 bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode Brian Leung
2023-12-12 14:04 ` Eli Zaretskii
2023-12-12 16:02 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-12-12 17:17 ` Eli Zaretskii
2024-03-05 6:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-05 7:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-15 2:17 ` 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=jwvo7eve83e.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=67795@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=leungbk@posteo.net \
--cc=monnier@iro.umontreal.ca \
/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.