From: Eshel Yaron Date: Sat, 13 May 2023 20:39:17 +0000 (+0300) Subject: * dict.el (dict-command): simplify X-Git-Tag: v0.1.6~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=666c0a7fa17f768b67b0bed812a0353bde3dce38;p=dict.git * dict.el (dict-command): simplify --- diff --git a/dict.el b/dict.el index 7c3e2bb..d70c1f8 100644 --- a/dict.el +++ b/dict.el @@ -105,39 +105,26 @@ COMMAND is an RFC2229 command in string format, without a newline. 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."