From 3b58d32a03eea8f7a84661a88c451c2e9ed94fbc Mon Sep 17 00:00:00 2001 From: Logan Warner Date: Fri, 6 Nov 2020 10:11:27 +1300 Subject: [PATCH] lisp/org-crypt.el: Add org-crypt-decrypt-after-save-magic which complements the org-crypt-use-before-save-magic function * org-crypt.el (org-crypt-decrypt-after-save-magic): Add the complement of `org-crypt-use-before-save' called `org-crypt-decrypt-after-save-magic' which adds a function to the hook `after-save-hook' which calls `org-decrypt-entries' * org-manual.org (Org Crypt): add "(org-crypt-decrypt-after-save-magic)" to the suggested org crypt settings in the Emacs init file, below "(org-crypt-use-before-save-magic)" `org-crypt-decrypt-after-save-magic' currently encrypts entries on save but doesn't decrypt them again after the file has been saved. This causes users to have to call `org-decrypt-entries'. Adding the new function allows users to add it to their .emacs and remove this requirement. TINYCHANGE --- doc/org-manual.org | 1 + lisp/org-crypt.el | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/doc/org-manual.org b/doc/org-manual.org index 7ab7d1c94..6679bea40 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -19706,6 +19706,7 @@ Here is a suggestion for Org Crypt settings in Emacs init file: #+begin_src emacs-lisp (require 'org-crypt) (org-crypt-use-before-save-magic) +(org-crypt-decrypt-after-save-magic) (setq org-tags-exclude-from-inheritance '("crypt")) (setq org-crypt-key nil) diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index 187560c55..b8d71114d 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -46,6 +46,10 @@ ;; 4. To automatically encrypt all necessary entries when saving a ;; file, call `org-crypt-use-before-save-magic' after loading ;; org-crypt.el. +;; +;; 5. To automatically decrypt all neccessary entries which have been +;; encrypted by `org-crypt-use-before-save-magic' after the file +;; has been saved call `org-crypt-decrypt-after-save-magic' ;;; Thanks: @@ -311,6 +315,15 @@ Assume `epg-context' is set." 'org-mode-hook (lambda () (add-hook 'before-save-hook 'org-encrypt-entries nil t)))) +;; Note +;; This will cause the buffer to always register as having been modified +;;;###autoload +(defun org-crypt-decrypt-after-save-magic () + "Add a hook to automatically decrypt entries after a file has been saved to disk." + (add-hook + 'org-mode-hook + (lambda () (add-hook 'after-save-hook 'org-decrypt-entries nil t)))) + (add-hook 'org-reveal-start-hook 'org-decrypt-entry) (provide 'org-crypt) -- 2.29.1