Return the result of calling the function PARSE in a the
beginning of a buffer with the server's response."
- (let ((buffer (get-buffer-create dict-process-buffer-name)))
- (with-current-buffer buffer
- (delete-region (point-min) (point-max)))
- (let* ((result nil)
- (done nil)
- (filter
- (lambda (process string)
- (internal-default-process-filter process string)
- (with-current-buffer (process-buffer process)
- (save-excursion
- (goto-char (point-min))
- (cond
- ((or (looking-at "^5")
- (search-forward "\r\n5" nil t))
- ;; server replied with an error code
- (setq done t))
- ((search-forward "\r\n.\r\n" nil t)
- (goto-char (point-min))
- (setq result (funcall parse)
- done t)))))))
- (proc (if (process-live-p dict-process)
- dict-process
- (setq dict-process
- (make-network-process
- :name dict-process-name
- :host (dict-server-host)
- :service dict-server-port
- :buffer buffer)))))
- (set-process-filter proc filter)
+ (with-current-buffer (get-buffer-create dict-process-buffer-name)
+ (delete-region (point-min) (point-max))
+ (let ((proc (if (process-live-p dict-process)
+ dict-process
+ (setq dict-process
+ (make-network-process
+ :name dict-process-name
+ :host (dict-server-host)
+ :service dict-server-port
+ :buffer (current-buffer))))))
(process-send-string proc (concat command "\n"))
- (while (not done)
- (accept-process-output proc 1))
- result)))
+ (named-let loop ()
+ (accept-process-output proc 1)
+ (goto-char (point-min))
+ (unless (or (looking-at "^5")
+ (search-forward "\r\n5" nil t))
+ (if (and (search-forward "\r\n.\r\n" nil t)
+ (goto-char (point-min)))
+ (funcall parse)
+ (loop)))))))
(defun dict-match-word (word)
"Return dictionary matches for WORD as a list of strings."