[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion f5384c6176 051/313: A little refactoring,
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion f5384c6176 051/313: A little refactoring, test case for wordbreak completion |
Date: |
Sat, 3 Dec 2022 10:59:15 -0500 (EST) |
branch: elpa/bash-completion
commit f5384c61760e5c9ac0c85456c131832ad027ef1d
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
A little refactoring, test case for wordbreak completion
---
bash-completion.el | 51 +++++++++++++++++++++++++++++++++++++------------
bash-completion_test.el | 18 +++++++++++++++++
2 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index fa2f0d03b7..4b2440ec9b 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -10,7 +10,11 @@
(defvar bash-completion-prog "bash"
"Command-line to execute bash")
-(defvar bash-completion-process-timeout 2.5)
+(defvar bash-completion-process-timeout 2.5
+ "Timeout value to apply when waiting from an answer from the
+bash process. If bash takes longer than that to answer, the answer
+will be ignored.")
+
(defvar bash-completion-initial-timeout 30
"Timeout value to apply when talking to bash for the first time.
The first thing bash is supposed to do is process /etc/bash_complete,
@@ -29,8 +33,15 @@ the following entry is added to `bash-completion-alist':
See `bash-completion-add-to-alist'.
")
-(defconst bash-completion-wordbreaks-str "\"'@><=;|&(:")
-(defconst bash-completion-wordbreaks (append bash-completion-wordbreaks-str
nil))
+(defconst bash-completion-wordbreaks-str "\"'@><=;|&(:"
+ "The equivalent of COMP_WORDBREAKS: special characters that are
+considered word breaks in some cases when doing completion. This
+was introduced initially to support file completion in
+colon-separated values.")
+
+(defconst bash-completion-wordbreaks
+ (append bash-completion-wordbreaks-str nil)
+ "`bash-completion-wordbreaks-str' as a list of characters")
(defun bash-completion-setup ()
(add-hook 'shell-dynamic-complete-functions
@@ -50,20 +61,32 @@ Call bash to do the completion."
(end (line-end-position))
(parsed (bash-completion-parse-line start end pos))
(line (cdr (assq 'line parsed)))
+ (point (cdr (assq 'point parsed)))
(cword (cdr (assq 'cword parsed)))
(words (cdr (assq 'words parsed)))
(stub (nth cword words))
+ (completions (bash-completion-comm line point words cword))
;; Override configuration for comint-dynamic-simple-complete.
;; Bash adds a space suffix automatically.
(comint-completion-addsuffix nil) )
- (let ((completions (bash-completion-comm line (- pos start) words cword)))
- (if completions
- (comint-dynamic-simple-complete stub completions)
- ;; try default completion after a wordbreak
- (let ((after-wordbreak (bash-completion-after-last-wordbreak stub)))
- (when (not (equal stub after-wordbreak))
- (bash-completion-send (concat (bash-completion-cd-command-prefix)
"compgen -o default -- " after-wordbreak))
- (comint-dynamic-simple-complete after-wordbreak
(bash-completion-extract after-wordbreak))))))))
+ (if completions
+ (comint-dynamic-simple-complete stub completions)
+ ;; no standard completion
+ ;; try default (file) completion after a wordbreak
+ (bash-completion-dynamic-try-wordbreak-complete stub))))
+
+(defun bash-completion-dynamic-try-wordbreak-complete (stub)
+ (let* ((wordbreak-split (bash-completion-last-wordbreak-split stub))
+ (before-wordbreak (car wordbreak-split))
+ (after-wordbreak (cdr wordbreak-split)))
+ (when (car wordbreak-split)
+ (bash-completion-send (concat
+ (bash-completion-cd-command-prefix)
+ "compgen -o default -- "
+ after-wordbreak))
+ (comint-dynamic-simple-complete
+ after-wordbreak
+ (bash-completion-extract after-wordbreak)))))
(defun bash-completion-join (words)
"Join WORDS into a shell line, escaped all words with single quotes"
@@ -116,6 +139,7 @@ Call bash to do the completion."
(push "" strings))
(list
(cons 'line (buffer-substring-no-properties start (cdr
(bash-completion-tokenize-get-range current))))
+ (cons 'point (- pos start))
(cons 'cword cword)
(cons 'words (nreverse strings)))))
@@ -234,7 +258,10 @@ Call bash to do the completion."
(defconst bash-completion-nonsep-alist
'((nil . "^ \t\n\r;&|'\"")
(?' . "^ \t\n\r'")
- (?\" . "^ \t\n\r\"")))
+ (?\" . "^ \t\n\r\""))
+ "Sets of non-breaking characters for all quoting
+environment (no quote, single quote and double quote).
+Get it using `bash-completion-nonsep'.")
(defun bash-completion-nonsep (quote)
(cdr (assq quote bash-completion-nonsep-alist)))
diff --git a/bash-completion_test.el b/bash-completion_test.el
index 688005598a..4f1f82c6aa 100644
--- a/bash-completion_test.el
+++ b/bash-completion_test.el
@@ -137,6 +137,7 @@ cases. That's why they need to be enabled manually.")
'("a hello world" cursor " b c")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "a hello world b c")
+ (point . 13)
(cword . 2)
(words . ("a" "hello" "world" "b" "c"))))
@@ -145,6 +146,7 @@ cases. That's why they need to be enabled manually.")
'("a hello wo" cursor "rld b c")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "a hello world b c")
+ (point . 10)
(cword . 2)
(words . ("a" "hello" "world" "b" "c"))))
@@ -153,6 +155,7 @@ cases. That's why they need to be enabled manually.")
'(" " cursor " a hello world b c")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . " a hello world b c")
+ (point . 0)
(cword . 0)
(words . ("" "a" "hello" "world" "b" "c"))))
@@ -161,6 +164,7 @@ cases. That's why they need to be enabled manually.")
'("a hello " cursor " world b c")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "a hello world b c")
+ (point . 8)
(cword . 2)
(words . ("a" "hello" "" "world" "b" "c"))))
@@ -169,6 +173,7 @@ cases. That's why they need to be enabled manually.")
'("a hello world b c" cursor)
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "a hello world b c")
+ (point . 17)
(cword . 4)
(words . ("a" "hello" "world" "b" "c"))))
@@ -177,6 +182,7 @@ cases. That's why they need to be enabled manually.")
'("cd /var/tmp ; ZORG=t make -" cursor " -f Makefile && ./zorg")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "make - -f Makefile")
+ (point . 6)
(cword . 1)
(words . ("make" "-" "-f" "Makefile"))))
@@ -186,6 +192,7 @@ cases. That's why they need to be enabled manually.")
'("ls /var/tmp | sort -" cursor)
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "sort -")
+ (point . 6)
(cword . 1)
(words . ("sort" "-"))))
@@ -194,6 +201,7 @@ cases. That's why they need to be enabled manually.")
'("find -name '*.txt' -" cursor " -exec echo {} ';' | head")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "find -name '*.txt' - -exec echo {} ';'")
+ (point . 20)
(cword . 3)
(words . ("find" "-name" "*.txt" "-" "-exec" "echo" "{}" ";"))))
@@ -202,6 +210,7 @@ cases. That's why they need to be enabled manually.")
'("cd /var/tmp ; A=f ZORG=t" cursor " make -f Makefile && ./zorg")
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "ZORG=t")
+ (point . 6)
(cword . 0)
(words . ("ZORG=t"))))
@@ -210,6 +219,7 @@ cases. That's why they need to be enabled manually.")
'("a hello world b c " cursor)
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "a hello world b c")
+ (point . 18)
(cword . 5)
(words . ("a" "hello" "world" "b" "c" ""))))
@@ -218,6 +228,7 @@ cases. That's why they need to be enabled manually.")
'("cd /vcr/shows/Dexter\\'s" cursor)
(bash-completion-parse-line 1 (line-end-position) (point)))
'((line . "cd /vcr/shows/Dexter\\'s")
+ (point . 23)
(cword . 1)
(words . ("cd" "/vcr/shows/Dexter's"))))
@@ -559,6 +570,13 @@ garbage
(bash-completion-dynamic-complete)))
"__bash_complete_wrapper ")
+ ("bash-completion execute wordbreak completion"
+ (bash-completion_test-with-shell
+ (let ((start (point)))
+ (insert "export PATH=/sbin:/b")
+ (bash-completion-dynamic-complete)))
+ "export PATH=/sbin:/bin/")
+
)))
;; Run diagnostics when this module is evaluated or compiled
- [nongnu] elpa/bash-completion c5d4f92e6d 195/313: Still EMACS_BASH_COMPLETE using setenv for local processes., (continued)
- [nongnu] elpa/bash-completion c5d4f92e6d 195/313: Still EMACS_BASH_COMPLETE using setenv for local processes., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 24088ede85 196/313: Explicitly mention compatibility with Bash 3 and 4., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0f6466eeb4 197/313: Tell minibuffer not to delay after displaying a message while, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0c4557a5ed 193/313: Integration test for default completion (-D)., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e7869dd68d 200/313: Fix a bug when no process is associated with the current buffer, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 80be2f37a9 205/313: Check the buffer uses comint-mode before using the same process, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 28ec870dd1 019/313: only one -complete method, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6a0ada6278 038/313: completed test cases, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7d6236e6e7 100/313: ignore .elc files, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1aff6d8806 084/313: comment about shell-command, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f5384c6176 051/313: A little refactoring, test case for wordbreak completion,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 6f7c2b8b4f 080/313: removed initial version, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a2cf41d7fc 102/313: put in accidentally removed blank line from README, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a8b652d00a 058/313: commented all functions, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b4fe25b51c 060/313: update tests for latest refactorings, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 49ae0ada64 076/313: keep open quote, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion aedcc114dc 105/313: Minor fixes to eliminate byte-compiler warnings., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8c771b10d1 082/313: fix typo, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9ca7e3a77f 085/313: Fixed errors in documentation, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 97cace2287 089/313: Split shopt sets; if one fails the rest can run, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 007765fdd1 111/313: Make bash-completion.el work under emacs trunk., ELPA Syncer, 2022/12/03