From ccade56fbee75dfebc6e1826738550a1c131d933 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Sat, 11 Apr 2015 16:31:59 +0900 Subject: [PATCH] Utilize `make-process' in epg.el * lisp/epg.el (epg-error-output): Abolish. (epg-context): New slot `error-buffer'. (epg--start): Use `make-process' and `make-pipe-process'. (epg--process-filter): Remove code separating stderr from stdout. (epg-wait-for-completion): Simplify `error-output' handling. (epg-reset): Dispose error buffer. --- lisp/epg.el | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/lisp/epg.el b/lisp/epg.el index 1b75b50df0e..601504882e6 100644 --- a/lisp/epg.el +++ b/lisp/epg.el @@ -40,7 +40,6 @@ (defvar epg-debug-buffer nil) (defvar epg-agent-file nil) (defvar epg-agent-mtime nil) -(defvar epg-error-output nil) ;; from gnupg/include/cipher.h (defconst epg-cipher-algorithm-alist @@ -213,7 +212,8 @@ result operation pinentry-mode - (error-output "")) + (error-output "") + error-buffer) ;; This is not an alias, just so we can mark it as autoloaded. ;;;###autoload @@ -581,11 +581,9 @@ callback data (if any)." (symbol-name (epg-context-pinentry-mode context)))) args)) - (coding-system-for-write 'binary) - (coding-system-for-read 'binary) - process-connection-type (process-environment process-environment) (buffer (generate-new-buffer " *epg*")) + error-process process terminal-name agent-file @@ -642,13 +640,24 @@ callback data (if any)." (make-local-variable 'epg-agent-file) (setq epg-agent-file agent-file) (make-local-variable 'epg-agent-mtime) - (setq epg-agent-mtime agent-mtime) - (make-local-variable 'epg-error-output) - (setq epg-error-output nil)) + (setq epg-agent-mtime agent-mtime)) + (setq error-process + (make-pipe-process :name "epg-error" + :buffer (generate-new-buffer " *epg-error*") + ;; Suppress "XXX finished" line. + :sentinel #'ignore + :noquery t)) + (setf (epg-context-error-buffer context) (process-buffer error-process)) (with-file-modes 448 - (setq process (apply #'start-process "epg" buffer - (epg-context-program context) args))) - (set-process-filter process #'epg--process-filter) + (setq process (make-process :name "epg" + :buffer buffer + :command (cons (epg-context-program context) + args) + :connection-type 'pipe + :coding '(binary . binary) + :filter #'epg--process-filter + :stderr error-process + :noquery t))) (setf (epg-context-process context) process))) (defun epg--process-filter (process input) @@ -690,14 +699,7 @@ callback data (if any)." (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 - ;; stderr and the FD specified with --status-fd. - (setq epg-error-output - (cons (buffer-substring (point) - (line-end-position)) - epg-error-output))) + (setq epg-last-status (cons status string)))) (forward-line) (setq epg-read-point (point))))))))) @@ -740,15 +742,17 @@ callback data (if any)." (epg-context-set-result-for context 'error (nreverse (epg-context-result-for context 'error))) - (with-current-buffer (process-buffer (epg-context-process context)) - (setf (epg-context-error-output context) - (mapconcat #'identity (nreverse epg-error-output) "\n")))) + (setf (epg-context-error-output context) + (with-current-buffer (epg-context-error-buffer context) + (buffer-string)))) (defun epg-reset (context) "Reset the CONTEXT." (if (and (epg-context-process context) (buffer-live-p (process-buffer (epg-context-process context)))) (kill-buffer (process-buffer (epg-context-process context)))) + (if (buffer-live-p (epg-context-error-buffer context)) + (kill-buffer (epg-context-error-buffer context))) (setf (epg-context-process context) nil) (setf (epg-context-edit-callback context) nil)) -- 2.39.2