Skip to content

Instantly share code, notes, and snippets.

@etyurkin
Last active October 12, 2018 14:24
Show Gist options
  • Save etyurkin/6430f23113ec6c81b0c4f0a2a326d5f4 to your computer and use it in GitHub Desktop.
Save etyurkin/6430f23113ec6c81b0c4f0a2a326d5f4 to your computer and use it in GitHub Desktop.
(defun org-display-decrypted-entry ()
"Display decrypted content of the current headline in a new read-only buffer."
(interactive)
(require 'epg)
(unless (org-before-first-heading-p)
(org-with-wide-buffer
(org-back-to-heading t)
(let ((heading-point (point))
(heading-was-invisible-p
(save-excursion
(outline-end-of-heading)
(org-invisible-p))))
(org-end-of-meta-data)
(when (looking-at "-----BEGIN PGP MESSAGE-----")
(setq-local epg-context (epg-make-context nil t t))
(let* ((end (save-excursion
(search-forward "-----END PGP MESSAGE-----")
(forward-line)
(point)))
(encrypted-text (buffer-substring-no-properties (point) end))
(decrypted-text
(decode-coding-string
(epg-decrypt-string
epg-context
encrypted-text)
'utf-8)))
(let* ((entry-name (elt (org-heading-components) 4))
(buf-name (concat "*decrypted: " entry-name "*"))
(buf (get-buffer-create buf-name)))
(with-current-buffer buf
(read-only-mode -1)
(erase-buffer)
(insert decrypted-text)
(read-only-mode)
(org-mode)
(pop-to-buffer buf)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment