emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/bash-completion 58447c67bf 206/313: Merge the send functio


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 58447c67bf 206/313: Merge the send functions
Date: Sat, 3 Dec 2022 10:59:31 -0500 (EST)

branch: elpa/bash-completion
commit 58447c67bf7141da6a5678865ceda852f4fb548d
Author: montag451 <montag451@laposte.net>
Commit: montag451 <montag451@laposte.net>

    Merge the send functions
---
 bash-completion.el | 98 +++++++++++++++++++-----------------------------------
 1 file changed, 35 insertions(+), 63 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index 90d537100f..9afcfc222c 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -1321,63 +1321,58 @@ and would like bash completion in Emacs to take these 
changes into account."
       (setq bash-completion-processes (delq entry bash-completion-processes)))
     running))
 
-(defun bash-completion--wait-for-output (process output-regex timeout)
+(defun bash-completion--wait-for-prompt (process output-regexp timeout)
   (let ((no-timeout t))
     (while (and no-timeout
-                (not (re-search-backward output-regex nil t)))
+                (not (re-search-backward output-regexp nil t)))
       (setq no-timeout (accept-process-output process timeout)))
     no-timeout))
 
-(defun bash-completion--send-separate-process (commandline &optional process 
timeout)
+(defun bash-completion-send (commandline &optional process timeout)
+  "Send a command to the bash completion process.
 
-  ;; (message commandline)
-  (let ((process (or process (bash-completion-require-process)))
-       (timeout (or timeout bash-completion-process-timeout)))
-    (with-current-buffer (bash-completion--get-buffer process)
-      (erase-buffer)
-      (process-send-string process (concat commandline "\n"))
-      (while (not (progn (goto-char 1) (search-forward "\v" nil t)))
-       (unless (accept-process-output process timeout)
-         (error (concat
-                  "Timeout while waiting for an answer from "
-                  "bash-completion process.\nProcess output: <<<EOF\n%sEOF")
-                 (buffer-string))))
-      (let* ((control-v-position (point))
-            (control-t-position (progn (search-backward "\t" nil t) (point)))
-            (status-code (string-to-number
-                          (buffer-substring-no-properties
-                           (1+ control-t-position) (1- control-v-position)))))
-       (delete-region control-t-position (point-max))
-       ;; (message "status: %d content: \"%s\""
-       ;;       status-code
-       ;;       (buffer-substring-no-properties
-       ;;        (point-min) (point-max)))
-        (if (string=
-               "124"
-               (bash-completion--parse-side-channel-data "wrapped-status"))
-            124
-          status-code)))))
+COMMANDLINE should be a bash command, without the final newline.
+
+PROCESS should be the bash process, if nil this function calls
+`bash-completion-require-process' which might start a new process
+depending on the value of
+`bash-completion-use-separate-processes'.
+
+TIMEOUT is the timeout value for this operation, if nil the value of
+`bash-completion-process-timeout' is used.
+
+Once this command has run without errors, you will find the
+result of the command in the bash completion process buffer or in
+`bash-completion-output-buffer' if
+`bash-completion-use-separate-processes' is nil.
 
-(defun bash-completion--send-same-process (commandline &optional process 
timeout)
+Return the status code of the command, as a number."
   (let ((process (or process (bash-completion-require-process)))
         (timeout (or timeout bash-completion-process-timeout))
-        (prompt-regex comint-prompt-regexp)
-        (comint-preoutput-filter-functions '(bash-completion--output-filter)))
+        (prompt-regexp (if bash-completion-use-separate-processes
+                           "\t-?[[:digit:]]+\v"
+                         comint-prompt-regexp))
+        (comint-preoutput-filter-functions
+         (if bash-completion-use-separate-processes
+             comint-preoutput-filter-functions
+           '(bash-completion--output-filter))))
     (with-current-buffer (bash-completion--get-buffer process)
       (erase-buffer)
       (comint-send-string process (concat
                                    commandline
-                                   "; echo -e \"\v$?\""
-                                   "; history -d -1\n"))
-      (unless (bash-completion--wait-for-output process prompt-regex timeout)
+                                   (when (not 
bash-completion-use-separate-processes)
+                                     "; echo -e \"\v$?\"; history -d -1")
+                                   "\n"))
+      (unless (bash-completion--wait-for-prompt process prompt-regexp timeout)
         (error (concat
                 "Timeout while waiting for an answer from "
                 "bash-completion process.\nProcess output: <<<EOF\n%sEOF")
                (buffer-string)))
-      (search-backward "\v")
-      (let* ((status-code (string-to-number
-                           (buffer-substring-no-properties
-                            (1+ (point)) (line-end-position)))))
+      (when (not bash-completion-use-separate-processes)
+        (search-backward "\v"))
+      (let ((status-code (string-to-number
+                          (buffer-substring-no-properties
+                           (1+ (point)) (line-end-position)))))
         (delete-region (point) (point-max))
         (if (string=
              "124"
@@ -1385,29 +1380,6 @@ and would like bash completion in Emacs to take these 
changes into account."
             124
           status-code)))))
 
-(defun bash-completion-send (commandline &optional process timeout)
-  "Send a command to the bash completion process.
-
-COMMANDLINE should be a bash command, without the final newline.
-
-PROCESS should be the bash process, if nil this function calls
-`bash-completion-require-process' which might start a new process
-depending on the value of
-`bash-completion-use-separate-processes'.
-
-TIMEOUT is the timeout value for this operation, if nil the value of
-`bash-completion-process-timeout' is used.
-
-Once this command has run without errors, you will find the
-result of the command in the bash completion process buffer or
-`bash-completion-output-buffer' is
-`bash-completion-use-separate-processes' is nil.
-
-Return the status code of the command, as a number."
-  (if bash-completion-use-separate-processes
-      (bash-completion--send-separate-process commandline process timeout)
-    (bash-completion--send-same-process commandline process timeout)))
-
 (defun bash-completion--get-output (process)
   "Return the output of the last command sent through `bash-completion-send'."
   (with-current-buffer (bash-completion--get-buffer process) (buffer-string)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]