[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion f7bfc68ea2 001/313: bash completion
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion f7bfc68ea2 001/313: bash completion |
Date: |
Sat, 3 Dec 2022 10:58:58 -0500 (EST) |
branch: elpa/bash-completion
commit f7bfc68ea28525f1ff4428d6c1859f6d1c10ac17
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
bash completion
---
bash-complete.el | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/bash-complete.el b/bash-complete.el
new file mode 100644
index 0000000000..b15daea8d9
--- /dev/null
+++ b/bash-complete.el
@@ -0,0 +1,91 @@
+
+(defun bash-complete-dynamic-complete ()
+ "Bash completion function for `comint-complete-dynamic-functions'.
+
+Call bash to do the completion."
+ (when (comint-match-partial-filename)
+ (unless (window-minibuffer-p (selected-window))
+ (message "Bash completion..."))
+ (bash-complete-dynamic-complete-0)))
+
+(defun bash-complete-dynamic-complete-0 ()
+ (save-excursion
+ (let* ( (pos (point))
+ (start (comint-line-beginning-position))
+ (end (line-end-position))
+ (line (buffer-substring-no-properties start end))
+ (wordsplit (bash-complete-split start end pos))
+ (words (car wordsplit))
+ (cword (cdr wordsplit))
+ (stub (nth cword words)) )
+ (comint-simple-complete stub
+ (bash-complete-comm
+ line pos words cword)))))
+
+(defun bash-complete-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
+at POS, the current word: ( (word1 word2 ...) . wordnum )"
+ (save-excursion
+ (goto-char start)
+ (nreverse (bash-complete-split-0 start end pos nil))))
+
+(defun bash-complete-split-0 (start end pos accum)
+ (let ( (char-start (char-after))
+ (quote nil) )
+ (when (or (= char-start ?') (= char-start ?\"))
+ (forward-char)
+ (setq quote char-start))
+ (bash-complete-split-1 start end pos quote accum)))
+
+;; "hell o" wor\ ld 'baa baaaa'a"hell o"world a
+
+;; (progn
+;; (load-library "~/.emacs.d/bash-complete.el")
+;; (let ((start 64) (end 108))
+;; (bash-complete-split start end 80)))
+
+(defun bash-complete-split-1 (start end pos quote accum)
+ (skip-chars-forward (bash-complete-nonsep quote) end)
+ (cond
+ ;; an escaped char, skip, whatever it is
+ ((= ?\\ (char-before))
+ (forward-char)
+ (bash-complete-split-1 start end pos (if (and quote (= quote
(char-before))) nil quote) accum))
+ ;; opening quote
+ ((and (not quote) (or (= ?' (char-after)) (= ?\" (char-after))))
+ (bash-complete-split-0 start end pos accum))
+ ;; closing quote
+ ((and quote (= quote (char-after)))
+ (forward-char)
+ (bash-complete-split-0 start end pos accum))
+ ;; space inside a quote
+ ((and quote (not (= quote (char-after))))
+ (forward-char)
+ (bash-complete-split-1 start end pos quote accum))
+ ;; word end
+ (t
+ (let ((str (buffer-substring-no-properties start (point))))
+ (when str
+ (push str accum)))
+ (skip-chars-forward " \t\n\r" end)
+ (if (< (point) end)
+ (bash-complete-split-0 (point) end pos accum)
+ accum))))
+
+(defun bash-complete-nonsep (quote)
+ (if quote
+ (concat "^ \t\n\r" (char-to-string quote))
+ "^ \t\n\r'\""))
+
+(defun bash-complete-comm (line pos words cword)
+ "Set LINE, POS, WORDS and CWORD, call bash completion, return the result.
+
+This function starts a separate bash process if necessary, sets up the
+completion environment (COMP_LINE, COMP_POINT, COMP_WORDS, COMP_CWORD) and
+calls compgen.
+
+The result is a list of candidates, which might be empty."
+
+ )
- [nongnu] branch elpa/bash-completion created (now 8e9c20dbfe), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7dc290e1c7 003/313: exclude quotes from result, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 540f8f516a 011/313: build bash cmdline, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6eebe8f965 016/313: cleaned up process launch, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 34d11220dd 024/313: add prefix if missing, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3036ef0394 028/313: disable quote_readline to get good whitespace handling for bash 3.2 at least, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ba83e81651 053/313: bash-completion-generate-line, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f7bfc68ea2 001/313: bash completion,
ELPA Syncer <=
- [nongnu] elpa/bash-completion f5885ec87a 002/313: test case for bash-complete, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 208cb5ab76 007/313: Join, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 47a890dd72 010/313: launch process, send commands, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 53f2c5d30e 009/313: parse complete -p output, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 11e52fce6f 018/313: Fixed initialization, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c10cfef5b8 015/313: complex line split, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b5c2fbf4a2 014/313: add hooks, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9eb026ae0b 025/313: fixed current directory for adding slash, workaround for bash ~ expansion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 02d1acf260 030/313: wordbreaks, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5931a2ba43 037/313: completion-fix, ELPA Syncer, 2022/12/03