[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion c10cfef5b8 015/313: complex line split
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion c10cfef5b8 015/313: complex line split |
Date: |
Sat, 3 Dec 2022 10:59:11 -0500 (EST) |
branch: elpa/bash-completion
commit c10cfef5b8ae46c36f98bf3646c17f2382b95f0c
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
complex line split
---
bash-complete.el | 51 +++++++++++++++++++++++++++++++--------------------
bash-complete_test.el | 22 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/bash-complete.el b/bash-complete.el
index 82a8072c8c..edbd4eacdb 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -35,7 +35,7 @@ Call bash to do the completion."
(defun bash-complete-dynamic-complete-0 ()
(let* ( (pos (point))
- (start (comint-line-beginning-position))
+ (start (bash-complete-line-beginning-position))
(end (line-end-position))
(line (buffer-substring-no-properties start end))
(wordsplit)
@@ -52,6 +52,15 @@ Call bash to do the completion."
(bash-complete-comm
line (- pos start) words cword))))
+(defun bash-complete-line-beginning-position (&optional start)
+ (save-excursion
+ (let ((start (or start (comint-line-beginning-position)))
+ (end (line-end-position)))
+ (goto-char start)
+ (if (search-forward-regexp "\\(;\\|\\(&&\\)\\|\\(||\\)\\)[ \t\n]" end t)
+ (match-end 0)
+ start))))
+
(defun bash-complete-join (words)
"Join WORDS into a shell line, escaped all words with single quotes"
(if words
@@ -161,25 +170,27 @@ The result is a list of candidates, which might be empty."
bash-complete-process)
(defun bash-complete-generate-line (line pos words cword)
- (let* ( (command (file-name-nondirectory (car words)))
- (compgen-args (cdr (assoc command bash-complete-alist))) )
- (if (not compgen-args)
- ;; no custom completion. use default completion
- (bash-complete-join (list "compgen" "-o" "default" (nth cword words)))
- ;; custom completion
- (let* ( (args (copy-tree compgen-args))
- (function (or (member "-F" args) (member "-C" args))) )
- (if function
- (let ((function-name (car (cdr function))))
- (setcar function "-F")
- (setcar (cdr function) "__bash_complete_wrapper")
- (format "__BASH_COMPLETE_WRAPPER=%s compgen %s -- %s"
- (bash-complete-quote (format "COMP_LINE=%s;
COMP_POINT=%s; COMP_CWORD=%s; COMP_WORDS=( %s ); %s \"$@\""
- (bash-complete-quote line)
pos cword (bash-complete-join words)
- (bash-complete-quote
function-name)))
- (bash-complete-join args)
- (bash-complete-quote (nth cword words))))
- (format "compgen %s -- %s" (bash-complete-join args) (nth cword
words)))))))
+ (concat
+ (if default-directory (concat "cd " (bash-complete-quote default-directory)
" && ") "")
+ (let* ( (command (file-name-nondirectory (car words)))
+ (compgen-args (cdr (assoc command bash-complete-alist))) )
+ (if (not compgen-args)
+ ;; no custom completion. use default completion
+ (bash-complete-join (list "compgen" "-o" "default" (nth cword words)))
+ ;; custom completion
+ (let* ( (args (copy-tree compgen-args))
+ (function (or (member "-F" args) (member "-C" args))) )
+ (if function
+ (let ((function-name (car (cdr function))))
+ (setcar function "-F")
+ (setcar (cdr function) "__bash_complete_wrapper")
+ (format "__BASH_COMPLETE_WRAPPER=%s compgen %s -- %s"
+ (bash-complete-quote (format "COMP_LINE=%s;
COMP_POINT=%s; COMP_CWORD=%s; COMP_WORDS=( %s ); %s \"$@\""
+ (bash-complete-quote line)
pos cword (bash-complete-join words)
+ (bash-complete-quote
function-name)))
+ (bash-complete-join args)
+ (bash-complete-quote (nth cword words))))
+ (format "compgen %s -- %s" (bash-complete-join args) (nth cword
words))))))))
(defun bash-complete-kill-process ()
(when (bash-complete-is-running)
diff --git a/bash-complete_test.el b/bash-complete_test.el
index 3a77c25ba7..64e21ba716 100644
--- a/bash-complete_test.el
+++ b/bash-complete_test.el
@@ -191,6 +191,28 @@ garbage
(mapcar 'bash-complete-trim '(" hello " " world " "x"))
'("hello" "world" "x"))
+ ("bash-complete-line-beginning-position start"
+ (sz-testutils-with-buffer
+ "cd /home/x"
+ (bash-complete-line-beginning-position 1))
+ 1)
+
+ ("bash-complete-line-beginning-position semicolon"
+ (sz-testutils-with-buffer
+ '("cd /home/x ; " cursor "echo hello")
+ (list
+ (point)
+ (bash-complete-line-beginning-position 1)))
+ '(14 14))
+
+ ("bash-complete-line-beginning-position &&"
+ (sz-testutils-with-buffer
+ '("cd /home/x && " cursor "echo hello")
+ (list
+ (point)
+ (bash-complete-line-beginning-position 1)))
+ '(15 15))
+
)))
- [nongnu] elpa/bash-completion 6eebe8f965 016/313: cleaned up process launch, (continued)
- [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, 2022/12/03
- [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 <=
- [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
- [nongnu] elpa/bash-completion a78fd6b587 044/313: turn off mailwarn and checkjobs, continue if this failed, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0ffaad3ef0 035/313: wordbreak-split, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 80cd654c35 043/313: turn off mailwarn and checkjobs, continue if this failed, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1c6b2efb67 040/313: enormous test, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion fc96b621e2 034/313: pass all tests in bash-completion, new test for -send, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e77c841dac 107/313: Merge pull request #3 from seanmcl/master, ELPA Syncer, 2022/12/03