|
@@ -116,6 +116,35 @@ nil : Leave auto-save-mode enabled.
|
|
(const :tag "Ask" ask)
|
|
(const :tag "Ask" ask)
|
|
(const :tag "Encrypt" encrypt)))
|
|
(const :tag "Encrypt" encrypt)))
|
|
|
|
|
|
|
|
+(defun org-crypt-check-auto-save ()
|
|
|
|
+ "Check whether auto-save-mode is enabled for the current buffer.
|
|
|
|
+
|
|
|
|
+`auto-save-mode' may cause leakage when decrypting entries, so
|
|
|
|
+check whether it's enabled, and decide what to do about it.
|
|
|
|
+
|
|
|
|
+See `org-crypt-disable-auto-save'."
|
|
|
|
+ (when buffer-auto-save-file-name
|
|
|
|
+ (cond
|
|
|
|
+ ((or
|
|
|
|
+ (eq org-crypt-disable-auto-save t)
|
|
|
|
+ (and
|
|
|
|
+ (eq org-crypt-disable-auto-save 'ask)
|
|
|
|
+ (y-or-n-p "org-decrypt: auto-save-mode may cause leakage. Disable it for current buffer? ")))
|
|
|
|
+ (message (concat "org-decrypt: Disabling auto-save-mode for " (or (buffer-file-name) (current-buffer))))
|
|
|
|
+ ; The argument to auto-save-mode has to be "-1", since
|
|
|
|
+ ; giving a "nil" argument toggles instead of disabling.
|
|
|
|
+ (auto-save-mode -1))
|
|
|
|
+ ((eq org-crypt-disable-auto-save nil)
|
|
|
|
+ (message "org-decrypt: Decrypting entry with auto-save-mode enabled. This may cause leakage."))
|
|
|
|
+ ((eq org-crypt-disable-auto-save 'encrypt)
|
|
|
|
+ (message "org-decrypt: Enabling re-encryption on auto-save.")
|
|
|
|
+ (add-hook 'auto-save-hook
|
|
|
|
+ (lambda ()
|
|
|
|
+ (message "org-crypt: Re-encrypting all decrypted entries due to auto-save.")
|
|
|
|
+ (org-encrypt-entries))
|
|
|
|
+ nil t))
|
|
|
|
+ (t nil))))
|
|
|
|
+
|
|
(defun org-crypt-key-for-heading ()
|
|
(defun org-crypt-key-for-heading ()
|
|
"Return the encryption key for the current heading."
|
|
"Return the encryption key for the current heading."
|
|
(save-excursion
|
|
(save-excursion
|
|
@@ -164,30 +193,6 @@ nil : Leave auto-save-mode enabled.
|
|
(defun org-decrypt-entry ()
|
|
(defun org-decrypt-entry ()
|
|
"Decrypt the content of the current headline."
|
|
"Decrypt the content of the current headline."
|
|
(interactive)
|
|
(interactive)
|
|
-
|
|
|
|
- ; auto-save-mode may cause leakage, so check whether it's enabled.
|
|
|
|
- (when buffer-auto-save-file-name
|
|
|
|
- (cond
|
|
|
|
- ((or
|
|
|
|
- (eq org-crypt-disable-auto-save t)
|
|
|
|
- (and
|
|
|
|
- (eq org-crypt-disable-auto-save 'ask)
|
|
|
|
- (y-or-n-p "org-decrypt: auto-save-mode may cause leakage. Disable it for current buffer? ")))
|
|
|
|
- (message (concat "org-decrypt: Disabling auto-save-mode for " (or (buffer-file-name) (current-buffer))))
|
|
|
|
- ; The argument to auto-save-mode has to be "-1", since
|
|
|
|
- ; giving a "nil" argument toggles instead of disabling.
|
|
|
|
- (auto-save-mode -1))
|
|
|
|
- ((eq org-crypt-disable-auto-save nil)
|
|
|
|
- (message "org-decrypt: Decrypting entry with auto-save-mode enabled. This may cause leakage."))
|
|
|
|
- ((eq org-crypt-disable-auto-save 'encrypt)
|
|
|
|
- (message "org-decrypt: Enabling re-encryption on auto-save.")
|
|
|
|
- (add-hook 'auto-save-hook
|
|
|
|
- (lambda ()
|
|
|
|
- (message "org-crypt: Re-encrypting all decrypted entries due to auto-save.")
|
|
|
|
- (org-encrypt-entries))
|
|
|
|
- nil t))
|
|
|
|
- (t nil)))
|
|
|
|
-
|
|
|
|
(require 'epg)
|
|
(require 'epg)
|
|
(unless (org-before-first-heading-p)
|
|
(unless (org-before-first-heading-p)
|
|
(save-excursion
|
|
(save-excursion
|
|
@@ -199,6 +204,7 @@ nil : Leave auto-save-mode enabled.
|
|
(outline-invisible-p))))
|
|
(outline-invisible-p))))
|
|
(forward-line)
|
|
(forward-line)
|
|
(when (looking-at "-----BEGIN PGP MESSAGE-----")
|
|
(when (looking-at "-----BEGIN PGP MESSAGE-----")
|
|
|
|
+ (org-crypt-check-auto-save)
|
|
(let* ((end (save-excursion
|
|
(let* ((end (save-excursion
|
|
(search-forward "-----END PGP MESSAGE-----")
|
|
(search-forward "-----END PGP MESSAGE-----")
|
|
(forward-line)
|
|
(forward-line)
|