[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 3c58afdb0d 033/313: expand file names in c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 3c58afdb0d 033/313: expand file names in colon-separated paths |
Date: |
Sat, 3 Dec 2022 10:59:13 -0500 (EST) |
branch: elpa/bash-completion
commit 3c58afdb0dcb1b333de8830e24565e14ce246bd1
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
expand file names in colon-separated paths
---
bash-completion.el | 45 +++++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index c7aff97876..4537b288dd 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -29,6 +29,8 @@ the following entry is added to `bash-completion-alist':
See `bash-completion-add-to-alist'.
")
+(defvar bash-completion-wordbreaks (append "\"'@><=;|&(:" nil))
+
(defun bash-completion-setup ()
(add-hook 'shell-dynamic-complete-functions
'bash-completion-dynamic-complete)
@@ -59,7 +61,13 @@ Call bash to do the completion."
(setq words (cdr wordsplit))
(setq stub (nth cword words)))
(let ((completions (bash-completion-comm line (- pos start) words cword)))
- (comint-dynamic-simple-complete stub completions))))
+ (if completions
+ (comint-dynamic-simple-complete stub completions)
+ ;; try default completion after a wordbreak
+ (let ((after-wordbreak (bash-completion-after-last-wordbreak stub)))
+ (when (not (equal stub after-wordbreak))
+ (bash-completion-send (concat (bash-completion-cd-command-prefix)
"compgen -o default -- " after-wordbreak))
+ (comint-dynamic-simple-complete after-wordbreak
(bash-completion-extract after-wordbreak))))))))
(defun bash-completion-line-beginning-position (&optional start)
(save-excursion
@@ -86,7 +94,10 @@ Call bash to do the completion."
"'")))
(defun bash-completion-escape (word)
- (replace-regexp-in-string "\\([ '\"]\\)" "\\\\\\1" word))
+ (message "escape: %s" word)
+ (if (string-match "^['\"]" word)
+ word
+ (replace-regexp-in-string "\\([ '\"]\\)" "\\\\\\1" word)))
(defun bash-completion-split (start end pos)
"Split LINE like bash would do, keep track of current word at POS.
@@ -165,8 +176,11 @@ calls compgen.
The result is a list of candidates, which might be empty."
(bash-completion-send (concat (bash-completion-generate-line line pos words
cword) " 2>/dev/null"))
- (let ((bash-completion-prefix (nth cword words)))
- (mapcar 'bash-completion-fix
+ (bash-completion-extract (nth cword words)))
+
+(defun bash-completion-extract (stub)
+ (let ((bash-completion-prefix stub))
+ (mapcar 'bash-completion-fix
(with-current-buffer (bash-completion-buffer)
(split-string (buffer-string) "\n" t)))))
@@ -198,14 +212,20 @@ The result is a list of candidates, which might be empty."
(concat prefix (bash-completion-escape rest) suffix)))))
(defun bash-completion-before-last-wordbreak (str)
- (catch 'bash-completion-return
+ (car (bash-completion-last-wordbreak-split str)))
+
+(defun bash-completion-after-last-wordbreak (str)
+ (cdr (bash-completion-last-wordbreak-split str)))
+
+(defun bash-completion-last-wordbreak-split (str)
+ (catch 'bash-completion-return
(let ((end (- (length str) 1)))
(while (> end 0)
- (when (memq (aref str end) '( ?' ?@ ?> ?< ?= ?\; ?| ?& ?\( ?: ))
- (throw 'bash-completion-return (substring str 0 (1+ end))))
+ (when (memq (aref str end) bash-completion-wordbreaks)
+ (throw 'bash-completion-return (cons (substring str 0 (1+ end))
(substring str (1+ end)))))
(setq end (1- end))))
- str))
-
+ (cons "" str)))
+
(defun bash-completion-ends-with (str suffix)
(let ((suffix-len (length suffix))
(str-len (length str)))
@@ -270,9 +290,14 @@ The result is a list of candidates, which might be empty."
(kill-process process)
(error nil))))))))
+(defun bash-completion-cd-command-prefix ()
+ (if default-directory
+ (concat "cd 2>/dev/null " (bash-completion-quote (expand-file-name
default-directory)) " ; ")
+ ""))
+
(defun bash-completion-generate-line (line pos words cword)
(concat
- (if default-directory (concat "cd 2>/dev/null " (bash-completion-quote
(expand-file-name default-directory)) " ; ") "")
+ (bash-completion-cd-command-prefix)
(let* ( (command-name (file-name-nondirectory (car words)))
(compgen-args (cdr (assoc command-name bash-completion-alist))) )
(if (not compgen-args)
- [nongnu] elpa/bash-completion ea5cc15b99 273/313: Let status code of compgen through when in single-process mode., (continued)
- [nongnu] elpa/bash-completion ea5cc15b99 273/313: Let status code of compgen through when in single-process mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 12da4f0e91 289/313: Better handle slow completion functions., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7186a18cad 012/313: Integrated into comm, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e81c478032 020/313: bash-complete -> bash-completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8270e09294 023/313: pass words as command-line arguments to the function, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 482383dcd7 021/313: handle slash for directory, usable completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion cd2ec103d1 026/313: Expand directory names with quotes and spaces, but no further, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1d7af7e40d 027/313: Remove debug messages, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion dda4697cfb 029/313: included bash-completion into google env, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 21eabde7f9 045/313: Reimplemented split, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3c58afdb0d 033/313: expand file names in colon-separated paths,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 5501cb63cf 042/313: Turn off mail warning, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0dcf43f91e 041/313: don't run integration tests by default, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5b76fc4a33 032/313: remove wrong a=b variable prefix handling, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7697f1a87c 063/313: comments about tried systems, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3efe7cb03c 067/313: escape #, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 42441e36b0 055/313: more documentation, a little refactoring, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5661a34c4a 098/313: updated test case for cd 2>/dev/null, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c64ca7a992 071/313: simplified parse-current-command, all tests pass, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion cc1a462415 050/313: tested complex line, detect escaped separators, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9ac7f58758 059/313: Gone through compgen, ELPA Syncer, 2022/12/03