[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 02d1acf260 030/313: wordbreaks
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 02d1acf260 030/313: wordbreaks |
Date: |
Sat, 3 Dec 2022 10:59:12 -0500 (EST) |
branch: elpa/bash-completion
commit 02d1acf2602a93ae7280ead2ca425f27d00744c2
Author: Stephane Zermatten <szermatt@google.com>
Commit: Stephane Zermatten <szermatt@gmx.net>
wordbreaks
---
bash-completion.el | 75 +++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 51 insertions(+), 24 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 09aaf77af1..7b0102e736 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -170,23 +170,50 @@ The result is a list of candidates, which might be empty."
(with-current-buffer (bash-completion-buffer)
(split-string (buffer-string) "\n" t)))))
-(defun bash-completion-fix (str)
- (bash-completion-addsuffix
- (let* ((rest (cond
- ((bash-completion-starts-with str bash-completion-prefix)
- (substring str (length bash-completion-prefix)))
- ;; bash expands the home directory automatic. this is confusing
- ;; for comint-dynamic-simple-complete
- ((and (bash-completion-starts-with bash-completion-prefix "~")
- (bash-completion-starts-with str (expand-file-name "~")))
- (substring (concat "~" (substring str (length
(expand-file-name "~"))))
- (length bash-completion-prefix)))
- ;; bash sometimes just prints whatever needs to be expanded,
- ;; for example: "export PATH=<complete>". Prepend the old
- ;; prefix to avoid confusing comint-dynamic-simple-complete
- (t str))))
- (concat bash-completion-prefix (bash-completion-escape rest)))))
-
+(defun bash-completion-fix (str &optional prefix)
+ (let ((prefix (or prefix bash-completion-prefix))
+ (suffix ""))
+ (bash-completion-addsuffix
+ (let* ((rebuilt)
+ (rest (cond
+ ((bash-completion-starts-with str prefix)
+ (substring str (length prefix)))
+ ;; bash expands the home directory automatically. This is
confusing
+ ;; for comint-dynamic-simple-complete
+ ((and (bash-completion-starts-with prefix "~")
+ (bash-completion-starts-with str (expand-file-name
"~")))
+ (substring (concat "~" (substring str (length
(expand-file-name "~"))))
+ (length prefix)))
+ ;; bash sometimes just prints whatever needs to be expanded,
+ ;; for example: "export PATH=<complete>". Prepend the old
+ ;; prefix to avoid confusing comint-dynamic-simple-complete
+ ((bash-completion-starts-with
+ (setq rebuilt (concat
(bash-completion-before-last-wordbreak prefix) str))
+ prefix)
+ (substring rebuilt (length prefix)))
+ (t str))))
+ (when (bash-completion-ends-with rest " ")
+ (setq rest (substring rest 0 -1))
+ (setq suffix " "))
+ (message "str=>%s< rest=>%s< prefix=>%s<" str rest prefix)
+ (concat prefix (bash-completion-escape rest) suffix)))))
+
+(defun bash-completion-before-last-wordbreak (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))))
+ (setq end (1- end))))
+ str))
+
+(defun bash-completion-ends-with (str prefix)
+ (let ((prefix-len (length prefix))
+ (str-len (length str)))
+ (and
+ (>= str-len prefix-len)
+ (equal (substring str (- prefix-len)) prefix))))
+
(defun bash-completion-starts-with (str prefix)
(let ((prefix-len (length prefix))
(str-len (length str)))
@@ -195,12 +222,12 @@ The result is a list of candidates, which might be empty."
(equal (substring str 0 prefix-len) prefix))))
(defun bash-completion-addsuffix (str)
- (let ((end (substring str -1)))
- (if (and (not (eq end " "))
- (not (eq end "/"))
- (file-accessible-directory-p (expand-file-name str
default-directory)))
- (concat str "/")
- str)))
+ (if (and (null (string-match "[/: ]$" str))
+ (file-accessible-directory-p (expand-file-name str
default-directory)))
+ (progn
+ (message "accessible: %s" (expand-file-name str default-directory))
+ (concat str "/"))
+ str))
(defun bash-completion-require-process ()
(if (bash-completion-is-running)
@@ -231,7 +258,7 @@ The result is a list of candidates, which might be empty."
;; strings - which compgen understands but only in some environment.
;; disable this dreadful business to get a saner way of handling
;; spaces.
- (bash-completion-send "function quote_readline { echo \"$1\"; }")
+ (bash-completion-send "function quote_readline { echo \"$1\"; }"
process)
(bash-completion-send "complete -p" process)
(bash-completion-build-alist (process-buffer process))
(setq bash-completion-process process)
- [nongnu] elpa/bash-completion ba83e81651 053/313: bash-completion-generate-line, (continued)
- [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, 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 <=
- [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
- [nongnu] elpa/bash-completion 062acfab3e 052/313: updated documentation, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 75e5de1494 066/313: fix initial completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ffe8bc46a2 097/313: Ignore 'cd' stdout, in case someone (like me) is crazy enough to override the builtin command, ELPA Syncer, 2022/12/03