diff options
| author | Juri Linkov | 2022-01-10 20:29:53 +0200 |
|---|---|---|
| committer | Juri Linkov | 2022-01-10 20:29:53 +0200 |
| commit | 97806bc7deeec7ab1458eb5ff689f46ec8e7c652 (patch) | |
| tree | e454d7c0aad622aa9639bb4b4d46f6ce067f05e7 /lisp/vc/diff-mode.el | |
| parent | 2b7a486605c01f7927de47ec2788f1eb2a4c0142 (diff) | |
| download | emacs-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.
Diffstat (limited to 'lisp/vc/diff-mode.el')
| -rw-r--r-- | lisp/vc/diff-mode.el | 30 |
1 files changed, 19 insertions, 11 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 |