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

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

[nongnu] elpa/bash-completion fd853663ee 304/313: Detect non-responsive


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion fd853663ee 304/313: Detect non-responsive processes more quickly.
Date: Sat, 3 Dec 2022 10:59:40 -0500 (EST)

branch: elpa/bash-completion
commit fd853663ee40c4493d58296731b3b90a8a0950e6
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>

    Detect non-responsive processes more quickly.
    
    With this change, bash-completion-send first sends a short echo command,
    just to see whether the process answers properly, so that, in the case
    where the process is not able to respond or not a bash process,
    bash-completion fails quickly.
    
    This makes issue #44 less annoying but doesn't actually solve the
    problem yet.
---
 bash-completion.el           | 31 ++++++++++++++++++++-----------
 test/bash-completion-test.el |  9 +++++----
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index 5c391b9190..cb81729914 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -179,11 +179,11 @@ explanation."
   :type '(repeat (string :tag "Argument"))
   :group 'bash-completion)
 
-(defcustom bash-completion-process-timeout 2.5
+(defcustom bash-completion-process-timeout 0.5
   "Number of seconds to wait for an answer from bash.
 
-If bash takes longer than that to answer, the answer will be
-ignored."
+This doesn't include the time it takes to execute an actual
+completion command, which is set by `bash-completion-command-timeout'."
   :type '(float)
   :group 'bash-completion)
 
@@ -1506,8 +1506,10 @@ Return the status code of the command, as a number."
          (send-string (if bash-completion-use-separate-processes
                           #'process-send-string
                         #'comint-send-string))
-         (pre-command (unless bash-completion-use-separate-processes
-                        "__emacs_complete_pre_command; "))
+         (pre-command (concat
+                       "echo bash\\-completion:; "
+                       (unless bash-completion-use-separate-processes
+                         "__emacs_complete_pre_command; ")))
          (complete-command (concat pre-command commandline "\n")))
     (setq bash-completion--debug-info
           (list (cons 'commandline complete-command)
@@ -1517,17 +1519,24 @@ Return the status code of the command, as a number."
     (with-current-buffer (bash-completion--get-buffer process)
       (erase-buffer)
       (funcall send-string process complete-command)
+      ;; Wait for 'echo bash\-completion' to be executed within
+      ;; bash-completion-process-timeout. This takes care of any
+      ;; command-line echo as well.
+      (unless (bash-completion--wait-for-regexp process "bash-completion:" 
bash-completion-process-timeout)
+        (push (cons 'error "non-bash") bash-completion--debug-info)
+        (push (cons 'buffer-string (buffer-substring-no-properties (point-min) 
(point-max)))
+              bash-completion--debug-info)
+        (error "Bash completion failed; not a bash process."))
+      (delete-region (point-min) (1+ (match-end 0)))
+      (goto-char (point-max))
+      ;; Now wait for the real to be executed within timeout. This can
+      ;; take a while for some completion commands.
       (unless (bash-completion--wait-for-regexp process "\t-?[[:digit:]]+\v" 
timeout)
+
         (push (cons 'error "timeout") bash-completion--debug-info)
         (push (cons 'buffer-string (buffer-substring-no-properties (point-min) 
(point-max)))
               bash-completion--debug-info)
         (error "Bash completion failed. M-x bash-completion-debug for 
details."))
-      (when pre-command
-        ;; Detect the command having been echoed and remove it
-        (save-excursion
-          (goto-char (point-min))
-          (when (looking-at pre-command)
-            (delete-region (match-beginning 0) (line-beginning-position 2)))))
       (let ((status (string-to-number
                           (buffer-substring-no-properties
                            (1+ (point))
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index bbe7cd56f6..061eef7ca8 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -519,15 +519,16 @@ Return (const return-value new-buffer-content)"
                (lambda (process command)
                  (unless (eq process 'process)
                    (error "unexpected process: %s" process))
-                 (unless (equal "cmd\n" command)
+                 (unless (equal command "echo bash\\-completion:; cmd\n")
                    (error "unexpected command: %s" command))))
               ((symbol-function 'accept-process-output)
                (lambda (process timeout &optional millisec just-this-one)
                  (unless (eq process 'process)
                    (error "unexpected process: %s" process))
-                 (unless (= timeout 3.14)
-                   (error "unexpected timeout: %s" timeout))
-                 (insert buffer-content)
+                 (cond ((= timeout 3.14) (insert buffer-content))
+                       ((= timeout bash-completion-process-timeout)
+                        (insert "bash-completion:\n"))
+                       (t (error "unexpected timeout: %s" timeout)))
                  t)))
       (bash-completion-test-with-buffer
        ""



reply via email to

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