forked from mirrors/org-mode
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.
This commit is contained in:
parent
ebf808f9aa
commit
4c101529a4
|
@ -137,25 +137,26 @@ This setting can also be overridden in the CRYPTKEY property."
|
||||||
"Decrypt the content of the current headline."
|
"Decrypt the content of the current headline."
|
||||||
(interactive)
|
(interactive)
|
||||||
(require 'epg)
|
(require 'epg)
|
||||||
(save-excursion
|
(unless (org-before-first-heading-p)
|
||||||
(org-back-to-heading t)
|
(save-excursion
|
||||||
(forward-line)
|
(org-back-to-heading t)
|
||||||
(when (looking-at "-----BEGIN PGP MESSAGE-----")
|
(forward-line)
|
||||||
(let* ((beg (point))
|
(when (looking-at "-----BEGIN PGP MESSAGE-----")
|
||||||
(end (save-excursion
|
(let* ((beg (point))
|
||||||
(search-forward "-----END PGP MESSAGE-----")
|
(end (save-excursion
|
||||||
(forward-line)
|
(search-forward "-----END PGP MESSAGE-----")
|
||||||
(point)))
|
(forward-line)
|
||||||
(epg-context (epg-make-context nil t t))
|
(point)))
|
||||||
(decrypted-text
|
(epg-context (epg-make-context nil t t))
|
||||||
(decode-coding-string
|
(decrypted-text
|
||||||
(epg-decrypt-string
|
(decode-coding-string
|
||||||
epg-context
|
(epg-decrypt-string
|
||||||
(buffer-substring-no-properties beg end))
|
epg-context
|
||||||
'utf-8)))
|
(buffer-substring-no-properties beg end))
|
||||||
(delete-region beg end)
|
'utf-8)))
|
||||||
(insert decrypted-text)
|
(delete-region beg end)
|
||||||
nil))))
|
(insert decrypted-text)
|
||||||
|
nil)))))
|
||||||
|
|
||||||
(defun org-encrypt-entries ()
|
(defun org-encrypt-entries ()
|
||||||
"Encrypt all top-level entries in the current buffer."
|
"Encrypt all top-level entries in the current buffer."
|
||||||
|
|
Loading…
Reference in a new issue