diff options
author | David Maus <dmaus@ictsoc.de> | 2010-07-16 20:25:45 +0000 |
---|---|---|
committer | Carsten Dominik <carsten.dominik@gmail.com> | 2010-07-18 07:21:47 +0200 |
commit | 4c101529a44f6588ef8dfecb62fba1d9fb1ab335 (patch) | |
tree | 314bb4cb731026eeaa11f30b33b9d5727d510c41 | |
parent | ebf808f9aa9297af2734172bb9cd1a9a1f715b0d (diff) | |
download | org-mode-4c101529a44f6588ef8dfecb62fba1d9fb1ab335.tar.gz |
Don't throw an error when trying to decrypt before first headline
* lisp/org-crypt.el (org-decrypt-entry): Silently do nothing when
cursor is before first headline.
-rw-r--r-- | lisp/org-crypt.el | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index 6411171..8b25213 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -137,25 +137,26 @@ This setting can also be overridden in the CRYPTKEY property." "Decrypt the content of the current headline." (interactive) (require 'epg) - (save-excursion - (org-back-to-heading t) - (forward-line) - (when (looking-at "-----BEGIN PGP MESSAGE-----") - (let* ((beg (point)) - (end (save-excursion - (search-forward "-----END PGP MESSAGE-----") - (forward-line) - (point))) - (epg-context (epg-make-context nil t t)) - (decrypted-text - (decode-coding-string - (epg-decrypt-string - epg-context - (buffer-substring-no-properties beg end)) - 'utf-8))) - (delete-region beg end) - (insert decrypted-text) - nil)))) + (unless (org-before-first-heading-p) + (save-excursion + (org-back-to-heading t) + (forward-line) + (when (looking-at "-----BEGIN PGP MESSAGE-----") + (let* ((beg (point)) + (end (save-excursion + (search-forward "-----END PGP MESSAGE-----") + (forward-line) + (point))) + (epg-context (epg-make-context nil t t)) + (decrypted-text + (decode-coding-string + (epg-decrypt-string + epg-context + (buffer-substring-no-properties beg end)) + 'utf-8))) + (delete-region beg end) + (insert decrypted-text) + nil))))) (defun org-encrypt-entries () "Encrypt all top-level entries in the current buffer." |