Org-mode mailing list
 help / color / mirror / Atom feed
* org-crypt patch
@ 2020-11-05 21:28 Logan James
  0 siblings, 0 replies; only message in thread
From: Logan James @ 2020-11-05 21:28 UTC (permalink / raw)
  To: emacs-orgmode


[-- 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-05 21:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 21:28 org-crypt patch Logan James

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git