* epa-file.el (epa-file-find-file-hook): New function.
authorueno <ueno>
Wed, 4 Apr 2007 08:41:03 +0000 (08:41 +0000)
committerueno <ueno>
Wed, 4 Apr 2007 08:41:03 +0000 (08:41 +0000)
(epa-file-enable): Add epa-file-find-file-hook to find-file-hooks.
(epa-file-disable): Remove epa-file-find-file-hook from
find-file-hooks.

ChangeLog
epa-file.el

index 70622f0..6075199 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-04  Daiki Ueno  <ueno@unixuser.org>
+
+       * epa-file.el (epa-file-find-file-hook): New function.
+       (epa-file-enable): Add epa-file-find-file-hook to find-file-hooks.
+       (epa-file-disable): Remove epa-file-find-file-hook from
+       find-file-hooks.
+
 2007-03-29  Daiki Ueno  <ueno@unixuser.org>
 
        * EasyPG: Version 0.0.11 released.
index 599e59b..18e28be 100644 (file)
@@ -125,8 +125,6 @@ May either be a string or a list of strings.")
   (barf-if-buffer-read-only)
   (if (and visit (or beg end))
       (error "Attempt to visit less than an entire file"))
-  (if epa-file-inhibit-auto-save
-      (auto-save-mode 0))
   (setq file (expand-file-name file))
   (let ((local-copy (epa-file-run-real-handler #'file-local-copy (list file)))
        (context (epg-make-context))
@@ -228,6 +226,12 @@ If no one is selected, symmetric encryption will be performed.  "
        (message "Wrote %s" buffer-file-name))))
 (put 'write-region 'epa-file 'epa-file-write-region)
 
+(defun epa-file-find-file-hook ()
+  (if (and buffer-file-name
+          (string-match epa-file-name-regexp buffer-file-name)
+          epa-file-inhibit-auto-save)
+      (auto-save-mode 0)))
+
 ;;;###autoload
 (defun epa-file-enable ()
   (interactive)
@@ -235,6 +239,7 @@ If no one is selected, symmetric encryption will be performed.  "
       (message "`epa-file' already enabled")
     (setq file-name-handler-alist
          (cons epa-file-handler file-name-handler-alist))
+    (add-hook 'find-file-hooks 'epa-file-find-file-hook)
     (message "`epa-file' enabled")))
 
 ;;;###autoload
@@ -244,6 +249,7 @@ If no one is selected, symmetric encryption will be performed.  "
       (progn
        (setq file-name-handler-alist
              (delq epa-file-handler file-name-handler-alist))
+       (remove-hook 'find-file-hooks 'epa-file-find-file-hook)
        (message "`epa-file' disabled"))
     (message "`epa-file' already disabled")))