1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-24 07:20:37 +00:00

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.
This commit is contained in:
Juri Linkov 2022-01-10 20:29:53 +02:00
parent 2b7a486605
commit 97806bc7de
3 changed files with 24 additions and 16 deletions

View File

@ -1479,6 +1479,14 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
(defvar whitespace-style)
(defvar whitespace-trailing-regexp)
(defvar-local diff-mode-read-only nil
"Non-nil when read-only diff buffer uses short keys.")
;; It should be lower than `outline-minor-mode' and `view-mode'.
(or (assq 'diff-mode-read-only minor-mode-map-alist)
(nconc minor-mode-map-alist
(list (cons 'diff-mode-read-only diff-mode-shared-map))))
;;;###autoload
(define-derived-mode diff-mode fundamental-mode "Diff"
"Major mode for viewing/editing context diffs.
@ -1516,23 +1524,23 @@ a diff with \\[diff-reverse-direction].
(diff-setup-whitespace)
(if diff-default-read-only
(setq buffer-read-only t))
;; read-only setup
(when diff-default-read-only
(setq buffer-read-only t))
(when buffer-read-only
(setq diff-mode-read-only t))
(add-hook 'read-only-mode-hook
(lambda ()
(setq diff-mode-read-only buffer-read-only))
nil t)
;; setup change hooks
(if (not diff-update-on-the-fly)
(add-hook 'write-contents-functions #'diff-write-contents-hooks nil t)
(make-local-variable 'diff-unhandled-changes)
(add-hook 'after-change-functions #'diff-after-change-function nil t)
(add-hook 'post-command-hook #'diff-post-command-hook nil t))
;; Neat trick from Dave Love to add more bindings in read-only mode:
(let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
(add-to-list 'minor-mode-overriding-map-alist ro-bind)
;; Turn off this little trick in case the buffer is put in view-mode.
(add-hook 'view-mode-hook
(lambda ()
(setq minor-mode-overriding-map-alist
(delq ro-bind minor-mode-overriding-map-alist)))
nil t))
;; add-log support
(setq-local add-log-current-defun-function #'diff-current-defun)
(setq-local add-log-buffer-file-name-function

View File

@ -1695,8 +1695,8 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
(vc-setup-buffer "*vc-git-stash*")
(vc-git-command "*vc-git-stash*" 'async nil "stash" "show" "-p" name)
(set-buffer "*vc-git-stash*")
(diff-mode)
(setq buffer-read-only t)
(diff-mode)
(pop-to-buffer (current-buffer)))
(defun vc-git-stash-apply (name)

View File

@ -1808,16 +1808,16 @@ 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)
;; Make the *vc-diff* buffer read only, the diff-mode key
;; bindings are nicer for read only buffers. pcl-cvs does the
;; same thing.
(setq buffer-read-only t)
(diff-mode)
(setq-local diff-vc-backend (car vc-fileset))
(setq-local diff-vc-revisions (list rev1 rev2))
(setq-local revert-buffer-function
(lambda (_ignore-auto _noconfirm)
(vc-diff-internal async vc-fileset rev1 rev2 verbose)))
;; Make the *vc-diff* buffer read only, the diff-mode key
;; bindings are nicer for read only buffers. pcl-cvs does the
;; same thing.
(setq buffer-read-only t)
(if (and (zerop (buffer-size))
(not (get-buffer-process (current-buffer))))
;; Treat this case specially so as not to pop the buffer.