changeset 39386:50956864fe56

(diff-default-read-only): New var. (diff-mode): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 22 Sep 2001 19:11:09 +0000
parents e651eb480e16
children 1e2b82b32e8d
files lisp/diff-mode.el
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/diff-mode.el	Sat Sep 22 17:50:10 2001 +0000
+++ b/lisp/diff-mode.el	Sat Sep 22 19:11:09 2001 +0000
@@ -69,6 +69,11 @@
   :group 'tools
   :group 'diff)
 
+(defcustom diff-default-read-only t
+  "If non-nil, `diff-mode' buffers default to being read-only."
+  :type 'boolean
+  :group 'diff-mode)
+
 (defcustom diff-jump-to-old-file nil
   "*Non-nil means `diff-goto-source' jumps to the old file.
 Else, it jumps to the new file."
@@ -862,10 +867,9 @@
 ;;;###autoload
 (define-derived-mode diff-mode fundamental-mode "Diff"
   "Major mode for viewing/editing context diffs.
-Supports unified and context diffs as well as (to a lesser extent) normal diffs.
-When the buffer is read-only, the ESC prefix is not necessary.
-This mode runs `diff-mode-hook'.
-\\{diff-mode-map}"
+Supports unified and context diffs as well as (to a lesser extent)
+normal diffs.
+When the buffer is read-only, the ESC prefix is not necessary."
   (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
   (set (make-local-variable 'outline-regexp) diff-outline-regexp)
   (set (make-local-variable 'imenu-generic-expression)
@@ -892,9 +896,9 @@
   ;; 	 (substring buffer-file-name 0 (match-beginning 0))))
   ;; (compilation-shell-minor-mode 1)
 
+  (when (and (> (point-max) (point-min)) diff-default-read-only)
+    (toggle-read-only t))
   ;; setup change hooks
-  (unless (and (bobp) (eobp))
-    (toggle-read-only t))
   (if (not diff-update-on-the-fly)
       (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
     (make-local-variable 'diff-unhandled-changes)