GNU bug report logs - #67795
[PATCH] Handle local-variable major-mode remaps specifying non-existent mode

Previous Next

Package: emacs;

Reported by: Brian Leung <leungbk <at> posteo.net>

Date: Tue, 12 Dec 2023 13:54:02 UTC

Severity: normal

Tags: patch

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Brian Leung <leungbk <at> posteo.net>
Cc: 67795 <at> debbugs.gnu.org
Subject: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode
Date: Tue, 05 Mar 2024 01:28:31 -0500
OK, I had another look at the problem.

For `hack-local-variables--find-variables` I still don't really
understand why we need this (eq handle-mode t) functionality
of the function, so maybe I missed a better way to fix the problem, but
the proposed hunk looks OK, tho it need to be updated to account for
recent changes in `master`.  The new hunk would look like:

    @@ -4235,7 +4241,7 @@ hack-local-variables--find-variables
     	        (forward-line 1)))))))
         (if (eq handle-mode t)
             ;; Return the final mode: setting that's defined.
    -        (car (seq-filter #'fboundp result))
    +        (car (seq-filter (lambda (mode) (fboundp (major-mode-remap mode))) result))
           result)))
     
     (defun hack-local-variables-apply ()

Tho the code can be streamlined a bit so as not to create a list only to
select its first element:

    @@ -4201,8 +4207,9 @@ hack-local-variables--find-variables
                               (not (string-match
                                     "-minor\\'"
                                     (setq val2 (downcase (symbol-name val)))))
    -                           ;; Allow several mode: elements.
    -                           (push (intern (concat val2 "-mode")) result))
    +                          (let ((mode (intern (concat val2 "-mode"))))
    +                             (when (fboundp (major-mode-remap mode))
    +                               (setq result mode))))
                        (cond ((eq var 'coding))
                              ((eq var 'lexical-binding)
                               (unless hack-local-variables--warned-lexical
    @@ -4233,10 +4240,7 @@ hack-local-variables--find-variables
                                             val)
                                        result))))))
                    (forward-line 1)))))))
    -    (if (eq handle-mode t)
    -        ;; Return the final mode: setting that's defined.
    -        (car (seq-filter #'fboundp result))
    -      result)))
    +    result))
     
     (defun hack-local-variables-apply ()
       "Apply the elements of `file-local-variables-alist'.

Any comment/objection on this part?


        Stefan





This bug report was last modified 1 year and 63 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.