branch: elpa/bash-completion
commit aa9bea48ba60c08ca0187e3b515f099d3740604f
Author: Stephane Zermatten <[email protected]>
Commit: Stephane Zermatten <[email protected]>
fix position
---
bash-completion.el | 21 ++++++++++++++-------
bash-completion_test.el | 36 ++++++++++++++++++++++--------------
2 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 43fe828745..9f1bbd9662 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -58,9 +58,10 @@ Call bash to do the completion."
(setq cword (car wordsplit))
(setq words (cdr wordsplit))
(setq stub (nth cword words)))
- (comint-dynamic-simple-complete
- stub
- (bash-completion-comm line (- pos start) words cword))))
+ (let ((completions (bash-completion-comm line (- pos start) words cword)))
+ (comint-dynamic-simple-complete
+ stub
+ completions))))
(defun bash-completion-line-beginning-position (&optional start)
(save-excursion
@@ -95,6 +96,9 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(goto-char start)
(let ((accum (cons nil nil)))
(setq accum (bash-completion-split-0 start end pos accum ""))
+ (when (and (not (null pos)) (null (car accum)))
+ (setcar accum (length (cdr accum)))
+ (setcdr accum (cons "" (cdr accum))))
(cons (car accum) (nreverse (cdr accum))))))
(defun bash-completion-split-0 (start end pos accum straccum)
@@ -107,6 +111,9 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(defun bash-completion-split-1 (start end pos quote accum straccum)
(let ((local-start (point)))
+ (when (and (null (car accum)) (not (null pos)) (<= pos local-start))
+ (setcar accum (length (cdr accum)))
+ (setcdr accum (cons "" (cdr accum))))
(skip-chars-forward (bash-completion-nonsep quote) end)
(setq straccum (concat straccum (buffer-substring-no-properties
local-start (point)))))
(cond
@@ -132,11 +139,11 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(concat straccum (char-to-string (char-before)))))
;; word end
(t
+ (when (and (null (car accum)) (not (null pos)) (<= pos (point)))
+ (setcar accum (length (cdr accum))))
(skip-chars-forward " \t\n\r" end)
(when (> (length straccum) 0)
- (setcdr accum (cons straccum (cdr accum)))
- (when (and (not (car accum)) (> pos 0) (<= pos (point)))
- (setcar accum (- (length (cdr accum)) 1))))
+ (setcdr accum (cons straccum (cdr accum))))
(if (< (point) end)
(bash-completion-split-0 (point) end pos accum "")
accum))))
@@ -270,7 +277,7 @@ Return `bash-completion-alist'."
(goto-char (point-max))
(while (= 0 (forward-line -1))
(bash-completion-add-to-alist
- (cdr (bash-completion-split (line-beginning-position)
(line-end-position) 0))))))
+ (cdr (bash-completion-split (line-beginning-position)
(line-end-position) nil))))))
bash-completion-alist)
(defun bash-completion-add-to-alist (words)
diff --git a/bash-completion_test.el b/bash-completion_test.el
index 64ef657b90..046368853c 100644
--- a/bash-completion_test.el
+++ b/bash-completion_test.el
@@ -43,49 +43,49 @@
("bash-completion-split simple"
(sz-testutils-with-buffer
'("a hello world b c")
- (bash-completion-split 1 (line-end-position) 0))
+ (bash-completion-split 1 (line-end-position) nil))
'(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))
+ (bash-completion-split 1 (line-end-position 2) nil))
'(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))
+ (bash-completion-split 1 (line-end-position) nil))
'(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))
+ (bash-completion-split 1 (line-end-position) nil))
'(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))
+ (bash-completion-split 1 (line-end-position) nil))
'(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))
+ (bash-completion-split 1 (line-end-position) nil))
'(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))
+ (bash-completion-split 1 (line-end-position) nil))
'(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))
+ (bash-completion-split 1 (line-end-position) nil))
'(nil . ("a" "hello world bc" "d")))
("bash-completion-split cursor at end of word"
@@ -104,13 +104,25 @@
(sz-testutils-with-buffer
'(" " cursor " a hello world b c")
(bash-completion-split 1 (line-end-position) (point)))
- '(0 . ("a" "hello" "world" "b" "c")))
+ '(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")))
+ '(2 . ("a" "hello" "" "world" "b" "c")))
+
+ ("bash-completion-split cursor at end"
+ (sz-testutils-with-buffer
+ '("a hello world b c" cursor)
+ (bash-completion-split 1 (line-end-position) (point)))
+ '(4 . ("a" "hello" "world" "b" "c")))
+
+ ("bash-completion-split cursor after end"
+ (sz-testutils-with-buffer
+ '("a hello world b c " cursor)
+ (bash-completion-split 1 (line-end-position) (point)))
+ '(5 . ("a" "hello" "world" "b" "c" "")))
("bash-completion-add-to-alist garbage"
(let ((bash-completion-alist nil))
@@ -191,10 +203,6 @@ garbage
(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"
- (mapcar 'bash-completion-trim '(" hello " " world " "x"))
- '("hello" "world" "x"))
-
("bash-completion-line-beginning-position start"
(sz-testutils-with-buffer
"cd /home/x"