[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion ca4fbce016 305/313: Turn off bash completi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion ca4fbce016 305/313: Turn off bash completion when non-bash prompts are detected. |
Date: |
Sat, 3 Dec 2022 10:59:40 -0500 (EST) |
branch: elpa/bash-completion
commit ca4fbce016f51150d84f50a459f720d0c8ac7ed3
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Turn off bash completion when non-bash prompts are detected.
In single-process mode, the comint version of
bash-completion-dynamic-complete automatically turns off bash completion
when it thinks it's not talking to a BASH command-line.
This is controlled by bash-completion-nonbash-prompts and
bash-completion-bash-prompts.
This is a way of avoiding issue #44.
---
bash-completion.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 51 insertions(+), 7 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index cb81729914..4b888e658f 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -234,6 +234,30 @@ to remove the extra space bash adds after a completion."
:type '(boolean)
:group 'bash-completion)
+(defcustom bash-completion-bash-prompts nil
+ "Regexps that match BASH prompts (PS1).
+
+If a prompt matches one of the regular expression on this list,
+it'll be considered a bash prompt even if it matches one of the
+regular expressions in `bash-completion-nonbash-prompts'.
+
+See `bash-completion-nonbash-prompts' for more details."
+ :type '(repeat string)
+ :group 'bash-completion)
+
+(defcustom bash-completion-nonbash-prompts '("[>+] +$")
+ "Regexps that match non-BASH prompts and BASH PS2 prompts.
+
+If a prompt matches one of the regular expressions on this list,
+`bash-completion-dynamic-complete' doesn't attempt to communicate
+with the current BASH process to do completion.
+
+If your BASH prompt matches one of the regexps on this list, you
+might want to put a regexp for it in
+`bash-completion-bash-prompts'."
+ :type '(repeat string)
+ :group 'bash-completion)
+
(defvar bash-completion-start-files
'("~/.emacs_bash.sh" "~/.emacs.d/init_bash.sh")
"Shell files that, if they exist, will be sourced at the beginning of a bash
completion subprocess.
@@ -480,13 +504,27 @@ When doing completion outside of a comint buffer, call
(if (and (not (window-minibuffer-p))
(not (null bash-completion-message-delay)))
(run-at-time
- bash-completion-message-delay nil
- (lambda () (message "Bash completion..."))))))
+ bash-completion-message-delay nil
+ (lambda () (message "Bash completion..."))))))
(unwind-protect
- (bash-completion-dynamic-complete-nocomint
- (comint-line-beginning-position)
- (point)
- 'dynamic-table)
+ (let ((prompt-end (comint-line-beginning-position)))
+ (if (or bash-completion-use-separate-processes
+ (let* ((prompt-start (save-excursion
+ (goto-char prompt-end)
+ (line-end-position -1)))
+ (prompt (buffer-substring-no-properties
+ prompt-start prompt-end)))
+ (or
+ (bash-completion--match-any
+ prompt bash-completion-bash-prompts)
+ (not (bash-completion--match-any
+ prompt bash-completion-nonbash-prompts)))))
+ (bash-completion-dynamic-complete-nocomint
+ prompt-end (point) 'dynamic-table)
+
+ (error (concat "Bash completion not available. "
+ "Call M-x customize-option
bash-completion-nonbash-prompts "
+ "if this is incorrect."))))
;; cleanup
(if message-timer
(cancel-timer message-timer)))))
@@ -1526,7 +1564,7 @@ Return the status code of the command, as a number."
(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."))
+ (error "Not a bash process. Fix using M-x customize-option
bash-completion-nonbash-prompts"))
(delete-region (point-min) (1+ (match-end 0)))
(goto-char (point-max))
;; Now wait for the real to be executed within timeout. This can
@@ -1679,6 +1717,12 @@ Return the parsed value, as a string or nil."
(prog1 (match-string 1)
(delete-region (match-beginning 0) (match-end 0)))))))
+(defun bash-completion--match-any (text regexp-list)
+ (catch 'bash-completion-return
+ (dolist (regexp regexp-list)
+ (when (string-match-p regexp text)
+ (throw 'bash-completion-return t)))))
+
(defun bash-completion--completion-table-with-cache (comp process)
"Build a dynamic completion table for COMP using PROCESS.
- [nongnu] elpa/bash-completion c6decb1d6c 285/313: Avoid escaping all non-ASCII characters., (continued)
- [nongnu] elpa/bash-completion c6decb1d6c 285/313: Avoid escaping all non-ASCII characters., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4c216c4eea 286/313: Add an integration test to cover multiple completion results., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8f877dc2ce 287/313: Let bash compute COMP_POINT, always at the end of COMP_LINE., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 377969faa7 288/313: Fix typos in README.md, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 72e9fce93d 291/313: Properly apply filter passed to the dynamic completion function., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 35d38fd3dc 295/313: Workaround for output containing \r\n instead of \n., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 666244383e 296/313: Workaround for command-line being echoed., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion abb72c36b8 297/313: Merge branch 'master' of github.com:szermatt/emacs-bash-completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e35943f37e 299/313: Fix backward-compatibility issue on 24.3: avoid using alist-get., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion abbe3bc268 301/313: Cleanup implementation of bash-completion-debug., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ca4fbce016 305/313: Turn off bash completion when non-bash prompts are detected.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion abe93ae2f6 308/313: Fix whitespace (#47), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion df635e79fd 310/313: Replace deprecated `cl` package with `cl-lib` (#50), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8e9c20dbfe 313/313: Replace or quote certain single quotes in docstrings (#55), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion aa9bea48ba 022/313: fix position, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6aedd69000 164/313: Delete duplicates when extracting candidates. fixes #26, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 58447c67bf 206/313: Merge the send functions, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion d6c28d3132 302/313: Add a troubleshooting section to README.md, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion d550256e3f 306/313: Disable flakey test for now., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a8f7de1e91 173/313: Merge remote-tracking branch 'montag451/remote-shell-support-rebase', ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9521f79b33 176/313: Display the emacs command run by the tests., ELPA Syncer, 2022/12/03