branch: elpa/git-commit
commit 6359e5c98fb55f270464a22f10e8552e989084ab
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit-hack-dir-local-variables: New function
    
    Users and package authors don't always realize that its possible
    to respect directory local variables in `special-mode's, causing
    them to set variables that are not suitable in such modes, without
    restricting them to a known good set of modes (by using nil as the
    mode key in ".dir-locals{,-2}.el".
---
 lisp/magit-diff.el    | 6 +++---
 lisp/magit-log.el     | 6 +++---
 lisp/magit-mode.el    | 9 ++++++++-
 lisp/magit-process.el | 2 +-
 lisp/magit-reflog.el  | 2 +-
 lisp/magit-refs.el    | 2 +-
 lisp/magit-stash.el   | 4 ++--
 lisp/magit-status.el  | 2 +-
 8 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index bef7d7b277..81631fc3e3 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1959,7 +1959,7 @@ Staging and applying changes is documented in info node
 
 \\{magit-diff-mode-map}"
   :group 'magit-diff
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-item-types 'file))
 
 (put 'magit-diff-mode 'magit-diff-default-arguments
@@ -2554,7 +2554,7 @@ Staging and applying changes is documented in info node
 
 \\{magit-revision-mode-map}"
   :group 'magit-revision
-  (hack-dir-local-variables-non-file-buffer))
+  (magit-hack-dir-local-variables))
 
 (put 'magit-revision-mode 'magit-diff-default-arguments
      '("--stat" "--no-ext-diff"))
@@ -2900,7 +2900,7 @@ Refer to user option 
`magit-revision-insert-related-refs-display-alist'."
 (define-derived-mode magit-merge-preview-mode magit-diff-mode "Magit Merge"
   "Mode for previewing a merge."
   :group 'magit-diff
-  (hack-dir-local-variables-non-file-buffer))
+  (magit-hack-dir-local-variables))
 
 (put 'magit-merge-preview-mode 'magit-diff-default-arguments
      '("--no-ext-diff"))
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index abac378acc..4682b38128 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -1061,7 +1061,7 @@ Type \\[magit-reset] to reset `HEAD' to the commit at 
point.
 
 \\{magit-log-mode-map}"
   :group 'magit-log
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-item-types 'commit))
 
 (put 'magit-log-mode 'magit-log-default-arguments
@@ -1690,7 +1690,7 @@ to visit the commit at point.
 Type \\[magit-log-select-pick] to select the commit at point.
 Type \\[magit-log-select-quit] to abort without selecting a commit."
   :group 'magit-log
-  (hack-dir-local-variables-non-file-buffer))
+  (magit-hack-dir-local-variables))
 
 (put 'magit-log-select-mode 'magit-log-default-arguments
      '("--graph" "-n256" "--decorate"))
@@ -1790,7 +1790,7 @@ Type \\[magit-cherry-pick] to apply the commit at point.
 
 \\{magit-cherry-mode-map}"
   :group 'magit-log
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-group-types 'cherries))
 
 (defun magit-cherry-setup-buffer (head upstream)
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 2547505ea5..92813eabad 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -553,7 +553,7 @@ to the kill ring."
 
 Magit is documented in info node `(magit)'."
   :group 'magit
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (face-remap-add-relative 'header-line 'magit-header-line)
   (setq mode-line-process (magit-repository-local-get 'mode-line-process))
   (setq-local revert-buffer-function #'magit-refresh-buffer)
@@ -562,6 +562,13 @@ Magit is documented in info node `(magit)'."
   (setq-local imenu-default-goto-function #'magit--imenu-goto-function)
   (setq-local isearch-filter-predicate #'magit-section--open-temporarily))
 
+(defun magit-hack-dir-local-variables ()
+  "Like `hack-dir-local-variables-non-file-buffer' but ignore some variables."
+  (let ((ignored-local-variables
+         `(show-trailing-whitespace
+           ,@ignored-local-variables)))
+    (hack-dir-local-variables-non-file-buffer)))
+
 ;;; Local Variables
 
 (defvar-local magit-buffer-arguments nil)
diff --git a/lisp/magit-process.el b/lisp/magit-process.el
index 1368231935..eb9cdd3e10 100644
--- a/lisp/magit-process.el
+++ b/lisp/magit-process.el
@@ -310,7 +310,7 @@ Used when `magit-process-display-mode-line-error' is 
non-nil."
 (define-derived-mode magit-process-mode magit-mode "Magit Process"
   "Mode for looking at Git process output."
   :group 'magit-process
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-item-types 'process))
 
 (defun magit-process-buffer (&optional nodisplay)
diff --git a/lisp/magit-reflog.el b/lisp/magit-reflog.el
index ef9d9b2ecb..751a2e09b5 100644
--- a/lisp/magit-reflog.el
+++ b/lisp/magit-reflog.el
@@ -151,7 +151,7 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
 
 \\{magit-reflog-mode-map}"
   :group 'magit-log
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-item-types 'commit))
 
 (defun magit-reflog-setup-buffer (ref)
diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index 1d7144415d..1ebe5bd16d 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -295,7 +295,7 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
 
 \\{magit-refs-mode-map}"
   :group 'magit-refs
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-group-types '(local remote tags)))
 
 (defun magit-refs-setup-buffer (ref args)
diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el
index 72f4a88ff2..37b60cf2f6 100644
--- a/lisp/magit-stash.el
+++ b/lisp/magit-stash.el
@@ -512,7 +512,7 @@ instead of \"Stashes:\"."
 (define-derived-mode magit-stashes-mode magit-reflog-mode "Magit Stashes"
   "Mode for looking at lists of stashes."
   :group 'magit-log
-  (hack-dir-local-variables-non-file-buffer))
+  (magit-hack-dir-local-variables))
 
 (defun magit-stashes-setup-buffer ()
   (magit-setup-buffer #'magit-stashes-mode nil
@@ -573,7 +573,7 @@ If there is no stash buffer in the same frame, then do 
nothing."
 (define-derived-mode magit-stash-mode magit-diff-mode "Magit Stash"
   "Mode for looking at individual stashes."
   :group 'magit-diff
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (setq magit--imenu-group-types '(commit)))
 
 (defun magit-stash-setup-buffer (stash args files)
diff --git a/lisp/magit-status.el b/lisp/magit-status.el
index afc558807f..3d3cf561a7 100644
--- a/lisp/magit-status.el
+++ b/lisp/magit-status.el
@@ -386,7 +386,7 @@ Type \\[magit-commit] to create a commit.
 
 \\{magit-status-mode-map}"
   :group 'magit-status
-  (hack-dir-local-variables-non-file-buffer)
+  (magit-hack-dir-local-variables)
   (when magit-status-initial-section
     (add-hook 'magit-post-create-buffer-hook
               #'magit-status-goto-initial-section nil t))

Reply via email to