]> git.eshelyaron.com Git - dict.git/commitdiff
* dict.el (dict-command): simplify
authorEshel Yaron <me@eshelyaron.com>
Sat, 13 May 2023 20:39:17 +0000 (23:39 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 13 May 2023 20:39:17 +0000 (23:39 +0300)
dict.el

diff --git a/dict.el b/dict.el
index 7c3e2bbadca3fdf4faf1208bc7f811bcd7a46a9c..d70c1f870147144ca76c1e7ae6f45bc34e3b346c 100644 (file)
--- 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."