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 20:27:12 +0100 Message-ID: <43E8F490.5040708@gmx.at> References: <87y80ndw6f.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090207020305090702010800" X-Trace: sea.gmane.org 1139342538 6879 80.91.229.2 (7 Feb 2006 20:02:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 7 Feb 2006 20:02:18 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 07 21:02:09 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 1F6Z1W-0000JU-Ki for ged-emacs-devel@m.gmane.org; Tue, 07 Feb 2006 21:01:15 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F6Z1W-00025g-19 for ged-emacs-devel@m.gmane.org; Tue, 07 Feb 2006 15:01:14 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F6YUc-0002tJ-HL for emacs-devel@gnu.org; Tue, 07 Feb 2006 14:27:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F6YUb-0002qZ-9T for emacs-devel@gnu.org; Tue, 07 Feb 2006 14:27:13 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F6YUa-0002pK-Q5 for emacs-devel@gnu.org; Tue, 07 Feb 2006 14:27:13 -0500 Original-Received: from [213.165.64.21] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1F6YXj-00088f-60 for emacs-devel@gnu.org; Tue, 07 Feb 2006 14:30:27 -0500 Original-Received: (qmail invoked by alias); 07 Feb 2006 19:27:10 -0000 Original-Received: from M3082P018.adsl.highway.telekom.at (EHLO [88.117.33.50]) [88.117.33.50] by mail.gmx.net (mp039) with SMTP; 07 Feb 2006 20:27:10 +0100 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: Stefan Monnier In-Reply-To: <87y80ndw6f.fsf-monnier+emacs@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:50167 Archived-At: This is a multi-part message in MIME format. --------------090207020305090702010800 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit > - 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? --------------090207020305090702010800 Content-Type: text/plain; name="files-patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="files-patch" *** 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 --------------090207020305090702010800 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 --------------090207020305090702010800--