Commit e554eeb7 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(find-file-noselect): Offer to change buffer-read-only

only when the file's read-only status has changed from before
as well as disagreeing with the buffer's current status.
(buffer-file-read-only): New var, local in all buffers.
parent 6a0d92d3
...@@ -197,6 +197,10 @@ If the buffer is visiting a new file, the value is nil.") ...@@ -197,6 +197,10 @@ If the buffer is visiting a new file, the value is nil.")
(defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt)))
"Non-nil means that buffer-file-number uniquely identifies files.") "Non-nil means that buffer-file-number uniquely identifies files.")
(defvar buffer-file-read-only nil
"Non-nil if visited file was read-only when visited.")
(make-variable-buffer-local 'buffer-file-read-only)
(defvar file-name-invalid-regexp (defvar file-name-invalid-regexp
(cond ((and (eq system-type 'ms-dos) (not (msdos-long-file-names))) (cond ((and (eq system-type 'ms-dos) (not (msdos-long-file-names)))
(concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive (concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive
...@@ -1071,16 +1075,19 @@ that are visiting the various files." ...@@ -1071,16 +1075,19 @@ that are visiting the various files."
(with-current-buffer buf (with-current-buffer buf
;; Check if a formerly read-only file has become ;; Check if a formerly read-only file has become
;; writable and vice versa. ;; writable and vice versa, but if the buffer agrees
;; with the new state of the file, that is ok too.
(let ((read-only (not (file-writable-p buffer-file-name)))) (let ((read-only (not (file-writable-p buffer-file-name))))
(unless (eq read-only buffer-read-only) (unless (or (eq read-only buffer-file-read-only)
(eq read-only buffer-read-only))
(when (or nowarn (when (or nowarn
(let ((question (let ((question
(format "File %s is %s on disk. Change buffer mode? " (format "File %s is %s on disk. Change buffer mode? "
buffer-file-name buffer-file-name
(if read-only "read-only" "writable")))) (if read-only "read-only" "writable"))))
(y-or-n-p question))) (y-or-n-p question)))
(setq buffer-read-only read-only)))) (setq buffer-read-only read-only)))
(setq buffer-file-read-only read-only))
(when (not (eq (not (null rawfile)) (when (not (eq (not (null rawfile))
(not (null find-file-literally)))) (not (null find-file-literally))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment