[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 42441e36b0 055/313: more documentation, a
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 42441e36b0 055/313: more documentation, a little refactoring |
Date: |
Sat, 3 Dec 2022 10:59:15 -0500 (EST) |
branch: elpa/bash-completion
commit 42441e36b0cb1d85699345661086e1e6388689c4
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
more documentation, a little refactoring
---
bash-completion.el | 49 ++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 40 insertions(+), 9 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 40d3c004c4..783c07a232 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -80,9 +80,16 @@ colon-separated values.")
;;;###autoload
(defun bash-completion-dynamic-complete ()
- "Bash completion function for `comint-complete-dynamic-functions'.
+ "Complete word at cursor using BASH completion.
-Call bash to do the completion."
+This function is meant to be added into
+`shell-dynamic-complete-functions' or
+`shell-command-complete-functions'. It uses `comint' to figure
+out what the current command is and calls
+`comint-dynamic-simple-complete' to do the completion.
+
+If a match was found, it is displayed as is usual for comint
+completion. Return nil if no match was found."
(when bash-completion-enabled
(when (not (window-minibuffer-p))
(message "Bash completion..."))
@@ -106,6 +113,13 @@ Call bash to do the completion."
(bash-completion-dynamic-try-wordbreak-complete stub)))))
(defun bash-completion-dynamic-try-wordbreak-complete (stub)
+ "Try wordbreak completion on STUB if the complete completion failed.
+
+Split STUB using the wordbreak list and apply compgen default
+completion on the last part. Return non-nil if a match was found.
+
+This function is not meant to be called outside of
+`bash-completion-dynamic-complete'."
(let* ((wordbreak-split (bash-completion-last-wordbreak-split stub))
(before-wordbreak (car wordbreak-split))
(after-wordbreak (cdr wordbreak-split)))
@@ -119,7 +133,13 @@ Call bash to do the completion."
(bash-completion-extract after-wordbreak)))))
(defun bash-completion-join (words)
- "Join WORDS into a shell line, escaped all words with single quotes"
+ "Join WORDS into a shell command line.
+
+All words that contain even mildly suspicious characters are
+quoted using single quotes to avoid the shell interpreting them
+when it shouldn't.
+
+Return one string containing WORDS."
(if words
(mapconcat
'bash-completion-quote
@@ -127,17 +147,16 @@ Call bash to do the completion."
""))
(defun bash-completion-quote (word)
+ "Put single quotes around WORD unless it's crearly unnecessary.
+
+If WORD contains characters that aren't known to be harmless, this
+functions adds single quotes around it and return the result. "
(if (string-match "^[a-zA-Z0-9_./-]*$" word)
word
(concat "'"
(replace-regexp-in-string "'" "'\\''" word :literal t)
"'")))
-(defun bash-completion-escape (word)
- (if (string-match "^['\"]" word)
- word
- (replace-regexp-in-string "\\([ '\"]\\)" "\\\\\\1" word)))
-
(defun bash-completion-parse-line (start end pos)
(bash-completion-parse-line-postprocess
(bash-completion-parse-current-command
@@ -341,7 +360,19 @@ The result is a list of candidates, which might be empty."
(when (bash-completion-ends-with rest " ")
(setq rest (substring rest 0 -1))
(setq suffix " "))
- (concat prefix (bash-completion-escape rest) suffix)))))
+ (concat prefix (bash-completion-escape-candidate rest) suffix)))))
+
+(defun bash-completion-escape-candidate (completion-candidate)
+ "Escapes COMPLETION-CANDIDATE.
+
+This function escapes all special characters in the result of
+bash completion. It does nothing if COMPLETION-CANDIDATE looks
+like a quoted string.
+
+Return a possibly escaped version of COMPLETION-CANDIDATE."
+ (if (string-match "^['\"]" completion-candidate)
+ completion-candidate
+ (replace-regexp-in-string "\\([ '\"]\\)" "\\\\\\1" completion-candidate)))
(defun bash-completion-before-last-wordbreak (str)
(car (bash-completion-last-wordbreak-split str)))
- [nongnu] elpa/bash-completion cd2ec103d1 026/313: Expand directory names with quotes and spaces, but no further, (continued)
- [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, 2022/12/03
- [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 <=
- [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
- [nongnu] elpa/bash-completion e515453141 047/313: from an alist to (string start stop), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 582b489fb3 091/313: Added message about mailcheck, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7f0160d271 065/313: Trim strange results that are a subset of the current value: test case, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 583ecc7707 103/313: Merge pull request #1 from kemmason/master, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 52af1ff8f7 090/313: Really disable mail check this time ? Set MAILCHECK to -1, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3859be798a 108/313: Add support for complete -D., ELPA Syncer, 2022/12/03