[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 685ed73df0 243/313: Allow completion to re
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 685ed73df0 243/313: Allow completion to replace the word being completed. |
Date: |
Sat, 3 Dec 2022 10:59:34 -0500 (EST) |
branch: elpa/bash-completion
commit 685ed73df0ea73f94691bf8c31e0fed3c98ac7a6
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Allow completion to replace the word being completed.
With this change, when bash-completion cannot find a link between the
word being completed and the completion result, it'll return the
completion result as a whole. This behavior is more consistent with
what bash does and accept more complex completion logic.
---
bash-completion.el | 61 +++++++++++++++++---------------
test/bash-completion-integration-test.el | 28 +++++++++++++--
test/bash-completion-test.el | 10 +++---
3 files changed, 64 insertions(+), 35 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 44ce408e9a..56a6126572 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -949,6 +949,7 @@ for directory name detection to work."
(wordbreaks (bash-completion--wordbreaks comp))
(suffix "")
(rest) ; the part between the prefix and the suffix
+ (whole)
(rebuilt))
;; build rest by removing parsed-prefix from str
@@ -976,34 +977,38 @@ for directory name detection to work."
parsed-prefix)
(setq rest (substring rebuilt (length parsed-prefix))))
- ;; there is no meaningful link between the prefix and
- ;; the string. just append the string to the prefix and
- ;; hope for the best.
- (t (setq rest str)))
-
- ;; build suffix
- (let ((last-char (bash-completion-last-char rest))
- (close-quote-str (if open-quote (char-to-string open-quote) ""))
- (final-space-str (if nospace "" " ")))
- (cond
- ((eq ?\ last-char)
- (setq rest (substring rest 0 -1))
- (setq suffix (concat close-quote-str final-space-str)))
- ((or (bash-completion--find-last last-char wordbreaks)
- (eq ?/ last-char))
- (setq suffix ""))
- ((file-accessible-directory-p
- (bash-completion--expand-file-name (bash-completion-unescape
- open-quote (concat parsed-prefix
rest))))
- (setq suffix "/"))
- (single
- (setq suffix (concat close-quote-str final-space-str)))
- (t (setq suffix close-quote-str))))
-
- ;; put everything back together
- (concat unparsed-prefix
- (bash-completion-escape-candidate rest open-quote)
- suffix)))
+ ;; there is no meaningful link between the prefix and the string.
+ ;; Bypass the whole prefix/suffix logic and replace the string
+ ;; being completed with the string provided by the completion
+ ;; logic.
+ (t (setq whole str)))
+
+ (if whole
+ (bash-completion-escape-candidate whole nil)
+
+ ;; build suffix
+ (let ((last-char (bash-completion-last-char rest))
+ (close-quote-str (if open-quote (char-to-string open-quote) ""))
+ (final-space-str (if nospace "" " ")))
+ (cond
+ ((eq ?\ last-char)
+ (setq rest (substring rest 0 -1))
+ (setq suffix (concat close-quote-str final-space-str)))
+ ((or (bash-completion--find-last last-char wordbreaks)
+ (eq ?/ last-char))
+ (setq suffix ""))
+ ((file-accessible-directory-p
+ (bash-completion--expand-file-name (bash-completion-unescape
+ open-quote (concat
parsed-prefix rest))))
+ (setq suffix "/"))
+ (single
+ (setq suffix (concat close-quote-str final-space-str)))
+ (t (setq suffix close-quote-str))))
+
+ ;; put everything back together
+ (concat unparsed-prefix
+ (bash-completion-escape-candidate rest open-quote)
+ suffix))))
(defun bash-completion-escape-candidate (completion-candidate open-quote)
"Escapes COMPLETION-CANDIDATE.
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index 8cf504d946..2c62d494aa 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -87,7 +87,8 @@
(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)))
+ (let ((comint-dynamic-complete-functions
'(bash-completion-dynamic-complete))
+ (completion-at-point-functions '(comint-completion-at-point
t)))
(progn ,@body))))
(when shell-buffer
(when (and (buffer-live-p shell-buffer)
@@ -100,12 +101,20 @@
(process-get (bash-completion--get-process) 'bash-major-version))
(defun bash-completion_test-complete (complete-me)
+ "Complete COMPLETE-ME and returns the resulting string."
(goto-char (point-max))
(delete-region (line-beginning-position) (line-end-position))
(insert complete-me)
(completion-at-point)
(buffer-substring-no-properties
- (comint-line-beginning-position) (point)))
+ (line-beginning-position) (point)))
+
+(defun bash-completion_test-candidates (complete-me)
+ "Complete COMPLETE-ME and returns the candidates."
+ (goto-char (point-max))
+ (delete-region (line-beginning-position) (line-end-position))
+ (insert complete-me)
+ (nth 2 (bash-completion-dynamic-complete-nocomint)))
(defun bash-completion_test-setup-env (bashrc)
"Sets up a directory that contains a bashrc file other files
@@ -309,5 +318,20 @@ for testing completion."
"sometimes_not_nospace dummyo"
(bash-completion_test-complete "sometimes_not_nospace
dum")))))))
+(ert-deftest bash-completion-integration-bash-4-complex-completion ()
+ (bash-completion_test-with-shell-harness
+ (concat ; .bashrc
+ "function _myprog {\n"
+ " COMPREPLY=( \"ba${COMP_WORDS[$COMP_CWORD]}ta\" )\n"
+ " COMPREPLY+=( \"ba${COMP_WORDS[$COMP_CWORD]}to\" )\n"
+ "}\n"
+ "complete -F _myprog myprog\n")
+ nil ; use-separate-process
+ ;; The default completion engine doesn't support replacing the word
+ ;; to complete with candidates and will ignore all candidates, but
+ ;; other completions engines do support it, so it's worth returning
+ ;; them - but we can't use bash-completion_test-complete.
+ (should (equal '("batitita" "batitito")
+ (bash-completion_test-candidates "myprog blah titi")))))
;;; bash-completion-integration-test.el ends here
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index 4f0d8c06c9..c4516e434a 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -660,14 +660,14 @@ Return (const return-value new-buffer-content)"
:wordbreaks "@><=;|&(:")
nil)))
- ;; just append
- (should (equal "hello\\ world"
+ ;; just replace
+ (should (equal "something\\ else"
(bash-completion-fix
- " world"
+ "something else"
(bash-completion--make
:cword 1
- :stub "hello"
- :unparsed-stub "hello"
+ :stub "something"
+ :unparsed-stub "something"
:wordbreaks "")
nil)))
- [nongnu] elpa/bash-completion 96ce14af96 221/313: Fix typo (#41), (continued)
- [nongnu] elpa/bash-completion 96ce14af96 221/313: Fix typo (#41), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 783a1e79f0 230/313: Add melpa and melpa-stable badges to README., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion d8f02ecbb1 231/313: Merge branch 'master' into use-separate-processes-opt, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 10569a4625 232/313: Fix bash-completion-test-send., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1b7ec87915 233/313: Fix byte-compilation error under Emacs 24 and 25., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a2da7b910b 235/313: Updated README to push for bash-completion-use-separate-processes., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion fd3ba68800 236/313: Force bash-completion-use-separate-processes to t in tests., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7f4410ebcb 237/313: Extend integration tests to cover single-process use-case., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f8c2083a14 239/313: Rename bash-completion-get-process., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c25f2203f5 240/313: Fix typo and extend note about use-separate-processes-opt., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 685ed73df0 243/313: Allow completion to replace the word being completed.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 7dc20e1b09 244/313: Use separate processes in integration tests when it doesn't matter., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a0a5816ce4 245/313: Attempt to make in-process execution more robust., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion cad904abfd 247/313: Redefine quote_readline from setup-bash-common., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5447034cdc 251/313: Respect completion-ignore-case setting from .inputrc., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 42630fe6cc 254/313: Fix test case to cover substring completion., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8f33a2aac4 257/313: Better document calling bash-completion from completion-at-point., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 96d2cef799 259/313: Prepare for a 3.0 release., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4aafffe76a 260/313: Create CONTRIBUTING.md, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2b9eba14fa 261/313: Update README.md, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 79ce50bec9 262/313: Update README.md title, ELPA Syncer, 2022/12/03