branch: elpa/bash-completion
commit e077918429f33d3bbdc86d1b619e915d59b56e04
Author: Stephane Zermatten <[email protected]>
Commit: Stephane Zermatten <[email protected]>
Remove support for Bash 3.
This patch removes workarounds that were necessary to support old-style
Bash 3 command completion.
---
bash-completion.el | 138 ++++++++++++++-----------------
test/bash-completion-integration-test.el | 95 ++++++++++-----------
test/bash-completion-test.el | 51 +++++-------
3 files changed, 126 insertions(+), 158 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 3da7307e1b..bdd84ef3ac 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -149,7 +149,7 @@ will be started to do completion."
This should be either an absolute path to the BASH executable or
the name of the bash command if it is on Emacs' PATH. This should
-point to a recent version of BASH, 3 or 4, with support for
+point to a recent version of BASH 4 or 5, with support for
command-line completion.
This variable is only used when creating separate processes for
@@ -354,74 +354,62 @@ returned."
(defun bash-completion--setup-bash-common (process)
"Setup PROCESS to be ready for completion."
- (let (bash-major-version)
- (bash-completion-send "complete -p" process)
- (process-put process 'complete-p
- (bash-completion-build-alist (bash-completion--get-buffer
process)))
- (bash-completion-send "echo -n ${BASH_VERSINFO[0]}" process)
- (setq bash-major-version
- (with-current-buffer (bash-completion--get-buffer process)
- (string-to-number (buffer-substring-no-properties
- (point-min) (point-max)))))
- (bash-completion-send
- (concat "function __emacs_complete_wrapper {"
- (if (>= bash-major-version 4)
- " COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\";"
- "")
- " eval $__EMACS_COMPLETE_WRAPPER;"
- " n=$?;"
- " if [[ $n = 124 ]]; then"
- (bash-completion--side-channel-data "wrapped-status" "124")
- " return 1; "
- " fi; "
- (when (>= bash-major-version 4)
- (concat
- " if [[ -n \"${_EMACS_COMPOPT}\" ]]; then"
- (bash-completion--side-channel-data "compopt"
"${_EMACS_COMPOPT}")
- " fi;"))
- " return $n;"
- "}")
- process)
- (if (>= bash-major-version 4)
- (bash-completion-send
- (concat
- "function compopt {"
- " command compopt \"$@\" 2>/dev/null;"
- " ret=$?; "
- " if [[ $ret == 1 && \"$*\" = *\"-o nospace\"* ]]; then"
- " _EMACS_COMPOPT='-o nospace';"
- " return 0;"
- " fi;"
- " if [[ $ret == 1 && \"$*\" = *\"+o nospace\"* ]]; then"
- " _EMACS_COMPOPT='+o nospace';"
- " return 0;"
- " fi;"
- " return $ret; "
- "}")
- process))
-
- ;; some bash completion functions use quote_readline
- ;; to double-quote strings - which compgen understands
- ;; but only in some environment. disable this dreadful
- ;; business to get a saner way of handling spaces.
- ;; Noticed in bash_completion v1.872.
- (bash-completion-send "function quote_readline { echo \"$1\"; }" process)
-
- (bash-completion-send "echo -n ${COMP_WORDBREAKS}" process)
- (process-put process 'wordbreaks
- (with-current-buffer (bash-completion--get-buffer process)
- (buffer-substring-no-properties
- (point-min) (point-max))))
- (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))
- (and (search-forward "completion-ignore-case on" nil
'noerror) t))))
-
- (process-put process 'setup-done t)))
+ (bash-completion-send "complete -p" process)
+ (process-put process 'complete-p
+ (bash-completion-build-alist (bash-completion--get-buffer
process)))
+ (bash-completion-send
+ (concat "function __emacs_complete_wrapper {"
+ " COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\";"
+ " eval $__EMACS_COMPLETE_WRAPPER;"
+ " n=$?;"
+ " if [[ $n = 124 ]]; then"
+ (bash-completion--side-channel-data "wrapped-status" "124")
+ " return 1; "
+ " fi; "
+ " if [[ -n \"${_EMACS_COMPOPT}\" ]]; then"
+ (bash-completion--side-channel-data "compopt" "${_EMACS_COMPOPT}")
+ " fi;"
+ " return $n;"
+ "}")
+ process)
+ (bash-completion-send
+ (concat
+ "function compopt {"
+ " command compopt \"$@\" 2>/dev/null;"
+ " ret=$?; "
+ " if [[ $ret == 1 && \"$*\" = *\"-o nospace\"* ]]; then"
+ " _EMACS_COMPOPT='-o nospace';"
+ " return 0;"
+ " fi;"
+ " if [[ $ret == 1 && \"$*\" = *\"+o nospace\"* ]]; then"
+ " _EMACS_COMPOPT='+o nospace';"
+ " return 0;"
+ " fi;"
+ " return $ret; "
+ "}")
+ process)
+
+ ;; some bash completion functions use quote_readline
+ ;; to double-quote strings - which compgen understands
+ ;; but only in some environment. disable this dreadful
+ ;; business to get a saner way of handling spaces.
+ ;; Noticed in bash_completion v1.872.
+ (bash-completion-send "function quote_readline { echo \"$1\"; }" process)
+
+ (bash-completion-send "echo -n ${COMP_WORDBREAKS}" process)
+ (process-put process 'wordbreaks
+ (with-current-buffer (bash-completion--get-buffer process)
+ (buffer-substring-no-properties
+ (point-min) (point-max))))
+
+ (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))
+ (and (search-forward "completion-ignore-case on" nil
'noerror) t))))
+
+ (process-put process 'setup-done t))
;;; Inline functions
@@ -544,8 +532,7 @@ Returns (list stub-start stub-end completions) with
(setq process (bash-completion--get-process)))
(let* ((comp (bash-completion--parse
comp-start comp-pos
- (process-get process 'wordbreaks)
- (process-get process 'bash-major-version)))
+ (process-get process 'wordbreaks)))
(stub-start (bash-completion--stub-start comp)))
(bash-completion--customize comp process)
@@ -597,7 +584,7 @@ functions adds single quotes around it and return the
result."
(replace-regexp-in-string "'" "'\\''" word nil t)
"'"))))
-(defun bash-completion--parse (comp-start comp-pos wordbreaks
bash-major-version)
+(defun bash-completion--parse (comp-start comp-pos wordbreaks)
"Process a command from COMP-START to COMP-POS.
WORDBREAK is the value of COMP_WORDBREAKS to use for this completion,
@@ -605,8 +592,7 @@ usually taken from the current process.
Returns a completion struct."
(let* ((all-tokens (bash-completion-tokenize
- comp-start comp-pos (if (>= bash-major-version 4)
- wordbreaks "")))
+ comp-start comp-pos wordbreaks))
(line-tokens (bash-completion-parse-current-command all-tokens))
(first-token (car line-tokens))
(last-token (car (last line-tokens)))
@@ -629,9 +615,6 @@ Returns a completion struct."
parsed-stub ""
words (append words '(""))
rebuilt-line (buffer-substring-no-properties start comp-pos))
- (if (< bash-major-version 4)
- (setq last-token (car (last (bash-completion-tokenize
- start comp-pos wordbreaks)))))
(setq stub-start (car (bash-completion-tokenize-get-range last-token))
parsed-stub (bash-completion-tokenize-get-str last-token)
unparsed-stub (buffer-substring-no-properties stub-start comp-pos)
@@ -1588,7 +1571,6 @@ Return the status code of the command, as a number."
(princ "Please retry\n\n")))
(bash-completion--debug-print-info 'use-separate-processes)
- (bash-completion--debug-print-procinfo 'bash-major-version)
(bash-completion--debug-print 'emacs-version emacs-version)
(bash-completion--debug-print-procinfo 'completion-ignore-case)
(bash-completion--debug-print-info 'context)
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index c044782d65..cb5671ed0b 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -105,10 +105,6 @@
(kill-process (get-buffer-process shell-buffer)))
(kill-buffer shell-buffer)))))
-(defun bash-completion_test-bash-major-version ()
- "Return the major version of the bash process."
- (process-get (bash-completion--get-process) 'bash-major-version))
-
(defun bash-completion_test-complete (complete-me)
"Complete COMPLETE-ME and returns the resulting string."
(goto-char (point-max))
@@ -347,11 +343,10 @@ across Emacs version."
"}\n"
"complete -D -F _default\n")
use-separate-process
- (when (>= (bash-completion_test-bash-major-version) 4)
- (should (equal "dosomething dummy "
- (bash-completion_test-complete "dosomething du")))
- (should (equal "dosomethingelse du"
- (bash-completion_test-complete "dosomethingelse du"))))))
+ (should (equal "dosomething dummy "
+ (bash-completion_test-complete "dosomething du")))
+ (should (equal "dosomethingelse du"
+ (bash-completion_test-complete "dosomethingelse du")))))
(ert-deftest bash-completion-integration-bash-4-compopt ()
(bash-completion_test-with-shell-harness
@@ -377,26 +372,25 @@ across Emacs version."
"complete -F _sometimes_nospace sometimes_nospace\n"
"complete -F _sometimes_not_nospace -o nospace sometimes_not_nospace\n")
t ; use-separate-process
- (when (>= (bash-completion_test-bash-major-version) 4)
+ (should (equal
+ "sometimes_nospace dummy "
+ (bash-completion_test-complete "sometimes_nospace du")))
+ (should (equal
+ "sometimes_nospace dummyo"
+ (bash-completion_test-complete "sometimes_nospace dum")))
+ (should (equal
+ "sometimes_not_nospace dummy"
+ (bash-completion_test-complete "sometimes_not_nospace du")))
+ (should (equal
+ "sometimes_not_nospace dummyo "
+ (bash-completion_test-complete "sometimes_not_nospace dum")))
+ (let ((bash-completion-nospace t)) ;; never nospace
(should (equal
- "sometimes_nospace dummy "
+ "sometimes_nospace dummy"
(bash-completion_test-complete "sometimes_nospace du")))
(should (equal
- "sometimes_nospace dummyo"
- (bash-completion_test-complete "sometimes_nospace dum")))
- (should (equal
- "sometimes_not_nospace dummy"
- (bash-completion_test-complete "sometimes_not_nospace du")))
- (should (equal
- "sometimes_not_nospace dummyo "
- (bash-completion_test-complete "sometimes_not_nospace dum")))
- (let ((bash-completion-nospace t)) ;; never nospace
- (should (equal
- "sometimes_nospace dummy"
- (bash-completion_test-complete "sometimes_nospace du")))
- (should (equal
- "sometimes_not_nospace dummyo"
- (bash-completion_test-complete "sometimes_not_nospace
dum")))))))
+ "sometimes_not_nospace dummyo"
+ (bash-completion_test-complete "sometimes_not_nospace dum"))))))
(ert-deftest bash-completion-integration-bash-4-substring-completion ()
(bash-completion_test-with-shell-harness
@@ -460,31 +454,30 @@ across Emacs version."
(make-directory "libs")
(make-directory "Library")
(bash-completion_test-with-shell
- (when (>= (bash-completion_test-bash-major-version) 4)
- ;; Case insensitive completion is done by compgen which, under
- ;; bash 4, respects the case sensitivity settings set in
- ;; .inputrc.
- (should (equal "ls some/" (bash-completion_test-complete "ls so")))
- (should (equal "ls some/" (bash-completion_test-complete "ls So")))
- (should (equal "ls Uppercase/" (bash-completion_test-complete "ls Up")))
- (should (equal "ls Uppercase/" (bash-completion_test-complete "ls up")))
-
- (should (equal "ls libs/" (bash-completion_test-complete "ls li")))
- (should (equal "ls libs/" (bash-completion_test-complete "ls Li")))
-
- (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 (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")))
-
- ;; 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")))))))
+ ;; Case insensitive completion is done by compgen which, under
+ ;; bash 4, respects the case sensitivity settings set in
+ ;; .inputrc.
+ (should (equal "ls some/" (bash-completion_test-complete "ls so")))
+ (should (equal "ls some/" (bash-completion_test-complete "ls So")))
+ (should (equal "ls Uppercase/" (bash-completion_test-complete "ls Up")))
+ (should (equal "ls Uppercase/" (bash-completion_test-complete "ls up")))
+
+ (should (equal "ls libs/" (bash-completion_test-complete "ls li")))
+ (should (equal "ls libs/" (bash-completion_test-complete "ls Li")))
+
+ (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 (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")))
+
+ ;; 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
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index 30b6a52847..7d477d8f79 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -156,7 +156,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"a hello world"
- (bash-completion--parse (point-min) 14 wordbreaks 3))))
+ (bash-completion--parse (point-min) 14 wordbreaks))))
;; some words separated by spaces, cursor after the last space
(should (equal
@@ -170,21 +170,21 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"a hello "
- (bash-completion--parse (point-min) 9 wordbreaks 3))))
+ (bash-completion--parse (point-min) 9 wordbreaks))))
;; complex multi-command line
(should (equal
(bash-completion--make
- :line "make -"
- :cword 1
- :words '("make" "-")
+ :line "ZORG=t make -"
+ :cword 4
+ :words '("ZORG" "=" "t" "make" "-")
:stub-start 27
:stub "-"
:unparsed-stub "-"
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd /var/tmp ; ZORG=t make -"
- (bash-completion--parse (point-min) 28 wordbreaks 3))))
+ (bash-completion--parse (point-min) 28 wordbreaks))))
;; multiple commands on multiple lines
(should (equal
@@ -198,7 +198,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd /var/tmp\nmake -"
- (bash-completion--parse (point-min) (point-max) wordbreaks 3))))
+ (bash-completion--parse (point-min) (point-max) wordbreaks))))
;; pipe
(should (equal
@@ -212,7 +212,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"ls /var/tmp | sort -"
- (bash-completion--parse (point-min) 21 wordbreaks 3))))
+ (bash-completion--parse (point-min) 21 wordbreaks))))
;; escaped semicolon
(should (equal
@@ -226,35 +226,35 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"find -name '*.txt' -exec echo {} ';' -"
- (bash-completion--parse (point-min) 39 wordbreaks 3))))
+ (bash-completion--parse (point-min) 39 wordbreaks))))
;; at var assignment
(should (equal
(bash-completion--make
- :line "ZORG=t"
- :cword 0
- :words '("ZORG=t")
+ :line "A=f ZORG=t"
+ :cword 5
+ :words '("A" "=" "f" "ZORG" "=" "t")
:stub-start 24
:stub "t"
:unparsed-stub "t"
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd /var/tmp ; A=f ZORG=t"
- (bash-completion--parse (point-min) 25 wordbreaks 3))))
+ (bash-completion--parse (point-min) 25 wordbreaks))))
;; stub is a subset of last word (bash 3)
(should (equal
(bash-completion--make
:line "export PATH=/bin:/usr/bi"
- :cword 1
- :words '("export" "PATH=/bin:/usr/bi")
+ :cword 5
+ :words '("export" "PATH" "=" "/bin" ":" "/usr/bi")
:stub-start 18
:stub "/usr/bi"
:unparsed-stub "/usr/bi"
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"export PATH=/bin:/usr/bi"
- (bash-completion--parse (point-min) (point-max) wordbreaks 3))))
+ (bash-completion--parse (point-min) (point-max) wordbreaks))))
;; last word is split according to COMP_WORDBREAKS (bash 4)
(should (equal
@@ -268,7 +268,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"export PATH=/bin:/usr/bi"
- (bash-completion--parse (point-min) (point-max) wordbreaks 4))))
+ (bash-completion--parse (point-min) (point-max) wordbreaks))))
;; with escaped quote
(should (equal
@@ -282,7 +282,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd /vcr/shows/Dexter\\'s"
- (bash-completion--parse (point-min) 24 wordbreaks 3))))
+ (bash-completion--parse (point-min) 24 wordbreaks))))
;; with escaped quote, bash 4
(should (equal
@@ -296,7 +296,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd /vcr/shows/Dexter\\'s"
- (bash-completion--parse (point-min) 24 wordbreaks 4))))
+ (bash-completion--parse (point-min) 24 wordbreaks))))
;; with double quote
(should (equal
@@ -311,7 +311,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd \"/vcr/shows/Dexter's"
- (bash-completion--parse (point-min) 24 wordbreaks 3))))
+ (bash-completion--parse (point-min) 24 wordbreaks))))
;; with single quote
(should (equal
@@ -326,7 +326,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
"cd '/vcr/shows/Dexter'\\''s"
- (bash-completion--parse (point-min) 27 wordbreaks 3))))
+ (bash-completion--parse (point-min) 27 wordbreaks))))
;; just one space, cursor after it
(should (equal
@@ -340,7 +340,7 @@ The return value is the one returned by BODY."
:wordbreaks wordbreaks)
(bash-completion-test-with-buffer
" "
- (bash-completion--parse (point-min) 2 wordbreaks 3))))))
+ (bash-completion--parse (point-min) 2 wordbreaks))))))
(ert-deftest bash-completion-build-alist ()
(should (equal
@@ -460,8 +460,6 @@ garbage
(eq 'complete-p prop))
'((nil "-F" "__default")
("zorg" "-F" "__zorg")))
- ((and (eq 'process process)
- (eq 'bash-major-version prop)) 3)
((and (eq 'process process)
(eq 'wordbreaks prop)) "\"'@><=;|&(:")
(t (error "unexpected: (process-get %s %s)"
@@ -929,7 +927,6 @@ before calling `bash-completion-dynamic-complete-nocomint'.
(bash-completion-alist '())
(bash-completion-use-separate-processes t)
(wordbreaks "@><=;|&(:")
- (bash-major-version 3)
(bash-completion-nospace nil))
(let ((--process-buffer)
(--test-buffer)
@@ -945,8 +942,6 @@ before calling `bash-completion-dynamic-complete-nocomint'.
(lambda (process prop value)
(cond ((and (eq 'process process) (eq 'complete-p
prop))
(setq bash-completion-alist value))
- ((and (eq 'process process) (eq
'bash-major-version prop))
- (setq bash-major-version value))
(t (error "unexpected: (process-put %s %s)"
process prop)))))
((symbol-function 'process-get)
(lambda (process prop)
@@ -955,8 +950,6 @@ before calling `bash-completion-dynamic-complete-nocomint'.
bash-completion-alist)
((and (eq 'process process) (eq 'wordbreaks prop))
wordbreaks)
- ((and (eq 'process process) (eq 'bash-major-version
prop))
- bash-major-version)
((and (eq 'process process) (eq
'completion-ignore-case prop))
completion-ignore-case)
(t (error "unexpected call")))))