diff options
| author | Daiki Ueno | 2014-11-18 16:19:14 +0900 |
|---|---|---|
| committer | Daiki Ueno | 2014-11-18 16:19:14 +0900 |
| commit | 9e8da9d27928ba19bf0c383a080b2fd01ad9f157 (patch) | |
| tree | 193417ab732bb1fd07efeefd9a62669d1b05b060 | |
| parent | b3cb91e07c26a3f83f684d9f7248c4492bf8fcc1 (diff) | |
| download | emacs-9e8da9d27928ba19bf0c383a080b2fd01ad9f157.tar.gz emacs-9e8da9d27928ba19bf0c383a080b2fd01ad9f157.zip | |
epg: Support key editing
* epg.el (epg-context): New slot EDIT-CALLBACK.
(epg--process-filter): Call EDIT-CALLBACK when editing a key.
(epg-reset): Reset EDIT-CALLBACK of the context.
(epg-start-edit-key): New function.
(epg-edit-key): New function.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/epg.el | 62 |
2 files changed, 62 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index feb93854eea..e885c924487 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2014-11-18 Daiki Ueno <ueno@gnu.org> | ||
| 2 | |||
| 3 | * epg.el (epg-context): New slot EDIT-CALLBACK. | ||
| 4 | (epg--process-filter): Call EDIT-CALLBACK when editing a key. | ||
| 5 | (epg-reset): Reset EDIT-CALLBACK of the context. | ||
| 6 | (epg-start-edit-key): New function. | ||
| 7 | (epg-edit-key): New function. | ||
| 8 | |||
| 1 | 2014-11-18 Paul Eggert <eggert@cs.ucla.edu> | 9 | 2014-11-18 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 10 | ||
| 3 | Port new time stamp handling to Emacs 23.2. | 11 | Port new time stamp handling to Emacs 23.2. |
diff --git a/lisp/epg.el b/lisp/epg.el index 20e67850693..520ff8d78b7 100644 --- a/lisp/epg.el +++ b/lisp/epg.el | |||
| @@ -205,6 +205,7 @@ | |||
| 205 | compress-algorithm | 205 | compress-algorithm |
| 206 | (passphrase-callback (list #'epg-passphrase-callback-function)) | 206 | (passphrase-callback (list #'epg-passphrase-callback-function)) |
| 207 | progress-callback | 207 | progress-callback |
| 208 | edit-callback | ||
| 208 | signers | 209 | signers |
| 209 | sig-notations | 210 | sig-notations |
| 210 | process | 211 | process |
| @@ -668,15 +669,27 @@ callback data (if any)." | |||
| 668 | (beginning-of-line) | 669 | (beginning-of-line) |
| 669 | (while (looking-at ".*\n") ;the input line finished | 670 | (while (looking-at ".*\n") ;the input line finished |
| 670 | (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)") | 671 | (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)") |
| 671 | (let* ((status (match-string 1)) | 672 | (let ((status (match-string 1)) |
| 672 | (string (match-string 2)) | 673 | (string (match-string 2)) |
| 673 | (symbol (intern-soft (concat "epg--status-" | 674 | symbol) |
| 674 | status)))) | ||
| 675 | (if (member status epg-pending-status-list) | 675 | (if (member status epg-pending-status-list) |
| 676 | (setq epg-pending-status-list nil)) | 676 | (setq epg-pending-status-list nil)) |
| 677 | (if (and symbol | 677 | ;; When editing a key, delegate all interaction |
| 678 | (fboundp symbol)) | 678 | ;; to edit-callback. |
| 679 | (funcall symbol epg-context string)) | 679 | (if (eq (epg-context-operation epg-context) 'edit-key) |
| 680 | (funcall (car (epg-context-edit-callback | ||
| 681 | epg-context)) | ||
| 682 | epg-context | ||
| 683 | status | ||
| 684 | string | ||
| 685 | (cdr (epg-context-edit-callback | ||
| 686 | epg-context))) | ||
| 687 | ;; Otherwise call epg--status-STATUS function. | ||
| 688 | (setq symbol (intern-soft (concat "epg--status-" | ||
| 689 | status))) | ||
| 690 | (if (and symbol | ||
| 691 | (fboundp symbol)) | ||
| 692 | (funcall symbol epg-context string))) | ||
| 680 | (setq epg-last-status (cons status string))) | 693 | (setq epg-last-status (cons status string))) |
| 681 | ;; Record other lines sent to stderr. This assumes | 694 | ;; Record other lines sent to stderr. This assumes |
| 682 | ;; that the process-filter receives output only from | 695 | ;; that the process-filter receives output only from |
| @@ -736,7 +749,8 @@ callback data (if any)." | |||
| 736 | (if (and (epg-context-process context) | 749 | (if (and (epg-context-process context) |
| 737 | (buffer-live-p (process-buffer (epg-context-process context)))) | 750 | (buffer-live-p (process-buffer (epg-context-process context)))) |
| 738 | (kill-buffer (process-buffer (epg-context-process context)))) | 751 | (kill-buffer (process-buffer (epg-context-process context)))) |
| 739 | (setf (epg-context-process context) nil)) | 752 | (setf (epg-context-process context) nil) |
| 753 | (setf (epg-context-edit-callback context) nil)) | ||
| 740 | 754 | ||
| 741 | (defun epg-delete-output-file (context) | 755 | (defun epg-delete-output-file (context) |
| 742 | "Delete the output file of CONTEXT." | 756 | "Delete the output file of CONTEXT." |
| @@ -2084,6 +2098,38 @@ PARAMETERS is a string which tells how to create the key." | |||
| 2084 | (epg-errors-to-string errors)))))) | 2098 | (epg-errors-to-string errors)))))) |
| 2085 | (epg-reset context))) | 2099 | (epg-reset context))) |
| 2086 | 2100 | ||
| 2101 | (defun epg-start-edit-key (context key edit-callback handback) | ||
| 2102 | "Initiate an edit operation on KEY. | ||
| 2103 | |||
| 2104 | EDIT-CALLBACK is called from process filter and takes 3 | ||
| 2105 | arguments: the context, a status, an argument string, and the | ||
| 2106 | handback argument. | ||
| 2107 | |||
| 2108 | If you use this function, you will need to wait for the completion of | ||
| 2109 | `epg-gpg-program' by using `epg-wait-for-completion' and call | ||
| 2110 | `epg-reset' to clear a temporary output file. | ||
| 2111 | If you are unsure, use synchronous version of this function | ||
| 2112 | `epg-edit-key' instead." | ||
| 2113 | (setf (epg-context-operation context) 'edit-key) | ||
| 2114 | (setf (epg-context-result context) nil) | ||
| 2115 | (setf (epg-context-edit-callback context) (cons edit-callback handback)) | ||
| 2116 | (epg--start context (list "--edit-key" | ||
| 2117 | (epg-sub-key-id | ||
| 2118 | (car (epg-key-sub-key-list key)))))) | ||
| 2119 | |||
| 2120 | (defun epg-edit-key (context key edit-callback handback) | ||
| 2121 | "Edit KEY in the keyring." | ||
| 2122 | (unwind-protect | ||
| 2123 | (progn | ||
| 2124 | (epg-start-edit-key context key edit-callback handback) | ||
| 2125 | (epg-wait-for-completion context) | ||
| 2126 | (let ((errors (epg-context-result-for context 'error))) | ||
| 2127 | (if errors | ||
| 2128 | (signal 'epg-error | ||
| 2129 | (list "Edit key failed" | ||
| 2130 | (epg-errors-to-string errors)))))) | ||
| 2131 | (epg-reset context))) | ||
| 2132 | |||
| 2087 | (defun epg--decode-percent-escape (string) | 2133 | (defun epg--decode-percent-escape (string) |
| 2088 | (let ((index 0)) | 2134 | (let ((index 0)) |
| 2089 | (while (string-match "%\\(\\(%\\)\\|\\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)" | 2135 | (while (string-match "%\\(\\(%\\)\\|\\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)" |