unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: mah@everybody.org (Mark A. Hershberger)
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: new file mode: automatic gpg encryption
Date: Wed, 19 Sep 2007 11:39:17 -0400	[thread overview]
Message-ID: <87abriy89m.fsf@everybody.org> (raw)
In-Reply-To: <jwvy7f3o03d.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 18 Sep 2007 22:35:55 -0400")

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> On emacswiki.org, I found a snippet of code that uses mailcrypt to
>> automatically encrypt and decrypt a file with the .gpg extension.
>
>> I rewrote this to use the functions bundled with emacs and think it
>> would be a useful addition to emacs.

> How 'bout posting a patch here?

I'm pretty sure the design is wrong.  That is, you can see the buffer
fill with encrypted text for just a bit (when the before-save-hook is
run) and then return to its previous state (when after-save-hook is
run).

Since this is the first time I've worked with a mode like this at all, I
can modify it as needed.

After looking at "(elisp) Saving Buffers", I suspect that the proper
place for this is the write-file-functions hook (which
allout-write-file-hook-handler uses to encrypt specific regions of
text).

Also, I've used pgg-gpg-* functions when I should probably use pgg-*
functions.

In any case, here is the code snippet I'm using.

(defvar pgg-gpg-user-id "YOUR-ID-HERE")
(autoload 'pgg-make-temp-file "pgg" "PGG")
(autoload 'pgg-gpg-decrypt-region "pgg-gpg" "PGG GnuPG")
(define-generic-mode 'gpg-file-mode
  (list ?#) 
  nil nil
  '(".gpg\\'" ".gpg-encrypted\\'")
  (list (lambda ()
	    (add-hook 'before-save-hook
                      (lambda () 
                        (let ((pgg-output-buffer (current-buffer)))
                          (pgg-gpg-encrypt-region (point-min) (point-max)
                                                  (list pgg-gpg-user-id))))
                      nil t)
	    (add-hook 'after-save-hook 
		      (lambda ()
                        (let ((pgg-output-buffer (current-buffer)))
                          (pgg-gpg-decrypt-region (point-min) (point-max)))
			(set-buffer-modified-p nil)
			(auto-save-mode nil))
		      nil t)
            (let ((pgg-output-buffer (current-buffer)))
              (pgg-gpg-decrypt-region (point-min) (point-max)))
	    (auto-save-mode nil)
	    (set-buffer-modified-p nil)))
  "Mode for gpg encrypted files")

-- 
http://hexmode.com/
GPG Fingerprint: 7E15 362D A32C DFAB E4D2  B37A 735E F10A 2DFC BFF5

The most beautiful experience we can have is the mysterious.
    -- Albert Einstein, The World As I See it

      parent reply	other threads:[~2007-09-19 15:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-19  1:50 new file mode: automatic gpg encryption Mark A. Hershberger
2007-09-19  1:56 ` Leo
2007-09-19  2:35 ` Stefan Monnier
2007-09-19  8:36   ` Leo
2007-09-19 15:39   ` Mark A. Hershberger [this message]

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87abriy89m.fsf@everybody.org \
    --to=mah@everybody.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.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).