[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion e81c478032 020/313: bash-complete -> bash-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion e81c478032 020/313: bash-complete -> bash-completion |
Date: |
Sat, 3 Dec 2022 10:59:11 -0500 (EST) |
branch: elpa/bash-completion
commit e81c4780327fe7dfb6c659ef4729907a668f870d
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
bash-complete -> bash-completion
---
bash-complete_test.el | 227 ---------------------------------
bash-complete.el => bash-completion.el | 178 +++++++++++++-------------
bash-completion_test.el | 227 +++++++++++++++++++++++++++++++++
3 files changed, 319 insertions(+), 313 deletions(-)
diff --git a/bash-complete_test.el b/bash-complete_test.el
deleted file mode 100644
index d5dfb32955..0000000000
--- a/bash-complete_test.el
+++ /dev/null
@@ -1,227 +0,0 @@
-;;; bash-complete_test.el --- Tests jbtn-complete.el
-
-
-;;; Commentary:
-;;
-;; This file defines `bash-complete-regress' and run the
-;; regression tests if and only if regress is already imported.
-;;
-
-;;; History:
-;;
-
-;;; Code:
-(eval-when-compile
- ;; force reload
- (load-library "~/.emacs.d/bash-complete.el")
-
- (require 'sz-testutils)
-
- ;; This code will not appear in the compiled (.elc) file
- (put 'bash-complete-regress 'regression-suite t)
- (setq bash-complete-regress
- '("bash-complete-regress"
- ;; Each test in the suite is of the form:
- ;; ([description] probe grader)
- ;; DESCRIPTION - string
- ;; PROBE - a sexp which runs the actual test
- ;; GRADER - the desired result or a sexp which determines
- ;; how we did
-
- ("bash-complete-join simple"
- (bash-complete-join '("a" "hello" "world" "b" "c"))
- "a hello world b c")
-
- ("bash-complete-join escape quote"
- (bash-complete-join '("a" "hel'lo" "world" "b" "c"))
- "a 'hel'\\''lo' world b c")
-
- ("bash-complete-join escape space"
- (bash-complete-join '("a" "hello world" "b" "c"))
- "a 'hello world' b c")
-
- ("bash-complete-split simple"
- (sz-testutils-with-buffer
- '("a hello world b c")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "hello" "world" "b" "c")))
-
- ("bash-complete-split simple extra spaces"
- (sz-testutils-with-buffer
- '(" a hello \n world \t b \r c ")
- (bash-complete-split 1 (line-end-position 2) 0))
- '(nil . ("a" "hello" "world" "b" "c")))
-
- ("bash-complete-split escaped space"
- (sz-testutils-with-buffer
- '("a hello\\ world b c")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "hello world" "b" "c")))
-
- ("bash-complete-split double quotes"
- (sz-testutils-with-buffer
- '("a \"hello world\" b c")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "hello world" "b" "c")))
-
- ("bash-complete-split double quotes escaped"
- (sz-testutils-with-buffer
- '("a \"-\\\"hello world\\\"-\" b c")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "-\"hello world\"-" "b" "c")))
-
- ("bash-complete-split single quotes"
- (sz-testutils-with-buffer
- '("a \"hello world\" b c")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "hello world" "b" "c")))
-
- ("bash-complete-split single quotes escaped"
- (sz-testutils-with-buffer
- '("a '-\\'hello world\\'-' b c")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "-'hello world'-" "b" "c")))
-
- ("bash-complete-split complex quote mix"
- (sz-testutils-with-buffer
- '("a hel\"lo w\"o'rld b'c d")
- (bash-complete-split 1 (line-end-position) 0))
- '(nil . ("a" "hello world bc" "d")))
-
- ("bash-complete-split cursor at end of word"
- (sz-testutils-with-buffer
- '("a hello world" cursor " b c")
- (bash-complete-split 1 (line-end-position) (point)))
- '(2 . ("a" "hello" "world" "b" "c")))
-
- ("bash-complete-split cursor in the middle of a word"
- (sz-testutils-with-buffer
- '("a hello wo" cursor "rld b c")
- (bash-complete-split 1 (line-end-position) (point)))
- '(2 . ("a" "hello" "world" "b" "c")))
-
- ("bash-complete-split cursor at the beginnig"
- (sz-testutils-with-buffer
- '(" " cursor " a hello world b c")
- (bash-complete-split 1 (line-end-position) (point)))
- '(0 . ("a" "hello" "world" "b" "c")))
-
- ("bash-complete-split cursor in the middle"
- (sz-testutils-with-buffer
- '("a hello " cursor " world b c")
- (bash-complete-split 1 (line-end-position) (point)))
- '(1 . ("a" "hello" "world" "b" "c")))
-
- ("bash-complete-add-to-alist garbage"
- (let ((bash-complete-alist nil))
- (bash-complete-add-to-alist '("just" "some" "garbage")))
- nil)
-
- ("bash-complete-add-to-alist empty"
- (let ((bash-complete-alist nil))
- (bash-complete-add-to-alist '()))
- nil)
-
- ("bash-complete-add-to-alist empty string"
- (let ((bash-complete-alist nil))
- (bash-complete-add-to-alist '("")))
- nil)
-
- ("bash-complete-add-to-alist empty complete"
- (let ((bash-complete-alist nil))
- (bash-complete-add-to-alist '("complete")))
- nil)
-
- ("bash-complete-add-to-alist one command"
- (let ((bash-complete-alist nil))
- (bash-complete-add-to-alist '("complete" "-e" "-F" "_cdargs_aliases"
"cdb")))
- '(("cdb" . ("-e" "-F" "_cdargs_aliases"))))
-
- ("bash-complete-build-alist"
- (sz-testutils-with-buffer
- "
-complete -F _cdargs_aliases cdb
-complete -F complete_projects project
-complete -F complete_projects pro
-complete -F _cdargs_aliases cv
-complete -F _cdargs_aliases cb
-garbage
-"
- (let ((bash-complete-alist '(garbage)))
- (bash-complete-build-alist (current-buffer))))
- '(("cdb" "-F" "_cdargs_aliases")
- ("project" "-F" "complete_projects")
- ("pro" "-F" "complete_projects")
- ("cv" "-F" "_cdargs_aliases")
- ("cb" "-F" "_cdargs_aliases")))
-
- ("bash-complete-quote not necessary"
- (bash-complete-quote "hello")
- "hello")
-
- ("bash-complete-quote space"
- (bash-complete-quote "hello world")
- "'hello world'")
-
- ("bash-complete-quote quote"
- (bash-complete-quote "hell'o")
- "'hell'\\''o'")
-
- ("bash-complete-generate-line no custom completion"
- (let ((bash-complete-alist nil))
- (bash-complete-generate-line "~/test" "hello worl" 7 '("hello" "worl")
1))
- (concat "cd " (expand-file-name "~/test") " ; compgen -o default worl"))
-
- ("bash-complete-generate-line custom completion no function or command"
- (let ((bash-complete-alist '(("zorg" . ("-A" "-G" "*.txt")))))
- (bash-complete-generate-line "/test" "zorg worl" 7 '("zorg" "worl") 1))
- "cd /test ; compgen -A -G '*.txt' -- worl")
-
- ("bash-complete-generate-line custom completion function"
- (let ((bash-complete-alist '(("zorg" . ("-F" "__zorg")))))
- (bash-complete-generate-line "/test" "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-complete-generate-line custom completion command"
- (let ((bash-complete-alist '(("zorg" . ("-C" "__zorg")))))
- (bash-complete-generate-line "/test" "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-complete-trim"
- (mapcar 'bash-complete-trim '(" hello " " world " "x"))
- '("hello" "world" "x"))
-
- ("bash-complete-line-beginning-position start"
- (sz-testutils-with-buffer
- "cd /home/x"
- (bash-complete-line-beginning-position 1))
- 1)
-
- ("bash-complete-line-beginning-position semicolon"
- (sz-testutils-with-buffer
- '("cd /home/x ; " cursor "echo hello")
- (list
- (point)
- (bash-complete-line-beginning-position 1)))
- '(14 14))
-
- ("bash-complete-line-beginning-position &&"
- (sz-testutils-with-buffer
- '("cd /home/x && " cursor "echo hello")
- (list
- (point)
- (bash-complete-line-beginning-position 1)))
- '(15 15))
-
- )))
-
-
-;; Run diagnostics when this module is evaluated or compiled
-;; if and only if the "regress" package is already loaded.
-;; This code will not appear in the compiled (.elc) file
-(eval-when-compile
- (autoload 'regress "regress" "run regression test suites" t)
- (if (featurep 'regress)
- (regress bash-complete-regress)))
-
-;;; bash-complete_test.el ends here
diff --git a/bash-complete.el b/bash-completion.el
similarity index 56%
rename from bash-complete.el
rename to bash-completion.el
index b1a4122cf0..dc9e40a177 100644
--- a/bash-complete.el
+++ b/bash-completion.el
@@ -1,43 +1,49 @@
(require 'comint)
-(defvar bash-complete-prog "bash"
+;;if [[ ( -z "$INSIDE_EMACS" || "$EMACS_BASH_COMPLETE" = "t" ) && -f
/etc/bash_c;;ompletion ]]; then
+;; echo -n "BASH completion..."
+;; . /etc/bash_completion
+;; echo "ON"
+;;fi
+
+(defvar bash-completion-prog "bash"
"Command-line to execute bash")
-(defvar bash-complete-process-timeout 2.5)
-(defvar bash-complete-initial-timeout 30
+(defvar bash-completion-process-timeout 2.5)
+(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,
which typically takes a long time.")
-(defvar bash-complete-process nil
+(defvar bash-completion-process nil
"Bash process object")
-(defvar bash-complete-alist nil
+(defvar bash-completion-alist nil
"Maps from command name to the 'complete' arguments.
For example if the following completion is defined in bash:
complete -F _cdargs_aliases cdb
-the following entry is added to `bash-complete-alist':
+the following entry is added to `bash-completion-alist':
(\"cdb\" . (\"-F\" \"_cdargs\"))
-See `bash-complete-add-to-alist'.
+See `bash-completion-add-to-alist'.
")
-(defun bash-complete-setup ()
+(defun bash-completion-setup ()
(add-hook 'shell-dynamic-complete-functions
- 'bash-complete-dynamic-complete)
+ 'bash-completion-dynamic-complete)
(add-hook 'shell-command-complete-functions
- 'bash-complete-dynamic-complete))
+ 'bash-completion-dynamic-complete))
;;;###autoload
-(defun bash-complete-dynamic-complete ()
+(defun bash-completion-dynamic-complete ()
"Bash completion function for `comint-complete-dynamic-functions'.
Call bash to do the completion."
(when (window-minibuffer-p)
(message "Bash completion..."))
(let* ( (pos (point))
- (start (bash-complete-line-beginning-position))
+ (start (bash-completion-line-beginning-position))
(end (line-end-position))
(line (buffer-substring-no-properties start end))
(wordsplit)
@@ -45,16 +51,16 @@ Call bash to do the completion."
(words)
(stub) )
(save-excursion
- (setq wordsplit (bash-complete-split start end pos))
+ (setq wordsplit (bash-completion-split start end pos))
(setq cword (car wordsplit))
(setq words (cdr wordsplit))
(setq stub (nth cword words)))
(comint-dynamic-simple-complete
stub
- (bash-complete-comm default-directory
+ (bash-completion-comm default-directory
line (- pos start) words cword))))
-(defun bash-complete-line-beginning-position (&optional start)
+(defun bash-completion-line-beginning-position (&optional start)
(save-excursion
(let ((start (or start (comint-line-beginning-position)))
(end (line-end-position)))
@@ -63,22 +69,22 @@ Call bash to do the completion."
(match-end 0)
start))))
-(defun bash-complete-join (words)
+(defun bash-completion-join (words)
"Join WORDS into a shell line, escaped all words with single quotes"
(if words
(mapconcat
- 'bash-complete-quote
+ 'bash-completion-quote
words " ")
""))
-(defun bash-complete-quote (word)
+(defun bash-completion-quote (word)
(if (string-match "^[a-zA-Z0-9_./-]*$" word)
word
(concat "'"
(replace-regexp-in-string "'" "'\\''" word :literal t)
"'")))
-(defun bash-complete-split (start end pos)
+(defun bash-completion-split (start end pos)
"Split LINE like bash would do, keep track of current word at POS.
Return a list containing the words and the number of the word
@@ -86,40 +92,40 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(save-excursion
(goto-char start)
(let ((accum (cons nil nil)))
- (setq accum (bash-complete-split-0 start end pos accum ""))
+ (setq accum (bash-completion-split-0 start end pos accum ""))
(cons (car accum) (nreverse (cdr accum))))))
-(defun bash-complete-split-0 (start end pos accum straccum)
+(defun bash-completion-split-0 (start end pos accum straccum)
(let ( (char-start (char-after))
(quote nil) )
(when (and char-start (or (= char-start ?') (= char-start ?\")))
(forward-char)
(setq quote char-start))
- (bash-complete-split-1 start end pos quote accum straccum)))
+ (bash-completion-split-1 start end pos quote accum straccum)))
-(defun bash-complete-split-1 (start end pos quote accum straccum)
+(defun bash-completion-split-1 (start end pos quote accum straccum)
(let ((local-start (point)))
- (skip-chars-forward (bash-complete-nonsep quote) end)
+ (skip-chars-forward (bash-completion-nonsep quote) end)
(setq straccum (concat straccum (buffer-substring-no-properties
local-start (point)))))
(cond
;; an escaped char, skip, whatever it is
((and (char-before) (= ?\\ (char-before)))
(forward-char)
- (bash-complete-split-1
+ (bash-completion-split-1
start end pos quote
accum
(concat (substring straccum 0 (- (length straccum) 1)) (char-to-string
(char-before)))))
;; opening quote
((and (not quote) (char-after) (or (= ?' (char-after)) (= ?\"
(char-after))))
- (bash-complete-split-0 start end pos accum straccum))
+ (bash-completion-split-0 start end pos accum straccum))
;; closing quote
((and quote (char-after) (= quote (char-after)))
(forward-char)
- (bash-complete-split-0 start end pos accum straccum))
+ (bash-completion-split-0 start end pos accum straccum))
;; space inside a quote
((and quote (char-after) (not (= quote (char-after))))
(forward-char)
- (bash-complete-split-1
+ (bash-completion-split-1
start end pos quote accum
(concat straccum (char-to-string (char-before)))))
;; word end
@@ -130,15 +136,15 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(when (and (not (car accum)) (> pos 0) (<= pos (point)))
(setcar accum (- (length (cdr accum)) 1))))
(if (< (point) end)
- (bash-complete-split-0 (point) end pos accum "")
+ (bash-completion-split-0 (point) end pos accum "")
accum))))
-(defun bash-complete-nonsep (quote)
+(defun bash-completion-nonsep (quote)
(if quote
(concat "^ \t\n\r" (char-to-string quote))
"^ \t\n\r'\""))
-(defun bash-complete-comm (dir line pos words cword)
+(defun bash-completion-comm (dir line pos words cword)
"Set DIR, LINE, POS, WORDS and CWORD, call bash completion, return the
result.
This function starts a separate bash process if necessary, sets up the
@@ -146,18 +152,18 @@ 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-complete-send (concat (bash-complete-generate-line dir line pos words
cword) " 2>/dev/null"))
- (with-current-buffer (bash-complete-buffer)
- (mapcar 'bash-complete-trim (split-string (buffer-string) "\n" t))))
+ (bash-completion-send (concat (bash-completion-generate-line dir line pos
words cword) " 2>/dev/null"))
+ (with-current-buffer (bash-completion-buffer)
+ (mapcar 'bash-completion-trim (split-string (buffer-string) "\n" t))))
-(defun bash-complete-trim (str)
+(defun bash-completion-trim (str)
(if (string-match "^ *\\(.*[^ ]\\) *$" str)
(match-string 1 str)
str))
-(defun bash-complete-require-process ()
- (if (bash-complete-is-running)
- bash-complete-process
+(defun bash-completion-require-process ()
+ (if (bash-completion-is-running)
+ bash-completion-process
;; start process
(let ((process))
(unwind-protect
@@ -165,28 +171,28 @@ The result is a list of candidates, which might be empty."
(setenv "EMACS_BASH_COMPLETE" "t")
(setq process
(start-process
- "*bash-complete*"
- "*bash-complete*"
- bash-complete-prog
+ "*bash-completion*"
+ "*bash-completion*"
+ bash-completion-prog
"--noediting"))
(set-process-query-on-exit-flag process nil)
- (let* ((shell-name (file-name-nondirectory bash-complete-prog))
+ (let* ((shell-name (file-name-nondirectory bash-completion-prog))
(startfile1 (concat "~/.emacs_" shell-name ".sh"))
(startfile2 (concat "~/.emacs.d/init_" shell-name ".sh")))
(cond
((file-exists-p startfile1)
- (message "bash-complete: source %s" startfile1)
+ (message "bash-completion: source %s" startfile1)
(process-send-string process (concat ". " startfile1 "\n")))
((file-exists-p startfile2)
- (message "bash-complete: source %s" startfile2)
+ (message "bash-completion: source %s" startfile2)
(process-send-string process (concat ". " startfile2 "\n")))))
- (bash-complete-send "PS1='\v'" process
bash-complete-initial-timeout)
- (bash-complete-send "function __bash_complete_wrapper { eval
$__BASH_COMPLETE_WRAPPER; }" process)
- (bash-complete-send "complete -p" process)
- (bash-complete-build-alist (process-buffer process))
- (setq bash-complete-process process)
+ (bash-completion-send "PS1='\v'" process
bash-completion-initial-timeout)
+ (bash-completion-send "function __bash_complete_wrapper { eval
$__BASH_COMPLETE_WRAPPER; }" process)
+ (bash-completion-send "complete -p" process)
+ (bash-completion-build-alist (process-buffer process))
+ (setq bash-completion-process process)
(setq process nil)
- bash-complete-process)
+ bash-completion-process)
;; finally
(progn
(setenv "EMACS_BASH_COMPLETE" nil)
@@ -195,14 +201,14 @@ The result is a list of candidates, which might be empty."
(kill-process process)
(error nil))))))))
-(defun bash-complete-generate-line (dir line pos words cword)
+(defun bash-completion-generate-line (dir line pos words cword)
(concat
- (if default-directory (concat "cd " (bash-complete-quote (expand-file-name
dir)) " ; ") "")
+ (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-complete-alist))) )
+ (compgen-args (cdr (assoc command bash-completion-alist))) )
(if (not compgen-args)
;; no custom completion. use default completion
- (bash-complete-join (list "compgen" "-o" "default" (nth cword words)))
+ (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))) )
@@ -211,55 +217,55 @@ The result is a list of candidates, which might be empty."
(setcar function "-F")
(setcar (cdr function) "__bash_complete_wrapper")
(format "__BASH_COMPLETE_WRAPPER=%s compgen %s -- %s"
- (bash-complete-quote (format "COMP_LINE=%s;
COMP_POINT=%s; COMP_CWORD=%s; COMP_WORDS=( %s ); %s \"$@\""
- (bash-complete-quote line)
pos cword (bash-complete-join words)
- (bash-complete-quote
function-name)))
- (bash-complete-join args)
- (bash-complete-quote (nth cword words))))
- (format "compgen %s -- %s" (bash-complete-join args) (nth cword
words))))))))
-
-(defun bash-complete-reset ()
+ (bash-completion-quote (format "COMP_LINE=%s;
COMP_POINT=%s; COMP_CWORD=%s; COMP_WORDS=( %s ); %s \"$@\""
+ (bash-completion-quote
line) pos cword (bash-completion-join words)
+ (bash-completion-quote
function-name)))
+ (bash-completion-join args)
+ (bash-completion-quote (nth cword words))))
+ (format "compgen %s -- %s" (bash-completion-join args) (nth cword
words))))))))
+
+(defun bash-completion-reset ()
(interactive)
- (when (bash-complete-is-running)
- (kill-process bash-complete-process))
- (setq bash-complete-process nil))
+ (when (bash-completion-is-running)
+ (kill-process bash-completion-process))
+ (setq bash-completion-process nil))
-(defun bash-complete-buffer ()
- (process-buffer (bash-complete-require-process)))
+(defun bash-completion-buffer ()
+ (process-buffer (bash-completion-require-process)))
-(defun bash-complete-is-running ()
- (and bash-complete-process (eq 'run (process-status bash-complete-process))))
+(defun bash-completion-is-running ()
+ (and bash-completion-process (eq 'run (process-status
bash-completion-process))))
-(defun bash-complete-send (commandline &optional process timeout)
- (let ((process (or process (bash-complete-require-process)))
- (timeout (or timeout bash-complete-process-timeout)))
+(defun bash-completion-send (commandline &optional process timeout)
+ (let ((process (or process (bash-completion-require-process)))
+ (timeout (or timeout bash-completion-process-timeout)))
(with-current-buffer (process-buffer process)
(erase-buffer)
(process-send-string process (concat commandline "\n"))
(while (not (progn (goto-char 1) (search-forward "\v" nil t)))
(unless (accept-process-output process timeout)
- (error "Timeout while waiting for an answer from bash-complete
process")))
+ (error "Timeout while waiting for an answer from bash-completion
process")))
(goto-char (point-max))
(delete-backward-char 1))))
-(defun bash-complete-build-alist (buffer)
- "Build `bash-complete-alist' with the content of BUFFER.
+(defun bash-completion-build-alist (buffer)
+ "Build `bash-completion-alist' with the content of BUFFER.
BUFFER should contains the output of:
complete -p
-Return `bash-complete-alist'."
+Return `bash-completion-alist'."
(with-current-buffer buffer
(save-excursion
- (setq bash-complete-alist nil)
+ (setq bash-completion-alist nil)
(goto-char (point-max))
(while (= 0 (forward-line -1))
- (bash-complete-add-to-alist
- (cdr (bash-complete-split (line-beginning-position)
(line-end-position) 0))))))
- bash-complete-alist)
+ (bash-completion-add-to-alist
+ (cdr (bash-completion-split (line-beginning-position)
(line-end-position) 0))))))
+ bash-completion-alist)
-(defun bash-complete-add-to-alist (words)
- "Add split 'complete' line WORDS to `bash-complete-add-to-alist'.
+(defun bash-completion-add-to-alist (words)
+ "Add split 'complete' line WORDS to `bash-completion-add-to-alist'.
This parses the complete command-line arguments as output by
complete -p
@@ -268,13 +274,13 @@ This does not work on arbitrary 'complete' calls.
Lines that do not start with the word complete are skipped.
-Return `bash-complete-alist'."
+Return `bash-completion-alist'."
(when (string= "complete" (car words))
(let* ( (reverse-wordsrest (nreverse (cdr words)))
(command (car reverse-wordsrest))
(options (nreverse (cdr reverse-wordsrest))) )
(when (and command options)
- (push (cons command options) bash-complete-alist))))
- bash-complete-alist)
+ (push (cons command options) bash-completion-alist))))
+ bash-completion-alist)
-(provide 'bash-complete)
\ No newline at end of file
+(provide 'bash-completion)
\ No newline at end of file
diff --git a/bash-completion_test.el b/bash-completion_test.el
new file mode 100644
index 0000000000..fb188a14fa
--- /dev/null
+++ b/bash-completion_test.el
@@ -0,0 +1,227 @@
+;;; bash-completion_test.el --- Tests bash-completion.el
+
+
+;;; Commentary:
+;;
+;; This file defines `bash-completion-regress' and run the
+;; regression tests if and only if regress is already imported.
+;;
+
+;;; History:
+;;
+
+;;; Code:
+(eval-when-compile
+ ;; force reload
+ (load-library "~/.emacs.d/bash-completion.el")
+
+ (require 'sz-testutils)
+
+ ;; This code will not appear in the compiled (.elc) file
+ (put 'bash-completion-regress 'regression-suite t)
+ (setq bash-completion-regress
+ '("bash-completion-regress"
+ ;; Each test in the suite is of the form:
+ ;; ([description] probe grader)
+ ;; DESCRIPTION - string
+ ;; PROBE - a sexp which runs the actual test
+ ;; GRADER - the desired result or a sexp which determines
+ ;; how we did
+
+ ("bash-completion-join simple"
+ (bash-completion-join '("a" "hello" "world" "b" "c"))
+ "a hello world b c")
+
+ ("bash-completion-join escape quote"
+ (bash-completion-join '("a" "hel'lo" "world" "b" "c"))
+ "a 'hel'\\''lo' world b c")
+
+ ("bash-completion-join escape space"
+ (bash-completion-join '("a" "hello world" "b" "c"))
+ "a 'hello world' b c")
+
+ ("bash-completion-split simple"
+ (sz-testutils-with-buffer
+ '("a hello world b c")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-split simple extra spaces"
+ (sz-testutils-with-buffer
+ '(" a hello \n world \t b \r c ")
+ (bash-completion-split 1 (line-end-position 2) 0))
+ '(nil . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-split escaped space"
+ (sz-testutils-with-buffer
+ '("a hello\\ world b c")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "hello world" "b" "c")))
+
+ ("bash-completion-split double quotes"
+ (sz-testutils-with-buffer
+ '("a \"hello world\" b c")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "hello world" "b" "c")))
+
+ ("bash-completion-split double quotes escaped"
+ (sz-testutils-with-buffer
+ '("a \"-\\\"hello world\\\"-\" b c")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "-\"hello world\"-" "b" "c")))
+
+ ("bash-completion-split single quotes"
+ (sz-testutils-with-buffer
+ '("a \"hello world\" b c")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "hello world" "b" "c")))
+
+ ("bash-completion-split single quotes escaped"
+ (sz-testutils-with-buffer
+ '("a '-\\'hello world\\'-' b c")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "-'hello world'-" "b" "c")))
+
+ ("bash-completion-split complex quote mix"
+ (sz-testutils-with-buffer
+ '("a hel\"lo w\"o'rld b'c d")
+ (bash-completion-split 1 (line-end-position) 0))
+ '(nil . ("a" "hello world bc" "d")))
+
+ ("bash-completion-split cursor at end of word"
+ (sz-testutils-with-buffer
+ '("a hello world" cursor " b c")
+ (bash-completion-split 1 (line-end-position) (point)))
+ '(2 . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-split cursor in the middle of a word"
+ (sz-testutils-with-buffer
+ '("a hello wo" cursor "rld b c")
+ (bash-completion-split 1 (line-end-position) (point)))
+ '(2 . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-split cursor at the beginnig"
+ (sz-testutils-with-buffer
+ '(" " cursor " a hello world b c")
+ (bash-completion-split 1 (line-end-position) (point)))
+ '(0 . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-split cursor in the middle"
+ (sz-testutils-with-buffer
+ '("a hello " cursor " world b c")
+ (bash-completion-split 1 (line-end-position) (point)))
+ '(1 . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-add-to-alist garbage"
+ (let ((bash-completion-alist nil))
+ (bash-completion-add-to-alist '("just" "some" "garbage")))
+ nil)
+
+ ("bash-completion-add-to-alist empty"
+ (let ((bash-completion-alist nil))
+ (bash-completion-add-to-alist '()))
+ nil)
+
+ ("bash-completion-add-to-alist empty string"
+ (let ((bash-completion-alist nil))
+ (bash-completion-add-to-alist '("")))
+ nil)
+
+ ("bash-completion-add-to-alist empty complete"
+ (let ((bash-completion-alist nil))
+ (bash-completion-add-to-alist '("complete")))
+ nil)
+
+ ("bash-completion-add-to-alist one command"
+ (let ((bash-completion-alist nil))
+ (bash-completion-add-to-alist '("complete" "-e" "-F" "_cdargs_aliases"
"cdb")))
+ '(("cdb" . ("-e" "-F" "_cdargs_aliases"))))
+
+ ("bash-completion-build-alist"
+ (sz-testutils-with-buffer
+ "
+complete -F _cdargs_aliases cdb
+complete -F complete_projects project
+complete -F complete_projects pro
+complete -F _cdargs_aliases cv
+complete -F _cdargs_aliases cb
+garbage
+"
+ (let ((bash-completion-alist '(garbage)))
+ (bash-completion-build-alist (current-buffer))))
+ '(("cdb" "-F" "_cdargs_aliases")
+ ("project" "-F" "complete_projects")
+ ("pro" "-F" "complete_projects")
+ ("cv" "-F" "_cdargs_aliases")
+ ("cb" "-F" "_cdargs_aliases")))
+
+ ("bash-completion-quote not necessary"
+ (bash-completion-quote "hello")
+ "hello")
+
+ ("bash-completion-quote space"
+ (bash-completion-quote "hello world")
+ "'hello world'")
+
+ ("bash-completion-quote quote"
+ (bash-completion-quote "hell'o")
+ "'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))
+ (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))
+ "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))
+ "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))
+ "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"
+ (mapcar 'bash-completion-trim '(" hello " " world " "x"))
+ '("hello" "world" "x"))
+
+ ("bash-completion-line-beginning-position start"
+ (sz-testutils-with-buffer
+ "cd /home/x"
+ (bash-completion-line-beginning-position 1))
+ 1)
+
+ ("bash-completion-line-beginning-position semicolon"
+ (sz-testutils-with-buffer
+ '("cd /home/x ; " cursor "echo hello")
+ (list
+ (point)
+ (bash-completion-line-beginning-position 1)))
+ '(14 14))
+
+ ("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))
+
+ )))
+
+
+;; Run diagnostics when this module is evaluated or compiled
+;; if and only if the "regress" package is already loaded.
+;; This code will not appear in the compiled (.elc) file
+(eval-when-compile
+ (autoload 'regress "regress" "run regression test suites" t)
+ (if (featurep 'regress)
+ (regress bash-completion-regress)))
+
+;;; bash-completion_test.el ends here
- [nongnu] elpa/bash-completion e95867c993 256/313: completion-table-with-cache captures and restore buffer and variables., (continued)
- [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
- [nongnu] elpa/bash-completion e81c478032 020/313: bash-complete -> bash-completion,
ELPA Syncer <=
- [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, 2022/12/03
- [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