From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pieter Praet Subject: [PATCH] org-crypt: make org-decrypt disable auto-save-mode (configurable) Date: Sun, 26 Jun 2011 10:38:04 +0200 Message-ID: <1309077484-1707-1-git-send-email-pieter@praet.org> References: <8762ntjdwr.fsf@praet.org> Return-path: Received: from eggs.gnu.org ([140.186.70.92]:46539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qakr7-0000aq-9c for emacs-orgmode@gnu.org; Sun, 26 Jun 2011 04:38:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qakr5-0007ep-W3 for emacs-orgmode@gnu.org; Sun, 26 Jun 2011 04:38:13 -0400 Received: from mail-wy0-f169.google.com ([74.125.82.169]:42050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qakr5-0007ej-QX for emacs-orgmode@gnu.org; Sun, 26 Jun 2011 04:38:11 -0400 Received: by wyg36 with SMTP id 36so3239742wyg.0 for ; Sun, 26 Jun 2011 01:38:10 -0700 (PDT) In-Reply-To: <8762ntjdwr.fsf@praet.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Dave Abrahams , Bastien , Nick Dokos Signed-off-by: Pieter Praet --- This is appears to be the only solution that doesn't cause the production of inordinate amounts of cortisol. I've also added a warning re the broken state of `auto-save-hook'. lisp/org-crypt.el | 36 ++++++++++++++++++++++++++++++++---- 1 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index 4bff7a1..0a0ce96 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -94,6 +94,15 @@ This setting can also be overridden in the CRYPTKEY property." :type 'string :group 'org-crypt) +(defcustom org-crypt-disable-auto-save t + "What org-decrypt should do if `auto-save-default' is enabled. + +t : Disable it for the current buffer prior to decrypting an entry. +nil : Leave it enabled." + :group 'org-crypt + :type '(choice (const :tag "Always" t) + (const :tag "Never" nil))) + (defun org-crypt-key-for-heading () "Return the encryption key for the current heading." (save-excursion @@ -142,6 +151,24 @@ This setting can also be overridden in the CRYPTKEY property." (defun org-decrypt-entry () "Decrypt the content of the current headline." (interactive) + + ; auto-save-mode causes leakage, so check whether it's enabled. + (when auto-save-default + ; Ideally, we'd check whether it's enabled for the current buffer, + ; using the buffer-local variable `auto-save-mode', but the + ; `auto-save-mode' function doesn't set this, so we have to check + ; the global variable `auto-save-default' instead. + ; Consequently, the following will run regardless of whether + ; `auto-save-mode' is enabled for the current buffer, spamming the + ; *Messages* buffer. + (if (eq org-crypt-disable-auto-save t) + (progn + (message "org-decrypt: Disabling auto-save-mode for current buffer to prevent leakage.") + ; The argument to auto-save-mode has to be "-1", since + ; giving a "nil" argument toggles instead of disabling. + (auto-save-mode -1)) + (message "org-decrypt: WARNING! auto-save-mode is enabled globally. This may cause leakage."))) + (require 'epg) (unless (org-before-first-heading-p) (save-excursion @@ -204,15 +231,16 @@ This setting can also be overridden in the CRYPTKEY property." ;; FIXME Find a better way to encrypt Org auto-saved buffers? ;; When `auto-save-default' is non-nil, make sure entries are ;; encrypted before auto-saving +;; NOTE: auto-save-hook does NOT work, so don't rely on it! ;; (when auto-save-default ;; (add-hook ;; 'org-mode-hook ;; (lambda () (add-hook 'auto-save-hook 'org-encrypt-entries nil t)))) -(when (and (functionp 'daemonp) - (not (daemonp)) auto-save-default) - (message "Warning: turn auto-save-mode off in Org buffers containing crypted entries.") - (sit-for 1)) +;; (when (and (functionp 'daemonp) +;; (not (daemonp)) auto-save-default) +;; (message "Warning: turn auto-save-mode off in Org buffers containing crypted entries.") +;; (sit-for 1)) (add-hook 'org-reveal-start-hook 'org-decrypt-entry) -- 1.7.4.1