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: Fri, 10 Feb 2006 09:45:03 +0100 Message-ID: <43EC528F.4060504@gmx.at> References: <87y80ndw6f.fsf-monnier+emacs@gnu.org> <43E8F490.5040708@gmx.at> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080803070606030603040209" X-Trace: sea.gmane.org 1139561426 13590 80.91.229.2 (10 Feb 2006 08:50:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 10 Feb 2006 08:50:26 +0000 (UTC) Cc: emacs-devel@gnu.org, Stefan Monnier , rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Feb 10 09:50:21 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 1F7Tyl-00008R-5X for ged-emacs-devel@m.gmane.org; Fri, 10 Feb 2006 09:50:11 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F7Tyj-0007Hx-AJ for ged-emacs-devel@m.gmane.org; Fri, 10 Feb 2006 03:50:10 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F7TyK-0007Hk-Hl for emacs-devel@gnu.org; Fri, 10 Feb 2006 03:49:44 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F7TyJ-0007HY-76 for emacs-devel@gnu.org; Fri, 10 Feb 2006 03:49:43 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F7TyI-0007HS-UX for emacs-devel@gnu.org; Fri, 10 Feb 2006 03:49:43 -0500 Original-Received: from [213.165.64.21] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.52) id 1F7U21-0008WJ-TD for emacs-devel@gnu.org; Fri, 10 Feb 2006 03:53:34 -0500 Original-Received: (qmail invoked by alias); 10 Feb 2006 08:49:40 -0000 Original-Received: from N885P008.adsl.highway.telekom.at (EHLO [62.47.54.136]) [62.47.54.136] by mail.gmx.net (mp024) with SMTP; 10 Feb 2006 09:49:40 +0100 X-Authenticated: #14592706 User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en Original-To: martin rudalics In-Reply-To: <43E8F490.5040708@gmx.at> 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:50313 Archived-At: This is a multi-part message in MIME format. --------------080803070606030603040209 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit > ... 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. --------------080803070606030603040209 Content-Type: text/plain; name="files-patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="files-patch" * 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. --------------080803070606030603040209 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 --------------080803070606030603040209--