]> git.eshelyaron.com Git - emacs.git/commitdiff
Utilize `make-process' in epg.el
authorDaiki Ueno <ueno@gnu.org>
Sat, 11 Apr 2015 07:31:59 +0000 (16:31 +0900)
committerDaiki Ueno <ueno@gnu.org>
Sat, 11 Apr 2015 22:00:41 +0000 (07:00 +0900)
* 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

index 1b75b50df0ebba72786ad6e1059de2fc03037377..601504882e60a94ffbcdda37b378666f10c0b3de 100644 (file)
@@ -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
   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))