From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?=C3=93scar_Fuentes?= Subject: [PATCH] Wash output of org-encrypt-entry Date: Fri, 18 Mar 2011 18:05:58 +0100 Message-ID: <87pqpo2wax.fsf@wanadoo.es> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=58658 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0d7w-00037l-LO for emacs-orgmode@gnu.org; Fri, 18 Mar 2011 13:06:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0d7v-0001uw-Gr for emacs-orgmode@gnu.org; Fri, 18 Mar 2011 13:06:16 -0400 Received: from lo.gmane.org ([80.91.229.12]:57781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0d7v-0001uq-3n for emacs-orgmode@gnu.org; Fri, 18 Mar 2011 13:06:15 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q0d7s-0006CC-4e for emacs-orgmode@gnu.org; Fri, 18 Mar 2011 18:06:12 +0100 Received: from 27.red-79-158-173.staticip.rima-tde.net ([79.158.173.27]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Mar 2011 18:06:12 +0100 Received: from ofv by 27.red-79-158-173.staticip.rima-tde.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Mar 2011 18:06:12 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org With a gpg executable with default settings, org-encrypt-entry produces output like this: -----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.10 (GNU/Linux) jA0EAwMCBWZVym6QMPVgyTxreTb1AEL3uTO+qCh2lR9/Qxk4nEMpPr9/RwNk95Gb slUra9X+N+qSWghEHvvxY0Ol8Yw9Ko4n7JVhHFs= =E4vw -----END PGP MESSAGE----- The first line (Version:...) can change from machine to machine and over time (as gpg is updated with a new version.) This is problematic when the file is stored under version control, because as you decrypt and encrypt an entry that line will change and create differences among the file on the workspace and the file stored on VC. Second, the empty line just wastes space and it is plain ugly once we remove the first one with the Version text. Finally, on some systems (mostly Windows) depending on how your Emacs and gpg are configured, ^M characters may appear at the end of every line of gpg output once it is inserted on the Emacs buffer. This happens when the buffer uses Unix line-endings but gpg uses DOS line-endings. The patch removes all that junk from the encrypted text just before it is inserted on the buffer. I'm assuming that the transformations made by this patch are uncontroversial and desirable. If anyone actually prefers to keep that noise on his encrypted org entries, an alternative implementation that uses a configurable list of regexps is trivial to implement, but then every user would have to do some job for achieving the same result. diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index b649e39..8ba382e 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -112,6 +112,17 @@ This setting can also be overridden in the CRYPTKEY property." (let ((epg-context (epg-make-context nil t t))) (epg-encrypt-string epg-context str (epg-list-keys epg-context crypt-key))))) +(defun org-crypt-wash-encrypted-string (str) + "Remove superfluos and annoying text from the encrypted string." + ;; Remove gpg version information: + (setq str (replace-regexp-in-string "^Version:.*$" "" str)) + ;; Remove ^M characters created by end-of-line type mismatch + ;; (Windows suffer from this): + (setq str (replace-regexp-in-string "\^M" "" str)) + ;; Remove empty lines: + (setq str (replace-regexp-in-string "^\n" "" str)) + str) + (defun org-encrypt-entry () "Encrypt the content of the current headline." (interactive) @@ -133,6 +144,7 @@ This setting can also be overridden in the CRYPTKEY property." encrypted-text (org-encrypt-string (buffer-substring beg end) crypt-key)) (delete-region beg end) + (setq encrypted-text (org-crypt-wash-encrypted-string encrypted-text)) (insert encrypted-text) (when folded (goto-char start-heading)