[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new file mode: automatic gpg encryption
From: |
Mark A. Hershberger |
Subject: |
Re: new file mode: automatic gpg encryption |
Date: |
Wed, 19 Sep 2007 11:39:17 -0400 |
User-agent: |
Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.0 (gnu/linux) |
Stefan Monnier <address@hidden> 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