summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2012-09-25 16:32:52 +0200
committerBastien Guerry <bzg@altern.org>2012-09-25 17:29:44 +0200
commitac6409feaecd4f2faa5b96ff7aeb42c156b8cbdc (patch)
treefdb3b64cd3ed8e31ce98a5caf080f5f307951da7
parent26b9e71f263a4bb29d8cc353d0afcd4be70287c2 (diff)
downloadorg-mode-ac6409feaecd4f2faa5b96ff7aeb42c156b8cbdc.tar.gz
Allow using an encrypted headline as a capture target.
* org-capture.el (org-capture-finalize): Maybe re-encrypt the target headline if it was decrypted. (org-capture-set-target-location): Maybe decrypt the target headline. * org-crypt.el (org-at-encrypted-entry-p): New function. Thanks to Guilherme Gondim for suggesting this.
-rw-r--r--lisp/org-capture.el18
-rw-r--r--lisp/org-crypt.el7
2 files changed, 22 insertions, 3 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 188c79e..6aa6472 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -698,6 +698,11 @@ captured item after finalizing."
;; Run the hook
(run-hooks 'org-capture-before-finalize-hook))
+ (when (org-capture-get :decrypted)
+ (save-excursion
+ (goto-char (org-capture-get :decrypted))
+ (org-encrypt-entry)))
+
;; Kill the indirect buffer
(save-buffer)
(let ((return-wconf (org-capture-get :return-to-wconf 'local))
@@ -800,8 +805,9 @@ already gone. Any prefix argument will be passed to the refile command."
(org-capture-put :initial-target-position (point)))
(defun org-capture-set-target-location (&optional target)
- "Find target buffer and position and store then in the property list."
- (let ((target-entry-p t))
+ "Find TARGET buffer and position.
+Store them in the capture property list."
+ (let ((target-entry-p t) decrypted-hl-pos)
(setq target (or target (org-capture-get :target)))
(save-excursion
(cond
@@ -922,8 +928,14 @@ already gone. Any prefix argument will be passed to the refile command."
(t (error "Invalid capture target specification")))
+ (when (org-at-encrypted-entry-p)
+ (org-decrypt-entry)
+ (setq decrypted-hl-pos
+ (save-excursion (and (org-back-to-heading t) (point)))))
+
(org-capture-put :buffer (current-buffer) :pos (point)
- :target-entry-p target-entry-p))))
+ :target-entry-p target-entry-p
+ :decrypted decrypted-hl-pos))))
(defun org-capture-expand-file (file)
"Expand functions and symbols for FILE.
diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el
index 257dba3..74a1104 100644
--- a/lisp/org-crypt.el
+++ b/lisp/org-crypt.el
@@ -252,6 +252,13 @@ See `org-crypt-disable-auto-save'."
(cdr (org-make-tags-matcher org-crypt-tag-matcher))
todo-only)))
+(defun org-at-encrypted-entry-p ()
+ "Is the current entry encrypted?"
+ (save-excursion
+ (org-back-to-heading t)
+ (search-forward "-----BEGIN PGP MESSAGE-----"
+ (save-excursion (org-end-of-subtree t)) t)))
+
(defun org-crypt-use-before-save-magic ()
"Add a hook to automatically encrypt entries before a file is saved to disk."
(add-hook