[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] 01/01: epg: Support key editing
From: |
Daiki Ueno |
Subject: |
[Emacs-diffs] 01/01: epg: Support key editing |
Date: |
Tue, 18 Nov 2014 07:19:58 +0000 |
branch: master
commit 9e8da9d27928ba19bf0c383a080b2fd01ad9f157
Author: Daiki Ueno <address@hidden>
Date: Tue Nov 18 16:19:14 2014 +0900
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.
---
lisp/ChangeLog | 8 +++++++
lisp/epg.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index feb9385..e885c92 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2014-11-18 Daiki Ueno <address@hidden>
+
+ * 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.
+
2014-11-18 Paul Eggert <address@hidden>
Port new time stamp handling to Emacs 23.2.
diff --git a/lisp/epg.el b/lisp/epg.el
index 20e6785..520ff8d 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -205,6 +205,7 @@
compress-algorithm
(passphrase-callback (list #'epg-passphrase-callback-function))
progress-callback
+ edit-callback
signers
sig-notations
process
@@ -668,15 +669,27 @@ callback data (if any)."
(beginning-of-line)
(while (looking-at ".*\n") ;the input line finished
(if (looking-at "\\[GNUPG:] \\([A-Z_]+\\) ?\\(.*\\)")
- (let* ((status (match-string 1))
- (string (match-string 2))
- (symbol (intern-soft (concat "epg--status-"
- status))))
+ (let ((status (match-string 1))
+ (string (match-string 2))
+ symbol)
(if (member status epg-pending-status-list)
(setq epg-pending-status-list nil))
- (if (and symbol
- (fboundp symbol))
- (funcall symbol epg-context string))
+ ;; When editing a key, delegate all interaction
+ ;; to edit-callback.
+ (if (eq (epg-context-operation epg-context) 'edit-key)
+ (funcall (car (epg-context-edit-callback
+ epg-context))
+ epg-context
+ status
+ string
+ (cdr (epg-context-edit-callback
+ epg-context)))
+ ;; Otherwise call epg--status-STATUS function.
+ (setq symbol (intern-soft (concat "epg--status-"
+ status)))
+ (if (and symbol
+ (fboundp symbol))
+ (funcall symbol epg-context string)))
(setq epg-last-status (cons status string)))
;; Record other lines sent to stderr. This assumes
;; that the process-filter receives output only from
@@ -736,7 +749,8 @@ callback data (if any)."
(if (and (epg-context-process context)
(buffer-live-p (process-buffer (epg-context-process context))))
(kill-buffer (process-buffer (epg-context-process context))))
- (setf (epg-context-process context) nil))
+ (setf (epg-context-process context) nil)
+ (setf (epg-context-edit-callback context) nil))
(defun epg-delete-output-file (context)
"Delete the output file of CONTEXT."
@@ -2084,6 +2098,38 @@ PARAMETERS is a string which tells how to create the
key."
(epg-errors-to-string errors))))))
(epg-reset context)))
+(defun epg-start-edit-key (context key edit-callback handback)
+ "Initiate an edit operation on KEY.
+
+EDIT-CALLBACK is called from process filter and takes 3
+arguments: the context, a status, an argument string, and the
+handback argument.
+
+If you use this function, you will need to wait for the completion of
+`epg-gpg-program' by using `epg-wait-for-completion' and call
+`epg-reset' to clear a temporary output file.
+If you are unsure, use synchronous version of this function
+`epg-edit-key' instead."
+ (setf (epg-context-operation context) 'edit-key)
+ (setf (epg-context-result context) nil)
+ (setf (epg-context-edit-callback context) (cons edit-callback handback))
+ (epg--start context (list "--edit-key"
+ (epg-sub-key-id
+ (car (epg-key-sub-key-list key))))))
+
+(defun epg-edit-key (context key edit-callback handback)
+ "Edit KEY in the keyring."
+ (unwind-protect
+ (progn
+ (epg-start-edit-key context key edit-callback handback)
+ (epg-wait-for-completion context)
+ (let ((errors (epg-context-result-for context 'error)))
+ (if errors
+ (signal 'epg-error
+ (list "Edit key failed"
+ (epg-errors-to-string errors))))))
+ (epg-reset context)))
+
(defun epg--decode-percent-escape (string)
(let ((index 0))
(while (string-match "%\\(\\(%\\)\\|\\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] 01/01: epg: Support key editing,
Daiki Ueno <=