-;;; epa.el --- the EasyPG Assistant
-;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;;; epa.el --- the EasyPG Assistant -*- lexical-binding: t -*-
+
+;; Copyright (C) 2006-2012 Free Software Foundation, Inc.
;; Author: Daiki Ueno <ueno@unixuser.org>
;; Keywords: PGP, GnuPG
(20 . ?G)))
(defvar epa-protocol 'OpenPGP
- "*The default protocol.
+ "The default protocol.
The value can be either OpenPGP or CMS.
You should bind this variable with `let', but do not set it globally.")
(defvar epa-armor nil
- "*If non-nil, epa commands create ASCII armored output.
+ "If non-nil, epa commands create ASCII armored output.
You should bind this variable with `let', but do not set it globally.")
(defvar epa-textmode nil
- "*If non-nil, epa commands treat input files as text.
+ "If non-nil, epa commands treat input files as text.
You should bind this variable with `let', but do not set it globally.")
(define-key keymap "g" 'revert-buffer)
(define-key keymap "n" 'next-line)
(define-key keymap "p" 'previous-line)
- (define-key keymap " " 'scroll-up)
- (define-key keymap [delete] 'scroll-down)
+ (define-key keymap " " 'scroll-up-command)
+ (define-key keymap [delete] 'scroll-down-command)
(define-key keymap "q" 'epa-exit-buffer)
(define-key keymap [menu-bar epa-key-list-mode] (cons "Keys" menu-map))
(define-key menu-map [epa-key-list-unmark-key]
:help "Encrypt FILE for RECIPIENTS"))
(define-key menu-map [separator-epa-key-list] '(menu-item "--"))
(define-key menu-map [epa-key-list-delete-keys]
- '(menu-item "Delete keys" epa-delete-keys
+ '(menu-item "Delete Keys" epa-delete-keys
:help "Delete Marked Keys"))
(define-key menu-map [epa-key-list-import-keys]
'(menu-item "Import Keys" epa-import-keys
:action 'epa--key-widget-action
:help-echo 'epa--key-widget-help-echo)
-(defun epa--key-widget-action (widget &optional event)
+(defun epa--key-widget-action (widget &optional _event)
(save-selected-window
(epa--show-key (widget-get widget :value))))
(list nil)))
(epa--list-keys name t))
-(defun epa--key-list-revert-buffer (&optional ignore-auto noconfirm)
+(defun epa--key-list-revert-buffer (&optional _ignore-auto _noconfirm)
(apply #'epa--list-keys epa-list-keys-arguments))
(defun epa--marked-keys ()
'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)
(unless (and epa-keys-buffer
(setq epa-keys-buffer (generate-new-buffer "*Keys*")))
(with-current-buffer epa-keys-buffer
(epa-key-list-mode)
+ ;; C-c C-c is the usual way to finish the selection (bug#11159).
+ (define-key (current-local-map) "\C-c\C-c" 'exit-recursive-edit)
(let ((inhibit-read-only t)
buffer-read-only)
(erase-buffer)
- `\\[epa-mark-key]' to mark a key on the line
- `\\[epa-unmark-key]' to unmark a key on the line\n"))
(widget-create 'link
- :notify (lambda (&rest ignore) (abort-recursive-edit))
+ :notify (lambda (&rest _ignore) (abort-recursive-edit))
:help-echo
(substitute-command-keys
"Click here or \\[abort-recursive-edit] to cancel")
"Cancel")
(widget-create 'link
- :notify (lambda (&rest ignore) (exit-recursive-edit))
+ :notify (lambda (&rest _ignore) (exit-recursive-edit))
:help-echo
(substitute-command-keys
"Click here or \\[exit-recursive-edit] to finish")
(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: "
(format "Passphrase for %s %s: " key-id (cdr entry))
(format "Passphrase for %s: " key-id)))))))
-(defun epa-progress-callback-function (context what char current total
+(defun epa-progress-callback-function (_context what _char current total
handback)
- (message "%s%d%% (%d/%d)" (or handback
- (concat what ": "))
- (if (> total 0) (floor (* (/ current (float total)) 100)) 0)
- current total))
+ (let ((prompt (or handback
+ (format "Processing %s: " what))))
+ ;; According to gnupg/doc/DETAIL: a "total" of 0 indicates that
+ ;; the total amount is not known. The condition TOTAL && CUR ==
+ ;; TOTAL may be used to detect the end of an operation.
+ (if (> total 0)
+ (if (= current total)
+ (message "%s...done" prompt)
+ (message "%s...%d%%" prompt
+ (floor (* (/ current (float total)) 100))))
+ (message "%s..." prompt))))
;;;###autoload
(defun epa-decrypt-file (file)
(file-name-nondirectory cipher))))
;;;###autoload
-(defun epa-decrypt-region (start end)
+(defun epa-decrypt-region (start end &optional make-buffer-function)
"Decrypt the current region between START and END.
-Don't use this command in Lisp programs!
+If MAKE-BUFFER-FUNCTION is non-nil, call it to prepare an output buffer.
+It should return that buffer. If it copies the input, it should
+delete the text now being decrypted. It should leave point at the
+proper place to insert the plaintext.
+
+Be careful about using this command in Lisp programs!
Since this function operates on regions, it does some tricks such
as coding-system detection and unibyte/multibyte conversion. If
you are sure how the data in the region should be treated, you
(or coding-system-for-read
(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)
- (delete-region start end)
- (goto-char start)
- (insert plain))
- (with-output-to-temp-buffer "*Temp*"
- (set-buffer standard-output)
- (insert plain)
- (epa-info-mode)))
+ (if make-buffer-function
+ (with-current-buffer (funcall make-buffer-function)
+ (let ((inhibit-read-only t))
+ (insert plain)))
+ (if (y-or-n-p "Replace the original text? ")
+ (let ((inhibit-read-only t))
+ (delete-region start end)
+ (goto-char start)
+ (insert plain))
+ (with-output-to-temp-buffer "*Temp*"
+ (set-buffer standard-output)
+ (insert plain)
+ (epa-info-mode))))
(if (epg-context-result-for context 'verify)
(epa-display-info (epg-verify-result-to-string
(epg-context-result-for context 'verify)))))))
(if (featurep 'xemacs)
(if (fboundp 'find-coding-system)
(find-coding-system mime-charset))
+ ;; Find the first coding system which corresponds to MIME-CHARSET.
(let ((pointer (coding-system-list)))
(while (and pointer
- (eq (coding-system-get (car pointer) 'mime-charset)
- mime-charset))
+ (not (eq (coding-system-get (car pointer) 'mime-charset)
+ mime-charset)))
(setq pointer (cdr pointer)))
- pointer)))
+ (car pointer))))
;;;###autoload
(defun epa-decrypt-armor-in-region (start end)
armor-end (re-search-forward "^-----END PGP MESSAGE-----$"
nil t))
(unless armor-end
- (error "No armor tail"))
+ (error "Encryption armor beginning has no matching end"))
(goto-char armor-start)
(let ((coding-system-for-read
(or coding-system-for-read
(eval-and-compile
(if (fboundp 'select-safe-coding-system)
(defalias 'epa--select-safe-coding-system 'select-safe-coding-system)
- (defun epa--select-safe-coding-system (from to)
+ (defun epa--select-safe-coding-system (_from _to)
buffer-file-coding-system)))
;;;###autoload
"Insert selected KEYS after the point."
(interactive
(list (epa-select-keys (epg-make-context epa-protocol)
- "Select keys to export. ")))
+ "Select keys to export.
+If no one is selected, default public key is exported. ")))
(let ((context (epg-make-context epa-protocol)))
;;(epg-context-set-armor context epa-armor)
(epg-context-set-armor context t)
(provide 'epa)
-;; arch-tag: 38d20ced-20d5-4137-b17a-f206335423d7
;;; epa.el ends here