branch: elpa/bash-completion
commit a0a5816ce444308d83ec2f69190691b674acf7bb
Author: Stephane Zermatten <[email protected]>
Commit: Stephane Zermatten <[email protected]>
Attempt to make in-process execution more robust.
When use-separate-processes is nil, this change waits for a special
string, added by bash-completion-send, instead of the prompt regexp.
This should be more robust, as prompts can change and the prompt
regexp might easily match output.
This change also removes uses of comint-last-prompt. This was an
attempt at making the prompt search more reliable, but won't work if
the prompt changes, such as a prompt that includes the history line
count.
---
bash-completion.el | 50 ++++++++++++++++----------------
test/bash-completion-integration-test.el | 5 ++--
2 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 56a6126572..cf6ede1a37 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -1418,25 +1418,13 @@ and would like bash completion in Emacs to take these
changes into account."
(ansi-color-filter-region begin (point))
"")))
-(defun bash-completion--wait-for-prompt (process prompt-regexp timeout)
+(defun bash-completion--wait-for-regexp (process prompt-regexp timeout
&optional limit)
(let ((no-timeout t))
(while (and no-timeout
- (not (re-search-backward prompt-regexp nil t)))
+ (not (re-search-backward prompt-regexp limit t)))
(setq no-timeout (accept-process-output process timeout nil t)))
no-timeout))
-(when (< emacs-major-version 26)
- ;; comint-last-prompt was not available prior to Emacs 26.1, so we
- ;; always fallback to comint-prompt-regexp.
- (defvar comint-last-prompt nil))
-
-(defun bash-completion--get-prompt-regexp ()
- (if comint-last-prompt
- (let ((start (car comint-last-prompt))
- (end (cdr comint-last-prompt)))
- (regexp-quote (buffer-substring-no-properties start end)))
- comint-prompt-regexp))
-
(defun bash-completion-send (commandline &optional process timeout)
"Send a command to the bash completion process.
@@ -1458,9 +1446,7 @@ result of the command in the bash completion process
buffer or in
Return the status code of the command, as a number."
(let ((process (or process (bash-completion--get-process)))
(timeout (or timeout bash-completion-process-timeout))
- (prompt-regexp (if bash-completion-use-separate-processes
- "\t-?[[:digit:]]+\v"
- (bash-completion--get-prompt-regexp)))
+ (prompt-regexp comint-prompt-regexp)
(comint-preoutput-filter-functions
(if bash-completion-use-separate-processes
comint-preoutput-filter-functions
@@ -1474,15 +1460,29 @@ Return the status code of the command, as a number."
(concat
commandline
(unless bash-completion-use-separate-processes
- "; echo -e \"\v$?\"; history -d $((HISTCMD - 1))")
+ "; echo \"--\v$?\"; history -d $((HISTCMD - 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)))
- (unless bash-completion-use-separate-processes
- (search-backward "\v"))
+ (if bash-completion-use-separate-processes
+ (unless (bash-completion--wait-for-regexp process
"\t-?[[:digit:]]+\v" timeout)
+ (error (concat
+ "Timeout while waiting for an answer from "
+ "bash-completion process with regexp %s.\nProcess output:
<<<EOF\n%sEOF")
+ prompt-regexp
+ (buffer-string)))
+ (unless (bash-completion--wait-for-regexp process "--\v" timeout)
+ (error (concat
+ "Timeout while waiting for process status\n"
+ "Process output: <<<EOF\n%sEOF")
+ (buffer-string)))
+ (let ((search-limit (point)))
+ (goto-char (point-max))
+ (unless (bash-completion--wait-for-regexp process prompt-regexp
timeout search-limit)
+ (error (concat
+ "Timeout while waiting for an answer from "
+ "bash-completion process with regexp %s.\nProcess output:
<<<EOF\n%sEOF")
+ prompt-regexp
+ (buffer-string)))
+ (goto-char search-limit)))
(let ((status-code (string-to-number
(buffer-substring-no-properties
(1+ (point))
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index 5871a751bd..8976ce0d04 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -84,9 +84,8 @@
(setq shell-buffer (shell (generate-new-buffer-name
"*bash-completion_test-with-shell*")))
(with-current-buffer shell-buffer
- (bash-completion--wait-for-prompt (get-buffer-process
shell-buffer)
-
(bash-completion--get-prompt-regexp)
- 3.0)
+ (bash-completion--wait-for-regexp
+ (get-buffer-process shell-buffer) comint-prompt-regexp 3.0)
(let ((comint-dynamic-complete-functions
'(bash-completion-dynamic-complete))
(completion-at-point-functions '(comint-completion-at-point
t)))
(progn ,@body))))