diff options
| author | Daiki Ueno | 2015-04-11 16:31:59 +0900 |
|---|---|---|
| committer | Daiki Ueno | 2015-04-12 07:00:41 +0900 |
| commit | ccade56fbee75dfebc6e1826738550a1c131d933 (patch) | |
| tree | b7d155b996c1088519aeeeb21689d57ffb3df1df | |
| parent | 24ecbc008f13c9fb18eac6e1895ea83bb70c4139 (diff) | |
| download | emacs-ccade56fbee75dfebc6e1826738550a1c131d933.tar.gz emacs-ccade56fbee75dfebc6e1826738550a1c131d933.zip | |
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.
| -rw-r--r-- | lisp/epg.el | 48 |
1 files 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 @@ | |||
| 40 | (defvar epg-debug-buffer nil) | 40 | (defvar epg-debug-buffer nil) |
| 41 | (defvar epg-agent-file nil) | 41 | (defvar epg-agent-file nil) |
| 42 | (defvar epg-agent-mtime nil) | 42 | (defvar epg-agent-mtime nil) |
| 43 | (defvar epg-error-output nil) | ||
| 44 | 43 | ||
| 45 | ;; from gnupg/include/cipher.h | 44 | ;; from gnupg/include/cipher.h |
| 46 | (defconst epg-cipher-algorithm-alist | 45 | (defconst epg-cipher-algorithm-alist |
| @@ -213,7 +212,8 @@ | |||
| 213 | result | 212 | result |
| 214 | operation | 213 | operation |
| 215 | pinentry-mode | 214 | pinentry-mode |
| 216 | (error-output "")) | 215 | (error-output "") |
| 216 | error-buffer) | ||
| 217 | 217 | ||
| 218 | ;; This is not an alias, just so we can mark it as autoloaded. | 218 | ;; This is not an alias, just so we can mark it as autoloaded. |
| 219 | ;;;###autoload | 219 | ;;;###autoload |
| @@ -581,11 +581,9 @@ callback data (if any)." | |||
| 581 | (symbol-name (epg-context-pinentry-mode | 581 | (symbol-name (epg-context-pinentry-mode |
| 582 | context)))) | 582 | context)))) |
| 583 | args)) | 583 | args)) |
| 584 | (coding-system-for-write 'binary) | ||
| 585 | (coding-system-for-read 'binary) | ||
| 586 | process-connection-type | ||
| 587 | (process-environment process-environment) | 584 | (process-environment process-environment) |
| 588 | (buffer (generate-new-buffer " *epg*")) | 585 | (buffer (generate-new-buffer " *epg*")) |
| 586 | error-process | ||
| 589 | process | 587 | process |
| 590 | terminal-name | 588 | terminal-name |
| 591 | agent-file | 589 | agent-file |
| @@ -642,13 +640,24 @@ callback data (if any)." | |||
| 642 | (make-local-variable 'epg-agent-file) | 640 | (make-local-variable 'epg-agent-file) |
| 643 | (setq epg-agent-file agent-file) | 641 | (setq epg-agent-file agent-file) |
| 644 | (make-local-variable 'epg-agent-mtime) | 642 | (make-local-variable 'epg-agent-mtime) |
| 645 | (setq epg-agent-mtime agent-mtime) | 643 | (setq epg-agent-mtime agent-mtime)) |
| 646 | (make-local-variable 'epg-error-output) | 644 | (setq error-process |
| 647 | (setq epg-error-output nil)) | 645 | (make-pipe-process :name "epg-error" |
| 646 | :buffer (generate-new-buffer " *epg-error*") | ||
| 647 | ;; Suppress "XXX finished" line. | ||
| 648 | :sentinel #'ignore | ||
| 649 | :noquery t)) | ||
| 650 | (setf (epg-context-error-buffer context) (process-buffer error-process)) | ||
| 648 | (with-file-modes 448 | 651 | (with-file-modes 448 |
| 649 | (setq process (apply #'start-process "epg" buffer | 652 | (setq process (make-process :name "epg" |
| 650 | (epg-context-program context) args))) | 653 | :buffer buffer |
| 651 | (set-process-filter process #'epg--process-filter) | 654 | :command (cons (epg-context-program context) |
| 655 | args) | ||
| 656 | :connection-type 'pipe | ||
| 657 | :coding '(binary . binary) | ||
| 658 | :filter #'epg--process-filter | ||
| 659 | :stderr error-process | ||
| 660 | :noquery t))) | ||
| 652 | (setf (epg-context-process context) process))) | 661 | (setf (epg-context-process context) process))) |
| 653 | 662 | ||
| 654 | (defun epg--process-filter (process input) | 663 | (defun epg--process-filter (process input) |
| @@ -690,14 +699,7 @@ callback data (if any)." | |||
| 690 | (if (and symbol | 699 | (if (and symbol |
| 691 | (fboundp symbol)) | 700 | (fboundp symbol)) |
| 692 | (funcall symbol epg-context string))) | 701 | (funcall symbol epg-context string))) |
| 693 | (setq epg-last-status (cons status string))) | 702 | (setq epg-last-status (cons status string)))) |
| 694 | ;; Record other lines sent to stderr. This assumes | ||
| 695 | ;; that the process-filter receives output only from | ||
| 696 | ;; stderr and the FD specified with --status-fd. | ||
| 697 | (setq epg-error-output | ||
| 698 | (cons (buffer-substring (point) | ||
| 699 | (line-end-position)) | ||
| 700 | epg-error-output))) | ||
| 701 | (forward-line) | 703 | (forward-line) |
| 702 | (setq epg-read-point (point))))))))) | 704 | (setq epg-read-point (point))))))))) |
| 703 | 705 | ||
| @@ -740,15 +742,17 @@ callback data (if any)." | |||
| 740 | (epg-context-set-result-for | 742 | (epg-context-set-result-for |
| 741 | context 'error | 743 | context 'error |
| 742 | (nreverse (epg-context-result-for context 'error))) | 744 | (nreverse (epg-context-result-for context 'error))) |
| 743 | (with-current-buffer (process-buffer (epg-context-process context)) | 745 | (setf (epg-context-error-output context) |
| 744 | (setf (epg-context-error-output context) | 746 | (with-current-buffer (epg-context-error-buffer context) |
| 745 | (mapconcat #'identity (nreverse epg-error-output) "\n")))) | 747 | (buffer-string)))) |
| 746 | 748 | ||
| 747 | (defun epg-reset (context) | 749 | (defun epg-reset (context) |
| 748 | "Reset the CONTEXT." | 750 | "Reset the CONTEXT." |
| 749 | (if (and (epg-context-process context) | 751 | (if (and (epg-context-process context) |
| 750 | (buffer-live-p (process-buffer (epg-context-process context)))) | 752 | (buffer-live-p (process-buffer (epg-context-process context)))) |
| 751 | (kill-buffer (process-buffer (epg-context-process context)))) | 753 | (kill-buffer (process-buffer (epg-context-process context)))) |
| 754 | (if (buffer-live-p (epg-context-error-buffer context)) | ||
| 755 | (kill-buffer (epg-context-error-buffer context))) | ||
| 752 | (setf (epg-context-process context) nil) | 756 | (setf (epg-context-process context) nil) |
| 753 | (setf (epg-context-edit-callback context) nil)) | 757 | (setf (epg-context-edit-callback context) nil)) |
| 754 | 758 | ||