branch: elpa/bash-completion
commit 7ce100b7eb9df4317b075f045fafa5ceb2ab439d
Author: Stephane Zermatten <[email protected]>
Commit: Stephane Zermatten <[email protected]>
cursor position
---
bash-complete.el | 6 ++++--
bash-complete_test.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/bash-complete.el b/bash-complete.el
index 8af7b5619b..d12720c2b0 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -77,9 +77,11 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(concat straccum (char-to-string (char-before)))))
;; word end
(t
- (when straccum
- (setcdr accum (cons straccum (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))))
(if (< (point) end)
(bash-complete-split-0 (point) end pos accum "")
accum))))
diff --git a/bash-complete_test.el b/bash-complete_test.el
index d3403a7343..ed832ec4b4 100644
--- a/bash-complete_test.el
+++ b/bash-complete_test.el
@@ -34,6 +34,12 @@
(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")
@@ -70,6 +76,30 @@
(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")))
+
)))