]> git.eshelyaron.com Git - emacs.git/commitdiff
(Custom-dirlocals-mode): Let `define-derived-mode` do its job
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 28 Apr 2025 17:35:09 +0000 (13:35 -0400)
committerEshel Yaron <me@eshelyaron.com>
Tue, 29 Apr 2025 07:32:52 +0000 (09:32 +0200)
* lisp/cus-edit.el (Custom-dirlocals-mode-map): Rename from
`custom-dirlocals-map`.
(Custom-dirlocals-menu): Adjust accordingly.
(Custom-dirlocals-mode): Let `define-derived-mode` do its job.
Use `run-mode-hooks`.

(cherry picked from commit a0f26f3eaf1ccde728806003932dc9e44ef07e9d)

lisp/cus-edit.el

index 2b76c2b9b197739bfea4f774a382e5a5f9071e4a..5b01d4a27c38c3e563c262b94f63f14879d558ec 100644 (file)
@@ -5966,7 +5966,9 @@ This stores EXP (without evaluating it) as the saved spec for SYMBOL."
 (defvar-local custom-dirlocals-file-widget nil
   "Widget that holds the name of the dir-locals file being customized.")
 
-(defvar-keymap custom-dirlocals-map
+(define-obsolete-variable-alias 'custom-dirlocals-map
+  'Custom-dirlocals-mode-map "31.1")
+(defvar-keymap Custom-dirlocals-mode-map
   :doc "Keymap used in the \"*Customize Dirlocals*\" buffer."
   :full t
   :parent widget-keymap
@@ -5998,7 +6000,7 @@ This stores EXP (without evaluating it) as the saved spec for SYMBOL."
 See `custom-commands' for further explanation.")
 
 (easy-menu-define
-  Custom-dirlocals-menu (list custom-dirlocals-map
+  Custom-dirlocals-menu (list Custom-dirlocals-mode-map
                               custom-dirlocals-field-map)
   "Menu used in dirlocals customization buffers."
   (nconc (list "Custom"
@@ -6110,14 +6112,8 @@ Moves point into the widget that holds the value."
   (add-hook 'widget-forward-hook #'custom-dirlocals-maybe-update-cons nil t))
 
 (define-derived-mode Custom-dirlocals-mode nil "Custom dirlocals"
-  "Major mode for customizing Directory Local Variables in current directory.
-Entry to this mode calls the value of `Custom-mode-hook' if its value
-is non-nil.
-
-\\{custom-dirlocals-map}"
-  (kill-all-local-variables)
+  "Major mode for customizing Directory Local Variables in current directory."
   (custom-dirlocals--set-widget-vars)
-  (setq-local major-mode #'Custom-dirlocals-mode)
   (setq-local text-conversion-style 'action)
   (setq-local touch-screen-keyboard-function
               #'Custom-display-on-screen-keyboard-p)
@@ -6129,13 +6125,17 @@ is non-nil.
                     (mapc
                      (lambda (arg)
                        (tool-bar-local-item-from-menu
-                        (nth 1 arg) (nth 4 arg) map custom-dirlocals-map
+                        (nth 1 arg) (nth 4 arg) map Custom-dirlocals-mode-map
                         :label (nth 5 arg)))
                      custom-dirlocals-commands)
                     (setq custom-dirlocals-tool-bar-map map))))
-  (use-local-map custom-dirlocals-map)
-  (run-hooks 'Custom-mode-hook))
+  (run-mode-hooks 'Custom-mode-hook))
 
+;; As discussed in bug#77228, deriving from `Custom-mode' would
+;; include all their settings that are not necessary for
+;; `customize-dirlocals' and that can break it.
+;; FIXME: Introduce a `Custom-base-mode', which could be useful
+;; also for `gnus-custom-mode'.
 (derived-mode-add-parents 'Custom-dirlocals-mode '(Custom-mode))
 
 (defmacro custom-dirlocals-with-buffer (&rest body)