changeset 110318:3386110d149b

epa-file: suppress file-locking question on M-x revert-buffer * epa-file.el (epa-file-insert-file-contents): If visiting, bind buffer-file-name to avoid file-locking. (Bug#7026)
author Daiki Ueno <ueno@unixuser.org>
date Mon, 13 Sep 2010 19:44:07 +0900
parents 50478146a2e1
children f52a8c72912b
files lisp/ChangeLog lisp/epa-file.el
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Sep 13 10:14:52 2010 +0000
+++ b/lisp/ChangeLog	Mon Sep 13 19:44:07 2010 +0900
@@ -1,3 +1,8 @@
+2010-09-13  Daiki Ueno  <ueno@unixuser.org>
+
+	* epa-file.el (epa-file-insert-file-contents): If visiting, bind
+	buffer-file-name to avoid file-locking.  (Bug#7026)
+
 2010-09-13  Julien Danjou  <julien@danjou.info>
 
 	* notifications.el (notifications-notify): Add support for
--- a/lisp/epa-file.el	Mon Sep 13 10:14:52 2010 +0000
+++ b/lisp/epa-file.el	Mon Sep 13 19:44:07 2010 +0900
@@ -158,12 +158,17 @@
 	  (if (or beg end)
 	      (setq string (substring string (or beg 0) end)))
 	  (save-excursion
-	    (save-restriction
-	      (narrow-to-region (point) (point))
-	      (epa-file-decode-and-insert string file visit beg end replace)
-	      (setq length (- (point-max) (point-min))))
-	    (if replace
-		(delete-region (point) (point-max)))
+	    ;; If visiting, bind off buffer-file-name so that
+	    ;; file-locking will not ask whether we should
+	    ;; really edit the buffer.
+	    (let ((buffer-file-name
+		   (if visit nil buffer-file-name)))
+	      (save-restriction
+		(narrow-to-region (point) (point))
+		(epa-file-decode-and-insert string file visit beg end replace)
+		(setq length (- (point-max) (point-min))))
+	      (if replace
+		  (delete-region (point) (point-max))))
 	    (if visit
 		(set-visited-file-modtime))))
       (if (and local-copy