[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 0a757bd5f4 238/313: Test calling completio
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 0a757bd5f4 238/313: Test calling completion from non-comint and non-bash shell buffers. |
Date: |
Sat, 3 Dec 2022 10:59:34 -0500 (EST) |
branch: elpa/bash-completion
commit 0a757bd5f4bbcf9bfd31660e66fb19dcff164bba
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Test calling completion from non-comint and non-bash shell buffers.
Also avoid using the single-process solution for non-bash shell
buffers.
---
README.md | 4 +-
bash-completion.el | 26 ++++++++----
test/bash-completion-integration-test.el | 69 ++++++++++++++++++++++++--------
3 files changed, 71 insertions(+), 28 deletions(-)
diff --git a/README.md b/README.md
index ed89d2eae5..bef0c428b4 100644
--- a/README.md
+++ b/README.md
@@ -24,9 +24,7 @@ running in term mode. Also, term mode is not available in
shell-command prompts.
Bash completion can also be run programatically, outside of a
-shell-mode command, by setting
-`bash-completion-use-separate-processes` to a non-nil value (which is
-the default) and by calling
+shell-mode command by calling
`bash-completion-dynamic-complete-nocomint`.
## INSTALLATION
diff --git a/bash-completion.el b/bash-completion.el
index cf12f08552..4915379a5a 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -181,7 +181,8 @@ perform completion. If nil, the process associated with the
current buffer is used to perform completion. Even when this
variable is set to nil, a separate process can be used to perform
completion when:
-- no process is associated with the current buffer
+- the current buffer is not a comint buffer
+- no bash process is associated with the current buffer
- an error occurred while trying to get completions"
:type 'boolean
:group 'bash-completion)
@@ -520,7 +521,7 @@ When doing completion outside of a comint buffer, call
;;;###autoload
(defun bash-completion-dynamic-complete-nocomint
- (comp-start comp-pos &optional dynamic-table)
+ (&optional comp-start comp-pos dynamic-table)
"Return completion information for bash command at an arbitrary position.
The bash command to be completed begins at COMP-START in the
@@ -537,7 +538,9 @@ Returns (list stub-start stub-end completions) with
or a function, if DYNAMIC-TABLE is non-nil, a lambda such as the one
returned by `completion-table-dynamic'"
(when bash-completion-enabled
- (let ((bash-completion-use-separate-processes
+ (let ((comp-start (or comp-start (line-beginning-position)))
+ (comp-pos (or comp-pos (point)))
+ (bash-completion-use-separate-processes
bash-completion-use-separate-processes)
(process (bash-completion-get-process)))
(when (and (not process) (not bash-completion-use-separate-processes))
@@ -1170,12 +1173,19 @@ is set to t."
(error nil)))))))))
(defun bash-completion--get-same-process ()
- "Setup the process associated with the current buffer and return it."
+ "Return the BASH process associated with the current buffer.
+
+Return nil if the current buffer is not a comint buffer or is not
+associated with a command that looks like a bash shell.
+Completion will fallback to creating a separate process
+completion in these cases."
(when (derived-mode-p 'comint-mode)
- (let ((process (get-buffer-process (current-buffer))))
- (unless (or (not process) (process-get process 'setup-done))
- (bash-completion--setup-bash-common process))
- process)))
+ (let* ((process (get-buffer-process (current-buffer)))
+ (command (when process (file-name-nondirectory (car
(process-command process))))))
+ (when (and command (bash-completion-starts-with command "bash"))
+ (unless (process-get process 'setup-done)
+ (bash-completion--setup-bash-common process))
+ process))))
(defun bash-completion-get-process ()
"Setup and return a bash completion process.
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index d71ad721d3..9186082c92 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -73,22 +73,25 @@
`(bash-completion_test-harness
,bashrc
,use-separate-process
- (let ((shell-buffer))
- (unwind-protect
- (progn
- (setq shell-buffer (shell (generate-new-buffer-name
- "*bash-completion_test-with-shell*")))
- (bash-completion--wait-for-prompt (get-buffer-process shell-buffer)
-
(bash-completion--get-prompt-regexp)
- 3.0)
- (with-current-buffer shell-buffer
- (let ((comint-dynamic-complete-functions
'(bash-completion-dynamic-complete)))
- (progn ,@body))))
- (when shell-buffer
- (when (and (buffer-live-p shell-buffer)
- (get-buffer-process shell-buffer))
- (kill-process (get-buffer-process shell-buffer)))
- (kill-buffer shell-buffer))))))
+ (bash-completion_test-with-shell ,@body)))
+
+(defmacro bash-completion_test-with-shell (&rest body)
+ `(let ((shell-buffer))
+ (unwind-protect
+ (progn
+ (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)
+ (let ((comint-dynamic-complete-functions
'(bash-completion-dynamic-complete)))
+ (progn ,@body))))
+ (when shell-buffer
+ (when (and (buffer-live-p shell-buffer)
+ (get-buffer-process shell-buffer))
+ (kill-process (get-buffer-process shell-buffer)))
+ (kill-buffer shell-buffer)))))
(defun bash-completion_test-bash-major-version ()
"Return the major version of the bash process."
@@ -96,7 +99,7 @@
(defun bash-completion_test-complete (complete-me)
(goto-char (point-max))
- (comint-delete-input)
+ (delete-region (line-beginning-position) (line-end-position))
(insert complete-me)
(completion-at-point)
(buffer-substring-no-properties
@@ -172,6 +175,38 @@ for testing completion."
(bash-completion_test-complete
"export SOMEPATH=some/directory:some/oth")))))
+(ert-deftest bash-completion-integration-nocomint-test ()
+ (bash-completion_test-harness
+ "function somefunction { echo ok; }\n"
+ nil ; use-separate-process=nil will be ignored
+ (with-temp-buffer
+ (let ((completion-at-point-functions
'(bash-completion-dynamic-complete-nocomint)))
+ ;; complete bash builtin
+ (should (equal "readonly "
+ (bash-completion_test-complete "reado")))
+ ;; complete command
+ (should (equal "somefunction "
+ (bash-completion_test-complete "somef")))))))
+
+(ert-deftest bash-completion-integration-notbash-test ()
+ (bash-completion_test-harness
+ "function somefunction { echo ok; }\n"
+ ; use-separate-process=nil will be ignored because the shell is not
+ ; a bash shell.
+ nil
+ (let ((explicit-shell-file-name "/bin/sh"))
+ (bash-completion_test-with-shell
+ ;; complete bash builtin
+ (should (equal "readonly "
+ (bash-completion_test-complete "reado")))
+ ;; complete command
+ (should (equal "somefunction "
+ (bash-completion_test-complete "somef")))
+
+ ;; make sure a separate process was used; in case /bin/sh is
+ ;; actually bash, the test could otherwise work just fine.
+ (should (not (null (cdr (assq nil bash-completion-processes)))))))))
+
(ert-deftest bash-completion-integration-bash-4-default-completion ()
(bash-completion_test-with-shell-harness
(concat ; .bashrc
- [nongnu] elpa/bash-completion cc9a3dcab4 204/313: Stop cluttering the Bash history, (continued)
- [nongnu] elpa/bash-completion cc9a3dcab4 204/313: Stop cluttering the Bash history, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0a6fa499ad 207/313: Fix one parameter name of bash-completion--wait-for-prompt, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3bd30eea3f 208/313: Use the correct function to send string to completion process, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion fd2f8e277e 211/313: Improve prompt detection, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ac3bd404e8 220/313: Fix typos (#40), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f31bb46ff4 222/313: Making sure that line editing is turned off (#42), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3210a44081 224/313: Makefile allows specifying the path to bash., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2178030cdf 225/313: Allow running unit and integration tests separately., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c564aff656 229/313: Add workflow for testing on MacOS with BASH 3., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ba8be293a4 226/313: Added test workflow to run tests on multiple versions of Emacs., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0a757bd5f4 238/313: Test calling completion from non-comint and non-bash shell buffers.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion c99083233f 241/313: Fix shell-type detection logic for remote processes., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4a1d89f01e 246/313: Support -o vi and emacs even in single-process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion aec357fbf1 249/313: Test default completion with both value of use-separate-process., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 38c82e5d59 252/313: Conserve quotes even when expanding case-insensitively., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6a66eeda45 253/313: Add test-case to cover tilde and tilde expansion., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b9e519e2ad 263/313: Fix typo, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2684ea9e46 264/313: Fix issue with case-insensitive completion., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6d74dd30ba 266/313: Avoid interference from PROMPT_COMMAND in single process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 23a3402844 270/313: Trying to disable the warning on MacOS that breaks the tests., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1598101f06 271/313: Remove the fallback to a separate process., ELPA Syncer, 2022/12/03