[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 34d11220dd 024/313: add prefix if missing
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 34d11220dd 024/313: add prefix if missing |
Date: |
Sat, 3 Dec 2022 10:59:12 -0500 (EST) |
branch: elpa/bash-completion
commit 34d11220dd5d474cfa3be2797388d566bd782860
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
add prefix if missing
---
bash-completion.el | 21 +++++++++++++++++----
bash-completion_test.el | 22 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index f880c9ee65..d649d6c1d7 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -59,9 +59,7 @@ Call bash to do the completion."
(setq words (cdr wordsplit))
(setq stub (nth cword words)))
(let ((completions (bash-completion-comm line (- pos start) words cword)))
- (comint-dynamic-simple-complete
- stub
- completions))))
+ (comint-dynamic-simple-complete stub completions))))
(defun bash-completion-line-beginning-position (&optional start)
(save-excursion
@@ -163,7 +161,21 @@ calls compgen.
The result is a list of candidates, which might be empty."
(bash-completion-send (concat (bash-completion-generate-line line pos words
cword) " 2>/dev/null"))
(with-current-buffer (bash-completion-buffer)
- (mapcar 'bash-completion-addsuffix (split-string (buffer-string) "\n" t))))
+ (let ((bash-completion-prefix (nth cword words)))
+ (mapcar 'bash-completion-fix (split-string (buffer-string) "\n" t)))))
+
+(defun bash-completion-fix (str)
+ (bash-completion-addsuffix
+ (if (bash-completion-starts-with str bash-completion-prefix)
+ str
+ (concat bash-completion-prefix str))))
+
+(defun bash-completion-starts-with (str prefix)
+ (let ((prefix-len (length prefix))
+ (str-len (length str)))
+ (and
+ (>= str-len prefix-len)
+ (equal (substring str 0 prefix-len) prefix))))
(defun bash-completion-addsuffix (str)
(let ((end (substring str -1)))
@@ -253,6 +265,7 @@ The result is a list of candidates, which might be empty."
(and bash-completion-process (eq 'run (process-status
bash-completion-process))))
(defun bash-completion-send (commandline &optional process timeout)
+ (message commandline)
(let ((process (or process (bash-completion-require-process)))
(timeout (or timeout bash-completion-process-timeout)))
(with-current-buffer (process-buffer process)
diff --git a/bash-completion_test.el b/bash-completion_test.el
index 4c33ea003e..cd64a75a65 100644
--- a/bash-completion_test.el
+++ b/bash-completion_test.el
@@ -249,6 +249,28 @@ garbage
(bash-completion-line-beginning-position 1)))
'(5 5))
+ ("bash-completion-line-beginning-position variable assignment"
+ (sz-testutils-with-buffer
+ '("ls ; c=d export a=b" cursor)
+ (bash-completion-line-beginning-position 1))
+ 10)
+
+ ("bash-completion-starts-with empty str"
+ (bash-completion-starts-with "" "prefix")
+ nil)
+
+ ("bash-completion-starts-with starts with"
+ (bash-completion-starts-with "blah-blah" "blah-")
+ t)
+
+ ("bash-completion-starts-with does not starts with"
+ (bash-completion-starts-with "blah-blah" "blih-")
+ nil)
+
+ ("bash-completion-starts-with same"
+ (bash-completion-starts-with "blah-" "blah-")
+ t)
+
)))
- [nongnu] branch elpa/bash-completion created (now 8e9c20dbfe), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7dc290e1c7 003/313: exclude quotes from result, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 540f8f516a 011/313: build bash cmdline, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6eebe8f965 016/313: cleaned up process launch, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 34d11220dd 024/313: add prefix if missing,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 3036ef0394 028/313: disable quote_readline to get good whitespace handling for bash 3.2 at least, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ba83e81651 053/313: bash-completion-generate-line, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f7bfc68ea2 001/313: bash completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f5885ec87a 002/313: test case for bash-complete, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 208cb5ab76 007/313: Join, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 47a890dd72 010/313: launch process, send commands, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 53f2c5d30e 009/313: parse complete -p output, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 11e52fce6f 018/313: Fixed initialization, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c10cfef5b8 015/313: complex line split, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b5c2fbf4a2 014/313: add hooks, ELPA Syncer, 2022/12/03