[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 2a937b3763 255/313: Don't let Emacs post-f
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 2a937b3763 255/313: Don't let Emacs post-filter completions built by bash. |
Date: |
Sat, 3 Dec 2022 10:59:35 -0500 (EST) |
branch: elpa/bash-completion
commit 2a937b3763d2d01dce06039fa87675681239d86b
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Don't let Emacs post-filter completions built by bash.
With this change, the completions built by bash are offered to the
user even if they don't match the string to be completed.
Before this change, the dynamic completion table would call
try-completion/all-completion/test-completion, which would then filter
the result according to the current completion style, which makes no
sense as bash produces complete completions.
Not allowing post-processing of the completion also means that there's
no need to worry about the value of completion-ignore-case anymore on
the Emacs side; bash-completion.el just serves whatever bash returns.
Note that post-filtering is still possible when using
bash-completion-dynamic-complete-nocomint with the argument
dynamic-table left nil. In this scenario, the completion engine is
free to process the results as it wants.
---
bash-completion.el | 77 +++++++++++++++++---------------
test/bash-completion-integration-test.el | 50 +++++++++++----------
test/bash-completion-test.el | 13 +-----
3 files changed, 68 insertions(+), 72 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 9836051d3f..b6d6d20301 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -441,12 +441,6 @@ returned."
(process-put process 'bash-major-version bash-major-version)
(bash-completion-send "bind -v 2>/dev/null" process)
- (process-put process 'completion-ignore-case
- (with-current-buffer (bash-completion--get-buffer process)
- (save-excursion
- (goto-char (point-min))
- (search-forward "completion-ignore-case on" nil
'noerror))))
-
(process-put process 'setup-done t)))
;;; ---------- Inline functions
@@ -522,10 +516,6 @@ When doing completion outside of a comint buffer, call
(if message-timer
(cancel-timer message-timer)))))
-(defalias 'bash-completion--completion-table-with-cache
- (if (fboundp 'completion-table-with-cache)
- 'completion-table-with-cache 'completion-table-dynamic))
-
(defun bash-completion--complete (comp process)
(condition-case err
(bash-completion-comm comp process)
@@ -570,26 +560,16 @@ Returns (list stub-start stub-end completions) with
comp-start comp-pos
(process-get process 'wordbreaks)
(process-get process 'bash-major-version)))
- (stub-start (bash-completion--stub-start comp))
- (use-separate-processes bash-completion-use-separate-processes))
-
- ;; This sets completion-ignore-case which matters for the
- ;; caller, as it needs to know how to post-process the
- ;; results.
- (let ((ignore-case (process-get process 'completion-ignore-case)))
- (unless (eq completion-ignore-case ignore-case)
- (setq completion-ignore-case ignore-case)))
-
+ (stub-start (bash-completion--stub-start comp)))
+
(bash-completion--customize comp process)
(list
stub-start
comp-pos
(if dynamic-table
(bash-completion--completion-table-with-cache
- (lambda (_)
- (let ((bash-completion-use-separate-processes
- use-separate-processes))
- (bash-completion--complete comp process))))
+ comp process
+ bash-completion-use-separate-processes)
(bash-completion--complete comp process)))))))
(defun bash-completion--find-last (elt array)
@@ -981,18 +961,6 @@ for directory name detection to work."
((bash-completion-starts-with str parsed-prefix)
(setq rest (substring str (length parsed-prefix))))
- ;; unexpand the home directory expanded by bash automatically
- ((and (bash-completion-starts-with parsed-prefix "~")
- (bash-completion-starts-with str (bash-completion--expand-file-name
"~" t)))
- (setq rest (substring (concat "~" (substring str (length
(bash-completion--expand-file-name "~" t))))
- (length parsed-prefix))))
-
- ((bash-completion-starts-with parsed-prefix str)
- ;; completion is a substring of prefix something's gone
- ;; wrong. Treat it as one (useless) candidate.
- (setq unparsed-prefix "")
- (setq rest str))
-
;; completion sometimes only applies to the last word, as
;; defined by COMP_WORDBREAKS. This detects and works around
;; this feature.
@@ -1005,6 +973,13 @@ for directory name detection to work."
;; Bypass the whole prefix/suffix logic and replace the string
;; being completed with the string provided by the completion
;; logic.
+ ((string-match "^~.*?\\($\\|/\\)" str)
+ (setq parsed-prefix (substring str 0 (match-end 0))
+ unparsed-prefix
+ (concat (substring str 0 (match-end 0))
+ (if open-quote (char-to-string open-quote) ""))
+ rest (substring str (match-end 0))))
+
(t
(setq parsed-prefix ""
unparsed-prefix (if open-quote (char-to-string open-quote) "")
@@ -1563,6 +1538,36 @@ Return the parsed value, as a string or nil."
(prog1 (match-string 1)
(delete-region (match-beginning 0) (match-end 0)))))))
+(defun bash-completion--completion-table-with-cache (comp process
use-separate-process)
+ "Build a dynamic completion table for COMP using PROCESS.
+
+The result is a function that works like one built by
+`completion-table-with-cache' with the difference that the
+completions, built by `bash-completion--complete' are complete
+and that completion style doesn't necessarily use substring
+completion."
+ (let ((last-str) (last-result))
+ (lambda (str predicate action)
+ (if (or (eq (car-safe action) 'boundaries)
+ (eq action 'metadata))
+ nil
+ (let ((result (if (equal str last-str)
+ last-result
+ (let ((bash-completion-use-separate-processes
+ use-separate-process))
+ (bash-completion--complete comp process)))))
+ (setq last-str str
+ last-result result)
+ ;; The below passes an empty string to try-completion,
+ ;; all-completions and test-completion to not let them do
+ ;; any further filtering.
+ (funcall
+ (cond
+ ((null action) 'try-completion)
+ ((eq action t) 'all-completions)
+ (t 'test-completion))
+ "" result predicate))))))
+
(provide 'bash-completion)
;; Local Variables:
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index e2fe939ef7..97e0238590 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -65,12 +65,16 @@
;; Give Emacs time to process any input or process state
;; change from bash-completion-reset.
(while (accept-process-output nil 0.1))
- (unwind-protect
- (progn ,@body)
- (progn
- (set explicit-args-var old-explicit-args)
- (bash-completion_test-teardown-env test-env-dir)
- (bash-completion-reset-all))))))
+ (let ((realhome (getenv "HOME")))
+ (unwind-protect
+ (progn
+ (setenv "HOME" test-env-dir)
+ ,@body)
+ (progn
+ (setenv "HOME" realhome)
+ (set explicit-args-var old-explicit-args)
+ (bash-completion_test-teardown-env test-env-dir)
+ (bash-completion-reset-all)))))))
(defmacro bash-completion_test-with-shell-harness (bashrc use-separate-process
&rest body)
`(bash-completion_test-harness
@@ -341,11 +345,9 @@ for testing completion."
"}\n"
"complete -F _myprog myprog\n")
t ; bash-completion-use-separate-processes
- (let ((completion-in-region-function 'completion--in-region)
- (completion-styles '(basic partial-completion substring emacs22)))
- (should (equal
- "myprog blah batitita "
- (bash-completion_test-complete "myprog blah titi"))))))
+ (should (equal
+ "myprog blah batitita "
+ (bash-completion_test-complete "myprog blah titi")))))
(ert-deftest bash-completion-integration-vioption-single-process-test ()
(bash-completion_test--with-bash-option "set -o vi" nil))
@@ -409,7 +411,13 @@ for testing completion."
(should (equal "ls \"Another Uppercase/" (bash-completion_test-complete
"ls \"ano")))
(should (equal "ls 'Another Uppercase/" (bash-completion_test-complete
"ls 'Ano")))
(should (equal "ls 'Another Uppercase/" (bash-completion_test-complete
"ls 'ano")))
- (should completion-ignore-case)))))
+
+ ;; When doing case-insensitive search, bash-completion.el cannot
+ ;; keep the exact same quotes, so it just puts the quote, if
+ ;; any, at the beginning, just after the tilde part.
+ (should (equal "ls \"Another Uppercase/" (bash-completion_test-complete
"ls ano\"t")))
+ (should (equal "ls 'Another Uppercase/" (bash-completion_test-complete
"ls ano't")))
+ (should (equal "ls ~/\"Another Uppercase/"
(bash-completion_test-complete "ls ~/ano\"t")))))))
(ert-deftest bash-completion-integration-case-sensitive-test ()
(bash-completion_test-harness
@@ -427,18 +435,12 @@ for testing completion."
(should (not completion-ignore-case)))))
(ert-deftest bash-completion-integration-tilde-test ()
- (bash-completion_test-harness
- "HOME=$PWD\n"
+ (bash-completion_test-with-shell-harness
+ ""
nil ; use-separate-process
- (let ((realhome (getenv "HOME")))
- (unwind-protect
- (progn
- (setenv "HOME" test-env-dir)
- (bash-completion_test-with-shell
- (should (equal "ls some/" (bash-completion_test-complete "ls so")))
- (should (equal "ls ~/some/" (bash-completion_test-complete "ls
~/so")))
- (should (equal "ls \"~/some/" (bash-completion_test-complete "ls
\"~/so")))
- (should (equal "ls '~/some/" (bash-completion_test-complete "ls
'~/so")))))
- (setenv "HOME" realhome)))))
+ (should (equal "ls some/" (bash-completion_test-complete "ls so")))
+ (should (equal "ls ~/some/" (bash-completion_test-complete "ls ~/so")))
+ (should (equal "ls \"~/some/" (bash-completion_test-complete "ls \"~/so")))
+ (should (equal "ls '~/some/" (bash-completion_test-complete "ls '~/so")))))
;;; bash-completion-integration-test.el ends here
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index 5c794525a2..84c2e2f30b 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -638,17 +638,6 @@ Return (const return-value new-buffer-content)"
:compgen-args '("-o" "nospace"))
nil)))
- ;; unexpand home and escape
- (should (equal "~/a/hello\\ world"
- (bash-completion-fix
- (expand-file-name "~/a/hello world")
- (bash-completion--make
- :cword 1
- :stub "~/a/he"
- :unparsed-stub "~/a/he"
- :wordbreaks "")
- nil)))
-
;; match after wordbreak and escape
(should (equal "a:b:c:hello\\ world"
(bash-completion-fix
@@ -674,7 +663,7 @@ Return (const return-value new-buffer-content)"
;; append / for home
(should (equal "~/"
(bash-completion-fix
- (expand-file-name "~")
+ "~"
(bash-completion--make
:cword 1
:stub "~"
- [nongnu] elpa/bash-completion fbdc78b877 198/313: Support compopt when using Bash 4., (continued)
- [nongnu] elpa/bash-completion fbdc78b877 198/313: Support compopt when using Bash 4., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f1bd3d528f 201/313: Improve some docstrings, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion fa49dbb382 209/313: Improve status code retrieval, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7822d84812 223/313: Added Cask with ert-runner to compile and run test., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 31a01859b2 227/313: Do not run tests under Emacs 24.1., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 21471cc542 228/313: Report result of running the test workflow on README.md., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 98a2a21be7 234/313: Provide a way of refreshing the completion table., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4fcddf83c9 242/313: Make /etc/bash_completion scripts work with escaped spaces., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2dbc7e61f6 248/313: Extend bash-completion-refresh to refresh everything, test it., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 04393bca0f 250/313: Apply filename post-processing even when prefix doesn't match., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2a937b3763 255/313: Don't let Emacs post-filter completions built by bash.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion e95867c993 256/313: completion-table-with-cache captures and restore buffer and variables., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 747920fdbf 265/313: Avoid having to set BASH_COMPLETION., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f15176ee59 267/313: Fix to properly evaluate PROMPT_COMMAND after restoring it., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b4ae893243 268/313: Test prompt and history manipulation, fix $? in prompt., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 20feaf909d 258/313: Fix markdown markup., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8713edbb92 269/313: Mention that completion works with bash 5, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4b80c75c43 272/313: Take current directory from shell when in single-process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ea5cc15b99 273/313: Let status code of compgen through when in single-process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 12da4f0e91 289/313: Better handle slow completion functions., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7186a18cad 012/313: Integrated into comm, ELPA Syncer, 2022/12/03