[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: reverting buffer from non-existent file
From: |
martin rudalics |
Subject: |
Re: reverting buffer from non-existent file |
Date: |
Tue, 07 Feb 2006 20:27:12 +0100 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
> - it's probably better to bind inhibit-read-only than buffer-read-only.
> - IIRC buffer-undo-list doesn't need to be bound here since
> insert-file-contents does it for us anyway.
In the attached patch I followed your suggestions and also simplified
the `revert-without-query' mechanism slightly. By the way, shouldn't
(set (make-local-variable 'revert-buffer-internal-hook)
local-hook)
be handled by add-hook?
*** files.el Wed Feb 1 10:17:44 2006
--- files.el Tue Feb 7 20:23:42 2006
***************
*** 3791,3803 ****
confirmation.)
Optional third argument PRESERVE-MODES non-nil means don't alter
! the files modes. Normally we reinitialize them using `normal-mode'.
If the value of `revert-buffer-function' is non-nil, it is called to
do all the work for this command. Otherwise, the hooks
`before-revert-hook' and `after-revert-hook' are run at the beginning
and the end, and if `revert-buffer-insert-file-contents-function' is
! non-nil, it is called instead of rereading visited file contents."
;; I admit it's odd to reverse the sense of the prefix argument, but
;; there is a lot of code out there which assumes that the first
--- 3791,3803 ----
confirmation.)
Optional third argument PRESERVE-MODES non-nil means don't alter
! the file's modes. Normally we reinitialize them using `normal-mode'.
If the value of `revert-buffer-function' is non-nil, it is called to
do all the work for this command. Otherwise, the hooks
`before-revert-hook' and `after-revert-hook' are run at the beginning
and the end, and if `revert-buffer-insert-file-contents-function' is
! non-nil, it is called instead of rereading the visited file's contents."
;; I admit it's odd to reverse the sense of the prefix argument, but
;; there is a lot of code out there which assumes that the first
***************
*** 3823,3835 ****
(error "Buffer does not seem to be associated with any file"))
((or noconfirm
(and (not (buffer-modified-p))
! (let ((tail revert-without-query)
! (found nil))
! (while tail
! (if (string-match (car tail) file-name)
! (setq found t))
! (setq tail (cdr tail)))
! found))
(yes-or-no-p (format "Revert buffer from file %s? "
file-name)))
(run-hooks 'before-revert-hook)
--- 3823,3832 ----
(error "Buffer does not seem to be associated with any file"))
((or noconfirm
(and (not (buffer-modified-p))
! (catch 'found
! (dolist (regexp revert-without-query)
! (when (string-match regexp file-name)
! (throw 'found t)))))
(yes-or-no-p (format "Revert buffer from file %s? "
file-name)))
(run-hooks 'before-revert-hook)
***************
*** 3838,3887 ****
(and (not auto-save-p)
(not (verify-visited-file-modtime (current-buffer)))
(setq buffer-backed-up nil))
- ;; Get rid of all undo records for this buffer.
- (or (eq buffer-undo-list t)
- (setq buffer-undo-list nil))
;; Effectively copy the after-revert-hook status,
;; since after-find-file will clobber it.
(let ((global-hook (default-value 'after-revert-hook))
(local-hook-p (local-variable-p 'after-revert-hook))
(local-hook (and (local-variable-p 'after-revert-hook)
! after-revert-hook)))
! (let (buffer-read-only
! ;; Don't make undo records for the reversion.
! (buffer-undo-list t))
! (if revert-buffer-insert-file-contents-function
! (funcall revert-buffer-insert-file-contents-function
! file-name auto-save-p)
! (if (not (file-exists-p file-name))
! (error (if buffer-file-number
! "File %s no longer exists!"
! "Cannot revert nonexistent file %s")
! file-name))
! ;; Bind buffer-file-name to nil
! ;; so that we don't try to lock the file.
! (let ((buffer-file-name nil))
! (or auto-save-p
! (unlock-buffer)))
! (widen)
! (let ((coding-system-for-read
! ;; Auto-saved file shoule be read by Emacs'
! ;; internal coding.
! (if auto-save-p 'auto-save-coding
! (or coding-system-for-read
! buffer-file-coding-system-explicit))))
! ;; This force after-insert-file-set-coding
! ;; (called from insert-file-contents) to set
! ;; buffer-file-coding-system to a proper value.
! (kill-local-variable 'buffer-file-coding-system)
!
! ;; Note that this preserves point in an intelligent way.
! (if preserve-modes
! (let ((buffer-file-format buffer-file-format))
! (insert-file-contents file-name (not auto-save-p)
! nil nil t))
! (insert-file-contents file-name (not auto-save-p)
! nil nil t)))))
;; Recompute the truename in case changes in symlinks
;; have changed the truename.
(setq buffer-file-truename
--- 3835,3886 ----
(and (not auto-save-p)
(not (verify-visited-file-modtime (current-buffer)))
(setq buffer-backed-up nil))
;; Effectively copy the after-revert-hook status,
;; since after-find-file will clobber it.
(let ((global-hook (default-value 'after-revert-hook))
(local-hook-p (local-variable-p 'after-revert-hook))
(local-hook (and (local-variable-p 'after-revert-hook)
! after-revert-hook))
! (inhibit-read-only t))
! (cond
! (revert-buffer-insert-file-contents-function
! (unless (eq buffer-undo-list t)
! ;; Get rid of all undo records for this buffer.
! (setq buffer-undo-list nil))
! ;; Don't make undo records for the reversion.
! (let ((buffer-undo-list t))
! (funcall revert-buffer-insert-file-contents-function
! file-name auto-save-p)))
! ((not (file-exists-p file-name))
! (error (if buffer-file-number
! "File %s no longer exists!"
! "Cannot revert nonexistent file %s")
! file-name))
! (t
! ;; Bind buffer-file-name to nil
! ;; so that we don't try to lock the file.
! (let ((buffer-file-name nil))
! (or auto-save-p
! (unlock-buffer)))
! (widen)
! (let ((coding-system-for-read
! ;; Auto-saved file should be read by Emacs'
! ;; internal coding.
! (if auto-save-p 'auto-save-coding
! (or coding-system-for-read
! buffer-file-coding-system-explicit))))
! ;; This force after-insert-file-set-coding
! ;; (called from insert-file-contents) to set
! ;; buffer-file-coding-system to a proper value.
! (kill-local-variable 'buffer-file-coding-system)
!
! ;; Note that this preserves point in an intelligent way.
! (if preserve-modes
! (let ((buffer-file-format buffer-file-format))
! (insert-file-contents file-name (not auto-save-p)
! nil nil t))
! (insert-file-contents file-name (not auto-save-p)
! nil nil t)))))
;; Recompute the truename in case changes in symlinks
;; have changed the truename.
(setq buffer-file-truename