all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Martin Rudalics <rudalics@gmx.at>
Subject: reverting buffer from non-existent file
Date: Mon, 06 Feb 2006 08:00:01 +0100	[thread overview]
Message-ID: <wkirrt0y6m.fsf@gmx.at> (raw)

When reverting a buffer and the file to revert from is not or no more
readable, all undo information gets killed nevertheless.  This is an
unhappy effect because I occasionally forget that I have not yet saved a
buffer I just created, do `revert-buffer', and loose the entire
information needed to undo the latest changes.  The patch below fixes
the problem for me.

============================================================
*** files.el	Wed Feb  1 10:17:44 2006
--- files.el	Fri Feb  3 20:47:02 2006
***************
*** 3840,3845 ****
--- 3840,3848 ----
  		    (setq buffer-backed-up nil))
  	       ;; Get rid of all undo records for this buffer.
  	       (or (eq buffer-undo-list t)
+                    ;; Do not clear buffer-undo-list if reverting will fail.
+                    (and (not (file-readable-p file-name))
+                         (not revert-buffer-insert-file-contents-function))
  		   (setq buffer-undo-list nil))
  	       ;; Effectively copy the after-revert-hook status,
  	       ;; since after-find-file will clobber it.
***************
*** 3847,3863 ****
  		     (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))
--- 3850,3873 ----
  		     (local-hook-p (local-variable-p 'after-revert-hook))
  		     (local-hook (and (local-variable-p 'after-revert-hook)
  				      after-revert-hook)))
!                  (cond
!                   (revert-buffer-insert-file-contents-function
!                    (let (buffer-read-only
!                          ;; Don't make undo records for the reversion.
!                          (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))
!                   ((not (file-readable-p file-name))
!                    (error "File %s is not readable" file-name))
!                   (t
!                    (let (buffer-read-only
!                          ;; Don't make undo records for the reversion.
!                          (buffer-undo-list t))
  		     ;; Bind buffer-file-name to nil
  		     ;; so that we don't try to lock the file.
  		     (let ((buffer-file-name nil))
***************
*** 3865,3871 ****
  			   (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
--- 3875,3881 ----
  			   (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
***************
*** 3881,3887 ****
  			     (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
--- 3891,3897 ----
  			     (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
============================================================

             reply	other threads:[~2006-02-06  7:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-06  7:00 Martin Rudalics [this message]
2006-02-07  6:06 ` reverting buffer from non-existent file 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

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=wkirrt0y6m.fsf@gmx.at \
    --to=rudalics@gmx.at \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.