]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix local variables overwritten when diff-mode is set
authorMatthias Meulien <orontee@gmail.com>
Tue, 9 Nov 2021 03:46:53 +0000 (04:46 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 9 Nov 2021 03:46:53 +0000 (04:46 +0100)
* lisp/vc/diff-mode.el (diff-mode):
(diff-setup-buffer-type): Defun to initialize `diff-buffer-type'

* lisp/vc/vc.el (vc-diff-finish): Set `diff-buffer-type' after content
inserted
(vc-diff-internal): Restore `diff-mode' being set before local
variables (bug#51016).

lisp/vc/diff-mode.el
lisp/vc/vc.el

index 746f76b46c3b96ddc02015e5fc9ac571540bee2c..9bac3aa67d89f1fb687f9dee74841fc710d97111 100644 (file)
@@ -1475,6 +1475,21 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
     ;; Added when diff--font-lock-prettify is non-nil!
     (cl-pushnew 'display font-lock-extra-managed-props)))
 
+(defun diff-setup-buffer-type ()
+  "Try to guess the `diff-buffer-type' from content of current Diff mode buffer.
+`outline-regexp' is updated accordingly."
+  (save-excursion
+    (goto-char (point-min))
+    (setq-local diff-buffer-type
+                (if (re-search-forward "^diff --git" nil t)
+                    'git
+                  nil)))
+  (when (eq diff-buffer-type 'git)
+    (setq diff-outline-regexp
+          (concat "\\(^diff --git.*\n\\|" diff-hunk-header-re "\\)"))
+    (setq-local outline-level #'diff--outline-level))
+  (setq-local outline-regexp diff-outline-regexp))
+
 (defvar whitespace-style)
 (defvar whitespace-trailing-regexp)
 
@@ -1540,16 +1555,7 @@ a diff with \\[diff-reverse-direction].
                 #'diff--filter-substring)
   (unless buffer-file-name
     (hack-dir-local-variables-non-file-buffer))
-  (save-excursion
-    (setq-local diff-buffer-type
-                (if (re-search-forward "^diff --git" nil t)
-                    'git
-                  nil)))
-  (when (eq diff-buffer-type 'git)
-    (setq diff-outline-regexp
-          (concat "\\(^diff --git.*\n\\|" diff-hunk-header-re "\\)"))
-    (setq-local outline-level #'diff--outline-level))
-  (setq-local outline-regexp diff-outline-regexp))
+  (diff-setup-buffer-type))
 
 ;;;###autoload
 (define-minor-mode diff-minor-mode
index c9500f454ae9cf8819050f59471132f49f05b477..87137d8ede25a4dea15602486e73895dc9226aa9 100644 (file)
@@ -1739,6 +1739,7 @@ to override the value of `vc-diff-switches' and `diff-switches'."
               (insert (cdr messages) ".\n")
               (message "%s" (cdr messages))))
        (diff-setup-whitespace)
+        (diff-setup-buffer-type)
        (goto-char (point-min))
        (when window
          (shrink-window-if-larger-than-buffer window)))
@@ -1804,6 +1805,7 @@ Return t if the buffer had changes, nil otherwise."
         (setq files (nreverse filtered))))
     (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async)
     (set-buffer buffer)
+    (diff-mode)
     (setq-local diff-vc-backend (car vc-fileset))
     (setq-local diff-vc-revisions (list rev1 rev2))
     (setq-local revert-buffer-function
@@ -1825,9 +1827,7 @@ Return t if the buffer had changes, nil otherwise."
       ;; after `pop-to-buffer'; the former assumes the diff buffer is
       ;; shown in some window.
       (let ((buf (current-buffer)))
-        (vc-run-delayed (progn
-                          (vc-diff-finish buf (when verbose messages))
-                          (diff-mode))))
+        (vc-run-delayed (vc-diff-finish buf (when verbose messages))))
       ;; In the async case, we return t even if there are no differences
       ;; because we don't know that yet.
       t)))