From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: mah@everybody.org (Mark A. Hershberger) Newsgroups: gmane.emacs.devel Subject: Re: new file mode: automatic gpg encryption Date: Wed, 19 Sep 2007 11:39:17 -0400 Message-ID: <87abriy89m.fsf@everybody.org> References: <87hclrbeza.fsf@everybody.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1190220952 27255 80.91.229.12 (19 Sep 2007 16:55:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 19 Sep 2007 16:55:52 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 19 18:55:43 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IY2ps-0000vk-Nv for ged-emacs-devel@m.gmane.org; Wed, 19 Sep 2007 18:55:37 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IY2pr-0003Yg-0a for ged-emacs-devel@m.gmane.org; Wed, 19 Sep 2007 12:55:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IY1e4-0000ey-SJ for emacs-devel@gnu.org; Wed, 19 Sep 2007 11:39:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IY1e2-0000dy-OP for emacs-devel@gnu.org; Wed, 19 Sep 2007 11:39:20 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IY1e2-0000do-Jo for emacs-devel@gnu.org; Wed, 19 Sep 2007 11:39:18 -0400 Original-Received: from superman.everybody.org ([216.220.171.94] helo=mail.nichework.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IY1e2-0004Hv-Ab for emacs-devel@gnu.org; Wed, 19 Sep 2007 11:39:18 -0400 Original-Received: from [24.115.83.248] (helo=spawn.everybody.org) by mail.nichework.com with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1IY1dz-0000In-Ck; Wed, 19 Sep 2007 11:39:16 -0400 X-URL: http://mah.everybody.org/weblog/ In-Reply-To: (Stefan Monnier's message of "Tue, 18 Sep 2007 22:35:55 -0400") User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.0 (gnu/linux) X-SA-Exim-Connect-IP: 24.115.83.248 X-SA-Exim-Mail-From: mah@everybody.org X-SA-Exim-Version: 4.2.1 (built Tue, 09 Jan 2007 17:23:22 +0000) X-SA-Exim-Scanned: Yes (on mail.nichework.com) X-Detected-Kernel: Linux 2.6 (newer, 3) X-Mailman-Approved-At: Wed, 19 Sep 2007 12:55:31 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:79331 Archived-At: Stefan Monnier 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