annotate lisp/epa-hook.el @ 97596:87f135663b95

*** empty log message ***
author John Paul Wallington <jpw@pobox.com>
date Thu, 21 Aug 2008 12:31:50 +0000
parents 2b066c2202f5
children 4dfef179eed3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
94752
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1 ;;; epa-hook.el --- preloaded code to enable epa-file.el
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
5 ;; Keywords: PGP, GnuPG
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
6
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation, either version 3 of the License, or
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12 ;; (at your option) any later version.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
18
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22 ;;; Code:
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24 (defgroup epa-file nil
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25 "The EasyPG Assistant hooks for transparent file encryption"
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
26 :version "23.1"
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27 :group 'epa)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29 (defun epa-file--file-name-regexp-set (variable value)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (set-default variable value)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (if (fboundp 'epa-file-name-regexp-update)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32 (epa-file-name-regexp-update)))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34 (defcustom epa-file-name-regexp "\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'"
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 "Regexp which matches filenames to be encrypted with GnuPG.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37 If you set this outside Custom while epa-file is already enabled, you
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 have to call `epa-file-name-regexp-update' after setting it to
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 properly update file-name-handler-alist. Setting this through Custom
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 does that automatically."
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41 :type 'regexp
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42 :group 'epa-file
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 :set 'epa-file--file-name-regexp-set)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 (defcustom epa-file-inhibit-auto-save t
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 "If non-nil, disable auto-saving when opening an encrypted file."
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 :type 'boolean
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 :group 'epa-file)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 (defvar epa-file-encrypt-to nil
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 "*Recipient(s) used for encrypting files.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 May either be a string or a list of strings.")
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (put 'epa-file-encrypt-to 'safe-local-variable
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 (lambda (val)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
56 (or (stringp val)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57 (and (listp val)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (catch 'safe
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (mapc (lambda (elt)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60 (unless (stringp elt)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61 (throw 'safe nil)))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 val)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 t)))))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (put 'epa-file-encrypt-to 'permanent-local t)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (defvar epa-file-handler
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (cons epa-file-name-regexp 'epa-file-handler))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70 (defvar epa-file-auto-mode-alist-entry
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71 (list epa-file-name-regexp nil 'epa-file))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (defun epa-file-name-regexp-update ()
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (interactive)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 (unless (equal (car epa-file-handler) epa-file-name-regexp)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76 (setcar epa-file-handler epa-file-name-regexp)))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (defun epa-file-find-file-hook ()
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (if (and buffer-file-name
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (string-match epa-file-name-regexp buffer-file-name)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 epa-file-inhibit-auto-save)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (auto-save-mode 0))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (set-buffer-modified-p nil))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (define-minor-mode auto-encryption-mode
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 "Toggle automatic file encryption and decryption.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 With prefix argument ARG, turn auto encryption on if positive, else off.
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 Return the new status of auto encryption (non-nil means on)."
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 :global t :init-value t :group 'epa-file :version "23.1"
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (setq file-name-handler-alist
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (delq epa-file-handler file-name-handler-alist))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (remove-hook 'find-file-hooks 'epa-file-find-file-hook)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (setq auto-mode-alist (delq epa-file-auto-mode-alist-entry
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 auto-mode-alist))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (when auto-encryption-mode
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (setq file-name-handler-alist
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (cons epa-file-handler file-name-handler-alist))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (add-hook 'find-file-hook 'epa-file-find-file-hook)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (setq auto-mode-alist (cons epa-file-auto-mode-alist-entry
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 auto-mode-alist))))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 (put 'epa-file-handler 'safe-magic t)
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (put 'epa-file-handler 'operations '(write-region insert-file-contents))
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104
94755
14eda1195ec3 Provide/require epa-hook, not epa-file-hook.
Eli Zaretskii <eliz@gnu.org>
parents: 94752
diff changeset
105 (provide 'epa-hook)
94752
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106
73a86a36a458 Renamed lisp/epa-file-hook.el to lisp/epa-hook.el.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 ;; arch-tag: f75c8a50-d32e-4eb3-9ec6-9e940c1fc8b5
94758
2b066c2202f5 Change file name on the last line.
Eli Zaretskii <eliz@gnu.org>
parents: 94755
diff changeset
108 ;;; epa-hook.el ends here