emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Logan James <frogman1189@gmail.com>
To: emacs-orgmode@gnu.org
Subject: org-crypt patch
Date: Fri, 6 Nov 2020 10:28:31 +1300	[thread overview]
Message-ID: <CAOh9Dizc1DwoGtq+2PLmduB2gjVufAdx7-sfY2NBqDzs5wJtMA@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 504 bytes --]

Add `org-crypt-decrypt-after-save-magic' function to complement the
currently existing `org-crypt-use-before-save-magic' function. Causes the
buffer to be unencrypted after it has been saved to file so that you can
continue working on it without manually running `org-decrypt-entries'
This has the downside of the buffer always being considered as modified,
but is a useful optional function.

Also updated the suggested org-crypt config in the org-manual to include
(org-crypt-decrypt-after-save-magic)

[-- Attachment #1.2: Type: text/html, Size: 587 bytes --]

[-- Attachment #2: 0001-lisp-org-crypt.el-Add-org-crypt-decrypt-after-save-m.patch --]
[-- Type: text/x-patch, Size: 2622 bytes --]

From 3b58d32a03eea8f7a84661a88c451c2e9ed94fbc Mon Sep 17 00:00:00 2001
From: Logan Warner <logan@true.group>
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


                 reply	other threads:[~2020-11-05 21:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOh9Dizc1DwoGtq+2PLmduB2gjVufAdx7-sfY2NBqDzs5wJtMA@mail.gmail.com \
    --to=frogman1189@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).