branch: elpa/bash-completion
commit 53f2c5d30ee1426bc537deba58749d92981abb4c
Author: Stephane Zermatten <[email protected]>
Commit: Stephane Zermatten <[email protected]>
parse complete -p output
---
bash-complete.el | 18 +++++++++++++++++-
bash-complete_test.el | 18 ++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/bash-complete.el b/bash-complete.el
index 83c22ccd49..0a2567d88d 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -62,7 +62,7 @@ at POS, the current word: ( (word1 word2 ...) . wordnum )"
(defun bash-complete-split-0 (start end pos accum straccum)
(let ( (char-start (char-after))
(quote nil) )
- (when (or (= char-start ?') (= char-start ?\"))
+ (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)))
@@ -119,6 +119,22 @@ The result is a list of candidates, which might be empty."
)
+(defun bash-complete-build-alist (buffer)
+ "Build `bash-complete-alist' with the content of BUFFER.
+
+BUFFER should contains the output of:
+ complete -p
+
+Return `bash-complete-alist'."
+ (with-current-buffer buffer
+ (save-excursion
+ (setq bash-complete-alist nil)
+ (end-of-buffer)
+ (while (= 0 (forward-line -1))
+ (bash-complete-add-to-alist
+ (cdr (bash-complete-split (line-beginning-position)
(line-end-position) 0))))))
+ bash-complete-alist)
+
(defun bash-complete-add-to-alist (words)
"Add split 'complete' line WORDS to `bash-complete-add-to-alist'.
diff --git a/bash-complete_test.el b/bash-complete_test.el
index ec4844c732..31b17544db 100644
--- a/bash-complete_test.el
+++ b/bash-complete_test.el
@@ -133,6 +133,24 @@
(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")))
+
)))