aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2022-01-10 20:29:53 +0200
committerJuri Linkov2022-01-10 20:29:53 +0200
commit97806bc7deeec7ab1458eb5ff689f46ec8e7c652 (patch)
treee454d7c0aad622aa9639bb4b4d46f6ce067f05e7
parent2b7a486605c01f7927de47ec2788f1eb2a4c0142 (diff)
downloademacs-97806bc7deeec7ab1458eb5ff689f46ec8e7c652.tar.gz
emacs-97806bc7deeec7ab1458eb5ff689f46ec8e7c652.zip
Add diff-mode-read-only to enable shorter keys in diff-mode
To be able to use outline-minor-mode-cycle keys in diff-mode, outline-minor-mode should be higher in minor-mode-map-alist, and a new variable diff-mode-read-only should be set when the diff-mode buffer is read-only. https://lists.gnu.org/archive/html/emacs-devel/2022-01/msg00740.html * lisp/vc/diff-mode.el: Add diff-mode-read-only to minor-mode-map-alist. (diff-mode-read-only): New buffer-local variable. (diff-mode): Set diff-mode-read-only to t when buffer-read-only is non-nil. Update diff-mode-read-only in read-only-mode-hook. Remove buffer-read-only from minor-mode-overriding-map-alist. Remove view-mode-hook because now view-mode is higher than diff-mode-read-only in minor-mode-map-alist. * lisp/vc/vc-git.el (vc-git-stash-show): * lisp/vc/vc.el (vc-diff-internal): Set buffer-read-only to t before calling diff-mode that will set diff-mode-read-only.
-rw-r--r--lisp/vc/diff-mode.el30
-rw-r--r--lisp/vc/vc-git.el2
-rw-r--r--lisp/vc/vc.el8
3 files changed, 24 insertions, 16 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index ca8df5d3805..37eaf254fdb 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -1479,6 +1479,14 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
1479(defvar whitespace-style) 1479(defvar whitespace-style)
1480(defvar whitespace-trailing-regexp) 1480(defvar whitespace-trailing-regexp)
1481 1481
1482(defvar-local diff-mode-read-only nil
1483 "Non-nil when read-only diff buffer uses short keys.")
1484
1485;; It should be lower than `outline-minor-mode' and `view-mode'.
1486(or (assq 'diff-mode-read-only minor-mode-map-alist)
1487 (nconc minor-mode-map-alist
1488 (list (cons 'diff-mode-read-only diff-mode-shared-map))))
1489
1482;;;###autoload 1490;;;###autoload
1483(define-derived-mode diff-mode fundamental-mode "Diff" 1491(define-derived-mode diff-mode fundamental-mode "Diff"
1484 "Major mode for viewing/editing context diffs. 1492 "Major mode for viewing/editing context diffs.
@@ -1516,23 +1524,23 @@ a diff with \\[diff-reverse-direction].
1516 1524
1517 (diff-setup-whitespace) 1525 (diff-setup-whitespace)
1518 1526
1519 (if diff-default-read-only 1527 ;; read-only setup
1520 (setq buffer-read-only t)) 1528 (when diff-default-read-only
1529 (setq buffer-read-only t))
1530 (when buffer-read-only
1531 (setq diff-mode-read-only t))
1532 (add-hook 'read-only-mode-hook
1533 (lambda ()
1534 (setq diff-mode-read-only buffer-read-only))
1535 nil t)
1536
1521 ;; setup change hooks 1537 ;; setup change hooks
1522 (if (not diff-update-on-the-fly) 1538 (if (not diff-update-on-the-fly)
1523 (add-hook 'write-contents-functions #'diff-write-contents-hooks nil t) 1539 (add-hook 'write-contents-functions #'diff-write-contents-hooks nil t)
1524 (make-local-variable 'diff-unhandled-changes) 1540 (make-local-variable 'diff-unhandled-changes)
1525 (add-hook 'after-change-functions #'diff-after-change-function nil t) 1541 (add-hook 'after-change-functions #'diff-after-change-function nil t)
1526 (add-hook 'post-command-hook #'diff-post-command-hook nil t)) 1542 (add-hook 'post-command-hook #'diff-post-command-hook nil t))
1527 ;; Neat trick from Dave Love to add more bindings in read-only mode: 1543
1528 (let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
1529 (add-to-list 'minor-mode-overriding-map-alist ro-bind)
1530 ;; Turn off this little trick in case the buffer is put in view-mode.
1531 (add-hook 'view-mode-hook
1532 (lambda ()
1533 (setq minor-mode-overriding-map-alist
1534 (delq ro-bind minor-mode-overriding-map-alist)))
1535 nil t))
1536 ;; add-log support 1544 ;; add-log support
1537 (setq-local add-log-current-defun-function #'diff-current-defun) 1545 (setq-local add-log-current-defun-function #'diff-current-defun)
1538 (setq-local add-log-buffer-file-name-function 1546 (setq-local add-log-buffer-file-name-function
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 2e6690c5376..ad39dc604a9 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1695,8 +1695,8 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
1695 (vc-setup-buffer "*vc-git-stash*") 1695 (vc-setup-buffer "*vc-git-stash*")
1696 (vc-git-command "*vc-git-stash*" 'async nil "stash" "show" "-p" name) 1696 (vc-git-command "*vc-git-stash*" 'async nil "stash" "show" "-p" name)
1697 (set-buffer "*vc-git-stash*") 1697 (set-buffer "*vc-git-stash*")
1698 (diff-mode)
1699 (setq buffer-read-only t) 1698 (setq buffer-read-only t)
1699 (diff-mode)
1700 (pop-to-buffer (current-buffer))) 1700 (pop-to-buffer (current-buffer)))
1701 1701
1702(defun vc-git-stash-apply (name) 1702(defun vc-git-stash-apply (name)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 6041c79efca..6f5c2f0934c 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1808,16 +1808,16 @@ Return t if the buffer had changes, nil otherwise."
1808 (setq files (nreverse filtered)))) 1808 (setq files (nreverse filtered))))
1809 (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async) 1809 (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async)
1810 (set-buffer buffer) 1810 (set-buffer buffer)
1811 ;; Make the *vc-diff* buffer read only, the diff-mode key
1812 ;; bindings are nicer for read only buffers. pcl-cvs does the
1813 ;; same thing.
1814 (setq buffer-read-only t)
1811 (diff-mode) 1815 (diff-mode)
1812 (setq-local diff-vc-backend (car vc-fileset)) 1816 (setq-local diff-vc-backend (car vc-fileset))
1813 (setq-local diff-vc-revisions (list rev1 rev2)) 1817 (setq-local diff-vc-revisions (list rev1 rev2))
1814 (setq-local revert-buffer-function 1818 (setq-local revert-buffer-function
1815 (lambda (_ignore-auto _noconfirm) 1819 (lambda (_ignore-auto _noconfirm)
1816 (vc-diff-internal async vc-fileset rev1 rev2 verbose))) 1820 (vc-diff-internal async vc-fileset rev1 rev2 verbose)))
1817 ;; Make the *vc-diff* buffer read only, the diff-mode key
1818 ;; bindings are nicer for read only buffers. pcl-cvs does the
1819 ;; same thing.
1820 (setq buffer-read-only t)
1821 (if (and (zerop (buffer-size)) 1821 (if (and (zerop (buffer-size))
1822 (not (get-buffer-process (current-buffer)))) 1822 (not (get-buffer-process (current-buffer))))
1823 ;; Treat this case specially so as not to pop the buffer. 1823 ;; Treat this case specially so as not to pop the buffer.