Function: org-decrypt-entry

org-decrypt-entry is an autoloaded, interactive and byte-compiled function defined in org-crypt.el.gz.

Signature

(org-decrypt-entry)

Documentation

Decrypt the content of the current headline.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-crypt.el.gz
;;;###autoload
(defun org-decrypt-entry ()
  "Decrypt the content of the current headline."
  (interactive)
  (pcase (org-at-encrypted-entry-p)
    (`(,beg . ,end)
     (require 'epg)
     (setq-local epg-context (epg-make-context nil t t))
     (org-with-point-at beg
       (org-crypt-check-auto-save)
       (let* ((folded-heading
	       (and (org-invisible-p)
		    (save-excursion
		      (org-previous-visible-heading 1)
		      (point))))
              (level (org-current-level))
	      (encrypted-text (org-crypt--encrypted-text beg end))
	      (decrypted-text
	       (decode-coding-string
		(epg-decrypt-string epg-context encrypted-text)
		'utf-8))
              origin-marker)
	 ;; Delete region starting just before point, because the
	 ;; outline property starts at the \n of the heading.
	 (delete-region (1- (point)) end)
         (setq origin-marker (point-marker))
         (if (string-match (org-headline-re level) decrypted-text)
             ;; If decrypted text contains other headings with levels
             ;; below LEVEL, adjust the subtree.
             (let ((start 0) (min-level level))
               (while (string-match (org-headline-re level) decrypted-text start)
                 (setq min-level (min min-level (1- (length (match-string 0 decrypted-text))))
                       start (match-end 0)))
               (insert "\n"
                       (replace-regexp-in-string
                        org-outline-regexp-bol
                        (concat (make-string (1+ (- level min-level)) ?*) "\\&")
                        decrypted-text)))
	   ;; Store a checksum of the decrypted and the encrypted text
	   ;; value.  This allows reusing the same encrypted text if the
	   ;; text does not change, and therefore avoid a re-encryption
	   ;; process.
	   (insert "\n"
		   (propertize decrypted-text
			       'org-crypt-checksum (sha1 decrypted-text)
			       'org-crypt-key (org-crypt-key-for-heading)
			       'org-crypt-text encrypted-text)))
         ;; Apply initial visibility.
         (save-restriction
           (narrow-to-region origin-marker (point))
           (set-marker origin-marker nil)
           (org-cycle-set-startup-visibility))
         ;; ... but keep the previous folded state.
	 (when folded-heading
	   (goto-char folded-heading)
	   (org-fold-subtree t))
	 nil)))
    (_ nil)))