From: martin rudalics <rudalics@gmx.at>
Cc: emacs-devel@gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
rms@gnu.org
Subject: Re: reverting buffer from non-existent file
Date: Fri, 10 Feb 2006 09:45:03 +0100 [thread overview]
Message-ID: <43EC528F.4060504@gmx.at> (raw)
In-Reply-To: <43E8F490.5040708@gmx.at>
[-- Attachment #1: Type: text/plain, Size: 272 bytes --]
> ... shouldn't
>
> (set (make-local-variable 'revert-buffer-internal-hook)
> local-hook)
>
> be handled by add-hook?
My mind was wandering, please disregard that. I now also modified
recover-file to use inhibit-read-only and fixed some doc-strings.
[-- Attachment #2: files-patch --]
[-- Type: text/plain, Size: 9256 bytes --]
* files.el (revert-buffer, recover-file): Replace
buffer-read-only by inhibit-read-only.
Suggested by Stefan Monnier.
(revert-buffer): Let insert-file-contents discard
buffer-undo-list. Simplify code.
(find-file, find-file-existing, revert-buffer): Doc-string fixes.
*** files.el Wed Feb 1 10:17:44 2006
--- files.el Fri Feb 10 08:22:16 2006
***************
*** 1024,1030 ****
Interactively, or if WILDCARDS is non-nil in a call from Lisp,
expand wildcards (if any) and visit multiple files. You can
! suppress wildcard expansion by setting `find-file-wildcards'.
To visit a file without any kind of conversion and without
automatically choosing a major mode, use \\[find-file-literally]."
--- 1024,1030 ----
Interactively, or if WILDCARDS is non-nil in a call from Lisp,
expand wildcards (if any) and visit multiple files. You can
! suppress wildcard expansion by setting `find-file-wildcards' to nil.
To visit a file without any kind of conversion and without
automatically choosing a major mode, use \\[find-file-literally]."
***************
*** 1076,1082 ****
(defun find-file-existing (filename &optional wildcards)
"Edit the existing file FILENAME.
! Like \\[find-file] but only allow files that exists."
(interactive (find-file-read-args "Find existing file: " t))
(unless (file-exists-p filename) (error "%s does not exist" filename))
(find-file filename wildcards)
--- 1076,1082 ----
(defun find-file-existing (filename &optional wildcards)
"Edit the existing file FILENAME.
! Like \\[find-file] but only allow a file that exists."
(interactive (find-file-read-args "Find existing file: " t))
(unless (file-exists-p filename) (error "%s does not exist" filename))
(find-file filename wildcards)
***************
*** 3787,3794 ****
to nil.
Optional second argument NOCONFIRM means don't ask for confirmation at
! all. (The local variable `revert-without-query', if non-nil, prevents
! confirmation.)
Optional third argument PRESERVE-MODES non-nil means don't alter
the files modes. Normally we reinitialize them using `normal-mode'.
--- 3787,3794 ----
to nil.
Optional second argument NOCONFIRM means don't ask for confirmation at
! all. \(The variable `revert-without-query' offers another way to
! revert buffers without querying for confirmation.)
Optional third argument PRESERVE-MODES non-nil means don't alter
the files modes. Normally we reinitialize them using `normal-mode'.
***************
*** 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,3885 ----
(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 (when (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
***************
*** 3889,3895 ****
(after-find-file nil nil t t preserve-modes)
;; Run after-revert-hook as it was before we reverted.
(setq-default revert-buffer-internal-hook global-hook)
! (if local-hook-p
(set (make-local-variable 'revert-buffer-internal-hook)
local-hook)
(kill-local-variable 'revert-buffer-internal-hook))
--- 3887,3893 ----
(after-find-file nil nil t t preserve-modes)
;; Run after-revert-hook as it was before we reverted.
(setq-default revert-buffer-internal-hook global-hook)
! (if local-hook
(set (make-local-variable 'revert-buffer-internal-hook)
local-hook)
(kill-local-variable 'revert-buffer-internal-hook))
***************
*** 3935,3941 ****
(insert-directory-safely file-name switches))))
(yes-or-no-p (format "Recover auto save file %s? " file-name)))
(switch-to-buffer (find-file-noselect file t))
! (let ((buffer-read-only nil)
;; Keep the current buffer-file-coding-system.
(coding-system buffer-file-coding-system)
;; Auto-saved file shoule be read with special coding.
--- 3933,3939 ----
(insert-directory-safely file-name switches))))
(yes-or-no-p (format "Recover auto save file %s? " file-name)))
(switch-to-buffer (find-file-noselect file t))
! (let ((inhibit-read-only t)
;; Keep the current buffer-file-coding-system.
(coding-system buffer-file-coding-system)
;; Auto-saved file shoule be read with special coding.
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
prev parent reply other threads:[~2006-02-10 8:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-06 7:00 reverting buffer from non-existent file Martin Rudalics
2006-02-07 6:06 ` Richard M. Stallman
2006-02-07 9:44 ` martin rudalics
2006-02-07 15:31 ` Stefan Monnier
2006-02-07 19:27 ` martin rudalics
2006-02-10 8:45 ` martin rudalics [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43EC528F.4060504@gmx.at \
--to=rudalics@gmx.at \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=rms@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).