Refill some copyright headers.
[bpt/emacs.git] / lisp / epa.el
index 9e02b64..01fba04 100644 (file)
@@ -1,15 +1,17 @@
 ;;; epa.el --- the EasyPG Assistant
-;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+
+;; Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
+;;   Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Keywords: PGP, GnuPG
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Code:
 
@@ -236,7 +236,7 @@ You should bind this variable with `let', but do not set it globally.")
       '(menu-item "Decrypt File..." epa-decrypt-file
                  :help "Decrypt FILE"))
     (define-key menu-map [epa-encrypt-file]
-      '(menu-item "Encrypt File.." epa-encrypt-file
+      '(menu-item "Encrypt File..." epa-encrypt-file
                  :help "Encrypt FILE for RECIPIENTS"))
     (define-key menu-map [separator-epa-key-list] '(menu-item "--"))
     (define-key menu-map [epa-key-list-delete-keys]
@@ -271,7 +271,8 @@ You should bind this variable with `let', but do not set it globally.")
   :help-echo 'epa--key-widget-help-echo)
 
 (defun epa--key-widget-action (widget &optional event)
-  (epa--show-key (widget-get widget :value)))
+  (save-selected-window
+    (epa--show-key (widget-get widget :value))))
 
 (defun epa--key-widget-value-create (widget)
   (let* ((key (widget-get widget :value))
@@ -329,7 +330,7 @@ You should bind this variable with `let', but do not set it globally.")
   (make-local-variable 'epa-exit-buffer-function)
   (make-local-variable 'revert-buffer-function)
   (setq revert-buffer-function 'epa--key-list-revert-buffer)
-  (run-hooks 'epa-key-list-mode-hook))
+  (run-mode-hooks 'epa-key-list-mode-hook))
 
 (defun epa-key-mode ()
   "Major mode for a key description."
@@ -346,7 +347,7 @@ You should bind this variable with `let', but do not set it globally.")
   ;; if buffer-file-name is not set.
   (font-lock-set-defaults)
   (make-local-variable 'epa-exit-buffer-function)
-  (run-hooks 'epa-key-mode-hook))
+  (run-mode-hooks 'epa-key-mode-hook))
 
 (defun epa-info-mode ()
   "Major mode for `epa-info-buffer'."
@@ -357,7 +358,7 @@ You should bind this variable with `let', but do not set it globally.")
        truncate-lines t
        buffer-read-only t)
   (use-local-map epa-info-mode-map)
-  (run-hooks 'epa-info-mode-hook))
+  (run-mode-hooks 'epa-info-mode-hook))
 
 (defun epa-mark-key (&optional arg)
   "Mark a key on the current line.
@@ -464,8 +465,7 @@ If ARG is non-nil, mark the key."
   (apply #'epa--list-keys epa-list-keys-arguments))
 
 (defun epa--marked-keys ()
-  (or (save-excursion
-       (set-buffer epa-keys-buffer)
+  (or (with-current-buffer epa-keys-buffer
        (goto-char (point-min))
        (let (keys key)
          (while (re-search-forward "^\\*" nil t)
@@ -473,18 +473,15 @@ If ARG is non-nil, mark the key."
                                             'epa-key))
                (setq keys (cons key keys))))
          (nreverse keys)))
-      (save-excursion
-       (beginning-of-line)
-       (let ((key (get-text-property (point) 'epa-key)))
-         (if key
-             (list key))))))
+      (let ((key (get-text-property (point-at-bol) 'epa-key)))
+       (if key
+           (list key)))))
 
 (defun epa--select-keys (prompt keys)
-  (save-excursion
-    (unless (and epa-keys-buffer
-                (buffer-live-p epa-keys-buffer))
-      (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
-    (set-buffer epa-keys-buffer)
+  (unless (and epa-keys-buffer
+               (buffer-live-p epa-keys-buffer))
+    (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
+  (with-current-buffer epa-keys-buffer
     (epa-key-list-mode)
     (let ((inhibit-read-only t)
          buffer-read-only)
@@ -511,13 +508,12 @@ If ARG is non-nil, mark the key."
       (set-keymap-parent (current-local-map) widget-keymap)
       (setq epa-exit-buffer-function #'abort-recursive-edit)
       (goto-char (point-min))
-      (pop-to-buffer (current-buffer)))
+      (let ((display-buffer-mark-dedicated 'soft))
+        (pop-to-buffer (current-buffer))))
     (unwind-protect
        (progn
          (recursive-edit)
          (epa--marked-keys))
-      (if (get-buffer-window epa-keys-buffer)
-         (delete-window (get-buffer-window epa-keys-buffer)))
       (kill-buffer epa-keys-buffer))))
 
 ;;;###autoload
@@ -587,7 +583,11 @@ If SECRET is non-nil, list secret keys instead of public keys."
                                      (epg-sub-key-creation-time (car pointer)))
                (error "????-??-??"))
              (if (epg-sub-key-expiration-time (car pointer))
-                 (format "\n\tExpires: %s"
+                 (format (if (time-less-p (current-time)
+                                          (epg-sub-key-expiration-time
+                                           (car pointer)))
+                             "\n\tExpires: %s"
+                           "\n\tExpired: %s")
                          (condition-case nil
                              (format-time-string "%Y-%m-%d"
                                                  (epg-sub-key-expiration-time
@@ -612,8 +612,7 @@ If SECRET is non-nil, list secret keys instead of public keys."
          (setq epa-info-buffer (generate-new-buffer "*Info*")))
        (if (get-buffer-window epa-info-buffer)
            (delete-window (get-buffer-window epa-info-buffer)))
-       (save-excursion
-         (set-buffer epa-info-buffer)
+       (with-current-buffer epa-info-buffer
          (let ((inhibit-read-only t)
                buffer-read-only)
            (erase-buffer)
@@ -632,12 +631,17 @@ If SECRET is non-nil, list secret keys instead of public keys."
 
 (defun epa-display-verify-result (verify-result)
   (epa-display-info (epg-verify-result-to-string verify-result)))
-(make-obsolete 'epa-display-verify-result 'epa-display-info)
+(make-obsolete 'epa-display-verify-result 'epa-display-info "23.1")
 
 (defun epa-passphrase-callback-function (context key-id handback)
   (if (eq key-id 'SYM)
-      (read-passwd "Passphrase for symmetric encryption: "
-                  (eq (epg-context-operation context) 'encrypt))
+      (read-passwd
+       (format "Passphrase for symmetric encryption%s: "
+              ;; Add the file name to the prompt, if any.
+              (if (stringp handback)
+                  (format " for %s" handback)
+                ""))
+       (eq (epg-context-operation context) 'encrypt))
     (read-passwd
      (if (eq key-id 'PIN)
        "Passphrase for PIN: "
@@ -713,8 +717,7 @@ If SECRET is non-nil, list secret keys instead of public keys."
             (setq type 'detached))
            ((eq c ??)
             (with-output-to-temp-buffer "*Help*"
-              (save-excursion
-                (set-buffer standard-output)
+              (with-current-buffer standard-output
                 (insert "\
 n - Create a normal signature
 c - Create a cleartext signature
@@ -722,7 +725,8 @@ d - Create a detached signature
 ? - Show this help
 "))))
            (t
-            (setq type 'normal))))))
+            (setq type 'normal))))
+    type))
 
 ;;;###autoload
 (defun epa-sign-file (file signers mode)
@@ -826,7 +830,8 @@ For example:
       (setq plain (epa--decode-coding-string
                   plain
                   (or coding-system-for-read
-                      (get-text-property start 'epa-coding-system-used))))
+                      (get-text-property start 'epa-coding-system-used)
+                      'undecided)))
       (if (y-or-n-p "Replace the original text? ")
          (let ((inhibit-read-only t)
                buffer-read-only)
@@ -915,7 +920,8 @@ For example:
     (setq plain (epa--decode-coding-string
                 plain
                 (or coding-system-for-read
-                    (get-text-property start 'epa-coding-system-used))))
+                    (get-text-property start 'epa-coding-system-used)
+                    'undecided)))
     (if (y-or-n-p "Replace the original text? ")
        (let ((inhibit-read-only t)
              buffer-read-only)
@@ -1245,5 +1251,4 @@ between START and END."
 
 (provide 'epa)
 
-;; arch-tag: 38d20ced-20d5-4137-b17a-f206335423d7
 ;;; epa.el ends here