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: Re: reverting buffer from non-existent file Date: Tue, 07 Feb 2006 10:44:11 +0100 Message-ID: <43E86BEB.5090105@gmx.at> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060006030204050108050203" X-Trace: sea.gmane.org 1139307345 31781 80.91.229.2 (7 Feb 2006 10:15:45 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 7 Feb 2006 10:15:45 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 07 11:15:39 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 1F6Psg-000471-UQ for ged-emacs-devel@m.gmane.org; Tue, 07 Feb 2006 11:15:31 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F6Pw2-0007WY-HF for ged-emacs-devel@m.gmane.org; Tue, 07 Feb 2006 05:18:58 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F6PTQ-0005pz-H7 for emacs-devel@gnu.org; Tue, 07 Feb 2006 04:49:24 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F6PTO-0005pN-G6 for emacs-devel@gnu.org; Tue, 07 Feb 2006 04:49:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F6PTN-0005p2-Ev for emacs-devel@gnu.org; Tue, 07 Feb 2006 04:49:21 -0500 Original-Received: from [213.165.64.21] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1F6PT4-00053G-EZ for emacs-devel@gnu.org; Tue, 07 Feb 2006 04:49:02 -0500 Original-Received: (qmail invoked by alias); 07 Feb 2006 09:45:50 -0000 Original-Received: from N791P010.adsl.highway.telekom.at (EHLO [62.47.42.202]) [62.47.42.202] by mail.gmx.net (mp020) with SMTP; 07 Feb 2006 10:45:50 +0100 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: rms@gnu.org In-Reply-To: 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:50141 Archived-At: This is a multi-part message in MIME format. --------------060006030204050108050203 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit > I think it is cleaner to bind > buffer-read-only and buffer-undo-list only once. On the one hand I don't want to compromise the original behavior for `revert-buffer-insert-file-contents-function' non-nil. On the other I don't want to bind `buffer-undo-list' when generating the "File no longer exists ..." errors. With `debug-on-error' non-nil, switching to *Backtrace* would leave me without undo information again. Hence the - admittedly ugly - two bindings. I added a comment to explain this. --------------060006030204050108050203 Content-Type: text/plain; name="files-patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="files-patch" * files.el (revert-buffer): Do not discard undo list when buffer cannot be reverted because file does not exist. *** files.el Wed Feb 1 10:17:44 2006 --- files.el Tue Feb 7 10:32:00 2006 *************** *** 3815,3821 **** buffer-auto-save-file-name (file-readable-p buffer-auto-save-file-name) (y-or-n-p ! "Buffer has been auto-saved recently. Revert from auto-save file? "))) (file-name (if auto-save-p buffer-auto-save-file-name buffer-file-name))) --- 3815,3821 ---- buffer-auto-save-file-name (file-readable-p buffer-auto-save-file-name) (y-or-n-p ! "Buffer has been auto-saved recently. Revert from auto-save file? "))) (file-name (if auto-save-p buffer-auto-save-file-name buffer-file-name))) *************** *** 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,3876 ---- (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))) ! ;; Don't bind buffer-undo-list around the error reporting ! ;; clauses to avoid that undo information gets lost when ! ;; calling the debugger. ! ((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 --- 3878,3884 ---- (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 --- 3894,3900 ---- (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 --------------060006030204050108050203 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --------------060006030204050108050203--