From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pieter Praet Subject: Re: [PATCH] org-crypt: when running org-decrypt-entry, only run auto-save-mode check if on an encrypted entry Date: Thu, 27 Oct 2011 10:52:32 +0200 Message-ID: <8762jazui7.fsf@praet.org> References: <878vqdpy3v.fsf@praet.org> <1314539207-15985-1-git-send-email-pieter@praet.org> <1E90A07C-2176-4265-934C-9159E1EEE76E@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([140.186.70.92]:33903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJLi8-00066Y-GM for emacs-orgmode@gnu.org; Thu, 27 Oct 2011 04:53:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJLi6-0006fX-PH for emacs-orgmode@gnu.org; Thu, 27 Oct 2011 04:53:16 -0400 Received: from mail-wy0-f169.google.com ([74.125.82.169]:48568) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJLi6-0006fM-Fx for emacs-orgmode@gnu.org; Thu, 27 Oct 2011 04:53:14 -0400 Received: by wyg34 with SMTP id 34so3086027wyg.0 for ; Thu, 27 Oct 2011 01:53:12 -0700 (PDT) In-Reply-To: <1E90A07C-2176-4265-934C-9159E1EEE76E@gmail.com> 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: Carsten Dominik Cc: emacs-orgmode@gnu.org On Sat, 8 Oct 2011 18:11:32 +0200, Carsten Dominik wrote: > Accepted, thanks. Thanks Carsten! BTW, my FSF copyright assignment is completed (assignment number #705083) so I should probably be added to the list of signees [1]. Would you like me to provide a patch to that effect? > - Carsten > > On 28.8.2011, at 15:46, Pieter Praet wrote: > > > * lisp/org-crypt.el (org-crypt-check-auto-save): New function, see next change. > > * lisp/org-crypt.el (org-decrypt-entry): Break the auto-save-mode check out > > into a separate function, and call it at a later point, to assure it only > > runs when visiting an encrypted entry. > > > > Currently `org-decrypt-entry' is doing the auto-save-mode check whenever > > it's run, regardless of context, while this only makes sense when run on > > an entry which is actually encrypted (or looks like it, at least). > > > > Signed-off-by: Pieter Praet > > --- > > > > lisp/org-crypt.el | 54 +++++++++++++++++++++++++++++----------------------- > > 1 files changed, 30 insertions(+), 24 deletions(-) > > > > diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el > > index 5991192..f764404 100644 > > --- a/lisp/org-crypt.el > > +++ b/lisp/org-crypt.el > > @@ -116,6 +116,35 @@ nil : Leave auto-save-mode enabled. > > (const :tag "Ask" ask) > > (const :tag "Encrypt" encrypt))) > > > > +(defun org-crypt-check-auto-save () > > + "Check whether auto-save-mode is enabled for the current buffer. > > + > > +`auto-save-mode' may cause leakage when decrypting entries, so > > +check whether it's enabled, and decide what to do about it. > > + > > +See `org-crypt-disable-auto-save'." > > + (when buffer-auto-save-file-name > > + (cond > > + ((or > > + (eq org-crypt-disable-auto-save t) > > + (and > > + (eq org-crypt-disable-auto-save 'ask) > > + (y-or-n-p "org-decrypt: auto-save-mode may cause leakage. Disable it for current buffer? "))) > > + (message (concat "org-decrypt: Disabling auto-save-mode for " (or (buffer-file-name) (current-buffer)))) > > + ; The argument to auto-save-mode has to be "-1", since > > + ; giving a "nil" argument toggles instead of disabling. > > + (auto-save-mode -1)) > > + ((eq org-crypt-disable-auto-save nil) > > + (message "org-decrypt: Decrypting entry with auto-save-mode enabled. This may cause leakage.")) > > + ((eq org-crypt-disable-auto-save 'encrypt) > > + (message "org-decrypt: Enabling re-encryption on auto-save.") > > + (add-hook 'auto-save-hook > > + (lambda () > > + (message "org-crypt: Re-encrypting all decrypted entries due to auto-save.") > > + (org-encrypt-entries)) > > + nil t)) > > + (t nil)))) > > + > > (defun org-crypt-key-for-heading () > > "Return the encryption key for the current heading." > > (save-excursion > > @@ -164,30 +193,6 @@ nil : Leave auto-save-mode enabled. > > (defun org-decrypt-entry () > > "Decrypt the content of the current headline." > > (interactive) > > - > > - ; auto-save-mode may cause leakage, so check whether it's enabled. > > - (when buffer-auto-save-file-name > > - (cond > > - ((or > > - (eq org-crypt-disable-auto-save t) > > - (and > > - (eq org-crypt-disable-auto-save 'ask) > > - (y-or-n-p "org-decrypt: auto-save-mode may cause leakage. Disable it for current buffer? "))) > > - (message (concat "org-decrypt: Disabling auto-save-mode for " (or (buffer-file-name) (current-buffer)))) > > - ; The argument to auto-save-mode has to be "-1", since > > - ; giving a "nil" argument toggles instead of disabling. > > - (auto-save-mode -1)) > > - ((eq org-crypt-disable-auto-save nil) > > - (message "org-decrypt: Decrypting entry with auto-save-mode enabled. This may cause leakage.")) > > - ((eq org-crypt-disable-auto-save 'encrypt) > > - (message "org-decrypt: Enabling re-encryption on auto-save.") > > - (add-hook 'auto-save-hook > > - (lambda () > > - (message "org-crypt: Re-encrypting all decrypted entries due to auto-save.") > > - (org-encrypt-entries)) > > - nil t)) > > - (t nil))) > > - > > (require 'epg) > > (unless (org-before-first-heading-p) > > (save-excursion > > @@ -199,6 +204,7 @@ nil : Leave auto-save-mode enabled. > > (outline-invisible-p)))) > > (forward-line) > > (when (looking-at "-----BEGIN PGP MESSAGE-----") > > + (org-crypt-check-auto-save) > > (let* ((end (save-excursion > > (search-forward "-----END PGP MESSAGE-----") > > (forward-line) > > -- > > 1.7.5.4 > > > > > Peace -- Pieter [1] http://orgmode.org/worg/org-contribute.html#contributors_with_fsf_papers