changeset 76769:3693d2ee35b8

(vc-with-current-file-buffer): New macro. (vc-arch-file-source-p): Use it to avoid infloop.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 28 Mar 2007 01:19:43 +0000
parents 36178b78d004
children e359709ed895
files lisp/ChangeLog lisp/vc-arch.el
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Mar 28 00:54:08 2007 +0000
+++ b/lisp/ChangeLog	Wed Mar 28 01:19:43 2007 +0000
@@ -1,3 +1,8 @@
+2007-03-28  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* vc-arch.el (vc-with-current-file-buffer): New macro.
+	(vc-arch-file-source-p): Use it to avoid infloop.
+
 2007-03-28  David Hansen  <david.hansen@gmx.net>  (tiny change)
 
 	* emacs-lisp/lisp.el (lisp-complete-symbol):
--- a/lisp/vc-arch.el	Wed Mar 28 00:54:08 2007 +0000
+++ b/lisp/vc-arch.el	Wed Mar 28 01:19:43 2007 +0000
@@ -109,6 +109,19 @@
 
 (defconst vc-arch-tagline-re "^\\W*arch-tag:[ \t]*\\(.*[^ \t\n]\\)")
 
+(defmacro vc-with-current-file-buffer (file &rest body)
+  (declare (indent 2) (debug t))
+  `(let ((-kill-buf- nil)
+         (-file- ,file))
+     (with-current-buffer (or (find-buffer-visiting -file-)
+                              (setq -kill-buf- (generate-new-buffer " temp")))
+       ;; Avoid find-file-literally since it can do many undesirable extra
+       ;; things (among which, call us back into an infinite loop).
+       (if -kill-buf- (insert-file-contents -file-))
+       (unwind-protect
+           (progn ,@body)
+         (if (buffer-live-p -kill-buf-) (kill-buffer -kill-buf-))))))
+
 (defun vc-arch-file-source-p (file)
   "Can return nil, `maybe' or a non-nil value.
 Only the value `maybe' can be trusted :-(."
@@ -122,7 +135,7 @@
 	  (concat ".arch-ids/" (file-name-nondirectory file) ".id")
 	  (file-name-directory file)))
 	;; Check the presence of a tagline.
-	(with-current-buffer (find-file-noselect file)
+	(vc-with-current-file-buffer file
 	  (save-excursion
 	    (goto-char (point-max))
 	    (or (re-search-backward vc-arch-tagline-re (- (point) 1000) t)