comparison lisp/pgg-gpg.el @ 69775:b6e0fc8209f9

2006-04-03 Daiki Ueno <ueno@unixuser.org> * pgg-gpg.el (pgg-gpg-process-filter) (pgg-gpg-wait-for-completion): Check if buffer is alive. * pgg-gpg.el (pgg-gpg-process-sentinel): Don't remove GNUPG: lines, temporary fix.
author Simon Josefsson <jas@extundo.com>
date Mon, 03 Apr 2006 09:12:08 +0000
parents d9ccf8ac6466
children 4192bb0fddd0
comparison
equal deleted inserted replaced
69774:6fa12a3dff9c 69775:b6e0fc8209f9
105 (set-process-filter process #'pgg-gpg-process-filter) 105 (set-process-filter process #'pgg-gpg-process-filter)
106 (set-process-sentinel process #'pgg-gpg-process-sentinel) 106 (set-process-sentinel process #'pgg-gpg-process-sentinel)
107 process)) 107 process))
108 108
109 (defun pgg-gpg-process-filter (process input) 109 (defun pgg-gpg-process-filter (process input)
110 (save-excursion 110 (if (buffer-live-p (process-buffer process))
111 (if pgg-gpg-debug
112 (save-excursion
113 (set-buffer (get-buffer-create " *pgg-gpg-debug*"))
114 (goto-char (point-max))
115 (insert input)))
116 (set-buffer (process-buffer process))
117 (goto-char (point-max))
118 (insert input)
119 (goto-char pgg-gpg-read-point)
120 (beginning-of-line)
121 (while (looking-at ".*\n") ;the input line is finished
122 (save-excursion 111 (save-excursion
123 (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\)\\>.*") 112 (if pgg-gpg-debug
124 (let* ((status (match-string 1)) 113 (save-excursion
125 (symbol (intern-soft (concat "pgg-gpg-status-" status))) 114 (set-buffer (get-buffer-create " *pgg-gpg-debug*"))
126 (entry (member status pgg-gpg-pending-status-list))) 115 (goto-char (point-max))
127 (if entry 116 (insert input)))
128 (setq pgg-gpg-pending-status-list 117 (set-buffer (process-buffer process))
129 (delq (car entry) 118 (goto-char (point-max))
130 pgg-gpg-pending-status-list))) 119 (insert input)
131 (if (and symbol 120 (goto-char pgg-gpg-read-point)
132 (fboundp symbol)) 121 (beginning-of-line)
133 (funcall symbol process (buffer-substring (match-beginning 1) 122 (while (looking-at ".*\n") ;the input line is finished
134 (match-end 0))))))) 123 (save-excursion
135 (forward-line)) 124 (if (looking-at "\\[GNUPG:] \\([A-Z_]+\\)\\>.*")
136 (setq pgg-gpg-read-point (point)))) 125 (let* ((status (match-string 1))
126 (symbol (intern-soft (concat "pgg-gpg-status-" status)))
127 (entry (member status pgg-gpg-pending-status-list)))
128 (if entry
129 (setq pgg-gpg-pending-status-list
130 (delq (car entry)
131 pgg-gpg-pending-status-list)))
132 (if (and symbol
133 (fboundp symbol))
134 (funcall symbol process (buffer-substring (match-beginning 1)
135 (match-end 0)))))))
136 (forward-line))
137 (setq pgg-gpg-read-point (point)))))
137 138
138 (defun pgg-gpg-process-sentinel (process status) 139 (defun pgg-gpg-process-sentinel (process status)
139 (set-process-filter process nil) 140 (set-process-filter process nil)
140 (save-excursion 141 (save-excursion
141 ;; Copy the contents of process-buffer to pgg-errors-buffer. 142 ;; Copy the contents of process-buffer to pgg-errors-buffer.
143 (buffer-disable-undo) 144 (buffer-disable-undo)
144 (erase-buffer) 145 (erase-buffer)
145 (when (buffer-live-p (process-buffer process)) 146 (when (buffer-live-p (process-buffer process))
146 (insert-buffer-substring (process-buffer process)) 147 (insert-buffer-substring (process-buffer process))
147 (goto-char (point-min)) 148 (goto-char (point-min))
148 (delete-matching-lines "^\\[GNUPG:] ") 149 ;(delete-matching-lines "^\\[GNUPG:] ")
149 (goto-char (point-min)) 150 (goto-char (point-min))
150 (while (re-search-forward "^gpg: " nil t) 151 (while (re-search-forward "^gpg: " nil t)
151 (replace-match ""))) 152 (replace-match "")))
152 ;; Read the contents of the output file to pgg-output-buffer. 153 ;; Read the contents of the output file to pgg-output-buffer.
153 (set-buffer (get-buffer-create pgg-output-buffer)) 154 (set-buffer (get-buffer-create pgg-output-buffer))
173 174
174 (defun pgg-gpg-wait-for-completion (process &optional status-list) 175 (defun pgg-gpg-wait-for-completion (process &optional status-list)
175 (process-send-eof process) 176 (process-send-eof process)
176 (while (eq (process-status process) 'run) 177 (while (eq (process-status process) 'run)
177 (sit-for 0.1)) 178 (sit-for 0.1))
178 (save-excursion 179 (if (buffer-live-p (process-buffer process))
179 (set-buffer (process-buffer process)) 180 (save-excursion
180 (setq status-list (copy-sequence status-list)) 181 (set-buffer (process-buffer process))
181 (let ((pointer status-list)) 182 (setq status-list (copy-sequence status-list))
182 (while pointer 183 (let ((pointer status-list))
183 (goto-char (point-min)) 184 (while pointer
184 (unless (re-search-forward 185 (goto-char (point-min))
185 (concat "^\\[GNUPG:] " (car pointer) "\\>") 186 (unless (re-search-forward
186 nil t) 187 (concat "^\\[GNUPG:] " (car pointer) "\\>")
187 (setq status-list (delq (car pointer) status-list))) 188 nil t)
188 (setq pointer (cdr pointer)))) 189 (setq status-list (delq (car pointer) status-list)))
189 (kill-buffer (process-buffer process)) 190 (setq pointer (cdr pointer))))
190 status-list)) 191 (kill-buffer (process-buffer process))
192 status-list)))
191 193
192 (defun pgg-gpg-status-USERID_HINT (process line) 194 (defun pgg-gpg-status-USERID_HINT (process line)
193 (if (string-match "\\`USERID_HINT \\([^ ]+\\) \\(.*\\)" line) 195 (if (string-match "\\`USERID_HINT \\([^ ]+\\) \\(.*\\)" line)
194 (let* ((key-id (match-string 1 line)) 196 (let* ((key-id (match-string 1 line))
195 (user-id (match-string 2 line)) 197 (user-id (match-string 2 line))