[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 482383dcd7 021/313: handle slash for direc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 482383dcd7 021/313: handle slash for directory, usable completion |
Date: |
Sat, 3 Dec 2022 10:59:11 -0500 (EST) |
branch: elpa/bash-completion
commit 482383dcd79a1527a0ef10d72c8a3ed017a84846
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
handle slash for directory, usable completion
---
bash-completion.el | 47 ++++++++++++++++++++++++++++-------------------
bash-completion_test.el | 44 ++++++++++++++++++++++++++++++++++++--------
2 files changed, 64 insertions(+), 27 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index dc9e40a177..43fe828745 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -40,7 +40,7 @@ See `bash-completion-add-to-alist'.
"Bash completion function for `comint-complete-dynamic-functions'.
Call bash to do the completion."
- (when (window-minibuffer-p)
+ (when (not (window-minibuffer-p))
(message "Bash completion..."))
(let* ( (pos (point))
(start (bash-completion-line-beginning-position))
@@ -49,7 +49,10 @@ Call bash to do the completion."
(wordsplit)
(cword)
(words)
- (stub) )
+ (stub)
+ ;; Override configuration for comint-dynamic-simple-complete.
+ ;; Bash adds a space suffix automatically.
+ (comint-completion-addsuffix nil) )
(save-excursion
(setq wordsplit (bash-completion-split start end pos))
(setq cword (car wordsplit))
@@ -57,15 +60,14 @@ Call bash to do the completion."
(setq stub (nth cword words)))
(comint-dynamic-simple-complete
stub
- (bash-completion-comm default-directory
- line (- pos start) words cword))))
+ (bash-completion-comm line (- pos start) words cword))))
(defun bash-completion-line-beginning-position (&optional start)
(save-excursion
(let ((start (or start (comint-line-beginning-position)))
(end (line-end-position)))
- (goto-char start)
- (if (search-forward-regexp "\\(;\\|\\(&&\\)\\|\\(||\\)\\)[ \t\n]" end t)
+ (goto-char end)
+ (if (search-backward-regexp "\\(;\\|\\(&&\\)\\|\\(||\\)\\|\\(=[^
\t]*\\)\\)[ \t\n]" start t)
(match-end 0)
start))))
@@ -144,22 +146,25 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(concat "^ \t\n\r" (char-to-string quote))
"^ \t\n\r'\""))
-(defun bash-completion-comm (dir line pos words cword)
- "Set DIR, LINE, POS, WORDS and CWORD, call bash completion, return the
result.
+(defun bash-completion-comm (line pos words cword)
+ "Set LINE, POS, WORDS and CWORD, call bash completion, return the result.
This function starts a separate bash process if necessary, sets up the
completion environment (COMP_LINE, COMP_POINT, COMP_WORDS, COMP_CWORD) and
calls compgen.
The result is a list of candidates, which might be empty."
- (bash-completion-send (concat (bash-completion-generate-line dir line pos
words cword) " 2>/dev/null"))
+ (bash-completion-send (concat (bash-completion-generate-line line pos words
cword) " 2>/dev/null"))
(with-current-buffer (bash-completion-buffer)
- (mapcar 'bash-completion-trim (split-string (buffer-string) "\n" t))))
+ (mapcar 'bash-completion-addsuffix (split-string (buffer-string) "\n" t))))
-(defun bash-completion-trim (str)
- (if (string-match "^ *\\(.*[^ ]\\) *$" str)
- (match-string 1 str)
- str))
+(defun bash-completion-addsuffix (str)
+ (let ((end (substring str -1)))
+ (if (and (not (eq end " "))
+ (not (eq end "/"))
+ (file-accessible-directory-p str))
+ (concat str "/")
+ str)))
(defun bash-completion-require-process ()
(if (bash-completion-is-running)
@@ -201,14 +206,18 @@ The result is a list of candidates, which might be empty."
(kill-process process)
(error nil))))))))
-(defun bash-completion-generate-line (dir line pos words cword)
+(defun bash-completion-generate-line (line pos words cword)
(concat
- (if default-directory (concat "cd " (bash-completion-quote
(expand-file-name dir)) " ; ") "")
- (let* ( (command (file-name-nondirectory (car words)))
- (compgen-args (cdr (assoc command bash-completion-alist))) )
+ (if default-directory (concat "cd " (bash-completion-quote
(expand-file-name default-directory)) " ; ") "")
+ (let* ( (command-name (file-name-nondirectory (car words)))
+ (compgen-args (cdr (assoc command-name bash-completion-alist))) )
(if (not compgen-args)
;; no custom completion. use default completion
- (bash-completion-join (list "compgen" "-o" "default" (nth cword
words)))
+ (if (= cword 0)
+ ;; a command. let emacs expand executable, let bash expand
builtins, aliases and functions
+ (concat (bash-completion-join (list "compgen" "-S" " " "-b" "-a"
"-A" "function" (car words))))
+ ;; argument
+ (bash-completion-join (list "compgen" "-o" "default" (nth cword
words))))
;; custom completion
(let* ( (args (copy-tree compgen-args))
(function (or (member "-F" args) (member "-C" args))) )
diff --git a/bash-completion_test.el b/bash-completion_test.el
index fb188a14fa..64ef657b90 100644
--- a/bash-completion_test.el
+++ b/bash-completion_test.el
@@ -168,23 +168,27 @@ garbage
"'hell'\\''o'")
("bash-completion-generate-line no custom completion"
- (let ((bash-completion-alist nil))
- (bash-completion-generate-line "~/test" "hello worl" 7 '("hello"
"worl") 1))
+ (let ((bash-completion-alist nil)
+ (default-directory "~/test"))
+ (bash-completion-generate-line "hello worl" 7 '("hello" "worl") 1))
(concat "cd " (expand-file-name "~/test") " ; compgen -o default worl"))
("bash-completion-generate-line custom completion no function or command"
- (let ((bash-completion-alist '(("zorg" . ("-A" "-G" "*.txt")))))
- (bash-completion-generate-line "/test" "zorg worl" 7 '("zorg" "worl")
1))
+ (let ((bash-completion-alist '(("zorg" . ("-A" "-G" "*.txt"))))
+ (default-directory "/test"))
+ (bash-completion-generate-line "zorg worl" 7 '("zorg" "worl") 1))
"cd /test ; compgen -A -G '*.txt' -- worl")
("bash-completion-generate-line custom completion function"
- (let ((bash-completion-alist '(("zorg" . ("-F" "__zorg")))))
- (bash-completion-generate-line "/test" "zorg worl" 7 '("zorg" "worl")
1))
+ (let ((bash-completion-alist '(("zorg" . ("-F" "__zorg"))))
+ (default-directory "/test"))
+ (bash-completion-generate-line "zorg worl" 7 '("zorg" "worl") 1))
"cd /test ; __BASH_COMPLETE_WRAPPER='COMP_LINE='\\''zorg worl'\\'';
COMP_POINT=7; COMP_CWORD=1; COMP_WORDS=( zorg worl ); __zorg \"$@\"' compgen -F
__bash_complete_wrapper -- worl")
("bash-completion-generate-line custom completion command"
- (let ((bash-completion-alist '(("zorg" . ("-C" "__zorg")))))
- (bash-completion-generate-line "/test" "zorg worl" 7 '("zorg" "worl")
1))
+ (let ((bash-completion-alist '(("zorg" . ("-C" "__zorg"))))
+ (default-directory "/test"))
+ (bash-completion-generate-line "zorg worl" 7 '("zorg" "worl") 1))
"cd /test ; __BASH_COMPLETE_WRAPPER='COMP_LINE='\\''zorg worl'\\'';
COMP_POINT=7; COMP_CWORD=1; COMP_WORDS=( zorg worl ); __zorg \"$@\"' compgen -F
__bash_complete_wrapper -- worl")
("bash-completion-trim"
@@ -205,6 +209,14 @@ garbage
(bash-completion-line-beginning-position 1)))
'(14 14))
+ ("bash-completion-line-beginning-position 2 semicolon"
+ (sz-testutils-with-buffer
+ '("cd /home/x ; blah; " cursor "echo hello")
+ (list
+ (point)
+ (bash-completion-line-beginning-position 1)))
+ '(20 20))
+
("bash-completion-line-beginning-position &&"
(sz-testutils-with-buffer
'("cd /home/x && " cursor "echo hello")
@@ -213,6 +225,22 @@ garbage
(bash-completion-line-beginning-position 1)))
'(15 15))
+ ("bash-completion-line-beginning-position ||"
+ (sz-testutils-with-buffer
+ '("cd /home/x || " cursor "echo hello")
+ (list
+ (point)
+ (bash-completion-line-beginning-position 1)))
+ '(15 15))
+
+ ("bash-completion-line-beginning-position variable assignment"
+ (sz-testutils-with-buffer
+ '("a=b " cursor "echo hello")
+ (list
+ (point)
+ (bash-completion-line-beginning-position 1)))
+ '(5 5))
+
)))
- [nongnu] elpa/bash-completion f15176ee59 267/313: Fix to properly evaluate PROMPT_COMMAND after restoring it., (continued)
- [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
- [nongnu] elpa/bash-completion e81c478032 020/313: bash-complete -> bash-completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8270e09294 023/313: pass words as command-line arguments to the function, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 482383dcd7 021/313: handle slash for directory, usable completion,
ELPA Syncer <=
- [nongnu] elpa/bash-completion cd2ec103d1 026/313: Expand directory names with quotes and spaces, but no further, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1d7af7e40d 027/313: Remove debug messages, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion dda4697cfb 029/313: included bash-completion into google env, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 21eabde7f9 045/313: Reimplemented split, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3c58afdb0d 033/313: expand file names in colon-separated paths, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5501cb63cf 042/313: Turn off mail warning, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0dcf43f91e 041/313: don't run integration tests by default, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5b76fc4a33 032/313: remove wrong a=b variable prefix handling, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7697f1a87c 063/313: comments about tried systems, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3efe7cb03c 067/313: escape #, ELPA Syncer, 2022/12/03