diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index ca8df5d380..63b9549b54 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -1479,6 +1479,12 @@ diff--font-lock-cleanup (defvar whitespace-style) (defvar whitespace-trailing-regexp) +(defvar-local diff-mode-read-only nil) + +(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 +1522,19 @@ diff-mode (diff-setup-whitespace) + (add-hook 'read-only-mode-hook + (lambda () + (setq diff-mode-read-only buffer-read-only)) + nil t) + (if diff-default-read-only - (setq buffer-read-only t)) + (let ((view-read-only nil)) (read-only-mode 1))) ;; 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 diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el index 4abcf6c15a..425155be40 100644 --- a/lisp/vc/diff.el +++ b/lisp/vc/diff.el @@ -182,7 +182,7 @@ diff-no-select " ")) (thisdir default-directory)) (with-current-buffer buf - (setq buffer-read-only t) + (let ((view-read-only nil)) (read-only-mode 1)) (buffer-disable-undo (current-buffer)) (let ((inhibit-read-only t)) (erase-buffer)) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 6041c79efc..600c4561ac 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1817,7 +1826,7 @@ vc-diff-internal ;; 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) + (let ((view-read-only nil)) (read-only-mode 1)) (if (and (zerop (buffer-size)) (not (get-buffer-process (current-buffer)))) ;; Treat this case specially so as not to pop the buffer.