From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Martin Rudalics Newsgroups: gmane.emacs.devel Subject: reverting buffer from non-existent file Date: Mon, 06 Feb 2006 08:00:01 +0100 Message-ID: NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1139209088 22070 80.91.229.2 (6 Feb 2006 06:58:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 6 Feb 2006 06:58:08 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 06 07:58:05 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F60K2-0006qd-A0 for ged-emacs-devel@m.gmane.org; Mon, 06 Feb 2006 07:58:02 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F60NK-0005Qz-6U for ged-emacs-devel@m.gmane.org; Mon, 06 Feb 2006 02:01:26 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F60N7-0005Qi-Vl for emacs-devel@gnu.org; Mon, 06 Feb 2006 02:01:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F60N6-0005QO-3Q for emacs-devel@gnu.org; Mon, 06 Feb 2006 02:01:13 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F60N5-0005QL-Vv for emacs-devel@gnu.org; Mon, 06 Feb 2006 02:01:12 -0500 Original-Received: from [213.165.64.21] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1F60Mb-0001eo-9w for emacs-devel@gnu.org; Mon, 06 Feb 2006 02:00:41 -0500 Original-Received: (qmail invoked by alias); 06 Feb 2006 06:57:44 -0000 Original-Received: from N870P013.adsl.highway.telekom.at (EHLO V357900157) [62.47.52.173] by mail.gmx.net (mp023) with SMTP; 06 Feb 2006 07:57:44 +0100 X-Authenticated: #14592706 Original-To: emacs-devel@gnu.org X-Y-GMX-Trusted: 0 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:50085 Archived-At: 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 ============================================================