[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion a8b652d00a 058/313: commented all function
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion a8b652d00a 058/313: commented all functions |
Date: |
Sat, 3 Dec 2022 10:59:16 -0500 (EST) |
branch: elpa/bash-completion
commit a8b652d00af2193cbb308c59ce39541f38b12cdf
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
commented all functions
---
bash-completion.el | 101 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 92 insertions(+), 9 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index c557201566..630af61d26 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -541,6 +541,22 @@ Return a possibly escaped version of COMPLETION-CANDIDATE."
completion-candidate
(replace-regexp-in-string "\\([ '\"]\\)" "\\\\\\1" completion-candidate)))
+(defconst bash-completion-known-suffixes-regexp
+ (concat "[" (regexp-quote bash-completion-wordbreaks-str) "/ ]$")
+ "Regexp matching known suffixes for `bash-completion-addsuffix'.")
+
+(defun bash-completion-addsuffix (str)
+ "Add a directory suffix to STR if it looks like a directory.
+
+This function looks for a directory called STR relative to the
+buffer-local variable default-directory. If it exists, it returns
+(concat STR \"/\"). Otherwise it retruns STR.
+"
+ (if (and (null (string-match bash-completion-known-suffixes-regexp str))
+ (file-accessible-directory-p (expand-file-name str
default-directory)))
+ (concat str "/")
+ str))
+
(defun bash-completion-before-last-wordbreak (str)
"Return the part of STR that comes after the last wordbreak character.
The return value does not include the worbreak character itself.
@@ -580,6 +596,7 @@ Return a CONS containing (before . after)."
(cons "" str)))
(defun bash-completion-ends-with (str suffix)
+ "Return t if STR ends with SUFFIX."
(let ((suffix-len (length suffix))
(str-len (length str)))
(or
@@ -589,20 +606,35 @@ Return a CONS containing (before . after)."
(equal (substring str (- suffix-len)) suffix)))))
(defun bash-completion-starts-with (str prefix)
+ "Return t if STR starts with SUFFIX."
(let ((prefix-len (length prefix))
(str-len (length str)))
(and
(>= str-len prefix-len)
(equal (substring str 0 prefix-len) prefix))))
-(defun bash-completion-addsuffix (str)
- (if (and (null (string-match (concat "[" (regexp-quote
bash-completion-wordbreaks-str) "/ ]$") str))
- (file-accessible-directory-p (expand-file-name str
default-directory)))
- (progn
- (concat str "/"))
- str))
-
(defun bash-completion-require-process ()
+ "Return the bash completion process, start it if necessary.
+
+If a bash completion process is already running, return it.
+
+Otherwise, create a bash completion process and return the
+result. This can take a since bash needs to start completely
+before this function returns to be sure everything has been
+initialized correctly.
+
+The process uses `bash-completion-prog' to figure out the path to
+bash on the current system.
+
+To get an environment consistent with shells started with `shell',
+the first file found in the following list are sourced if they exist:
+ ~/.emacs_bash.sh (actually ~/.emacs_$(basename bash-completion-prog).sh)
+ ~/.emacs.d/init_bash.sh (actually ~/.emacs.d/init_$(basename
bash-completion-prog).sh)
+
+To allow scripts to tell the difference between shells launched
+by bash-completion, the environment variable EMACS_BASH_COMPLETE
+is set to t.
+"
(if (bash-completion-is-running)
bash-completion-process
;; start process
@@ -650,11 +682,36 @@ Return a CONS containing (before . after)."
(error nil))))))))
(defun bash-completion-cd-command-prefix ()
+ "Build a command-line that CD to default-directory.
+
+Return a bash command-line for going to default-directory or \"\"."
(if default-directory
- (concat "cd 2>/dev/null " (bash-completion-quote (expand-file-name
default-directory)) " ; ")
+ (concat "cd 2>/dev/null "
+ (bash-completion-quote (expand-file-name default-directory))
+ " ; ")
""))
(defun bash-completion-generate-line (line pos words cword)
+ "Generate a command-line that calls compgen.
+
+This function looks into `bash-completion-alist' for a matching compgen
+argument set. If it finds one, it executes it. Otherwise, it executes the
+default bash completion (compgen -o default)
+
+LINE is the command-line to complete.
+POS is the position of the cursor on LINE
+WORDS is the content of LINE split by words and unescaped
+CWORD is the word 0-based index of the word to complete in WORDS
+
+If the compgen argument set specifies a custom function or command, the
+arguments will be passed to this function or command as:
+ COMP_LINE, taken from LINE
+ COMP_POINT, taken from POS
+ COMP_WORDS, taken from WORDS (a bash array)
+ COMP_CWORD, taken for CWORD
+
+Return a bash command-line that calls compgen to get the completion
+candidates."
(concat
(bash-completion-cd-command-prefix)
(let* ( (command-name (file-name-nondirectory (car words)))
@@ -691,12 +748,23 @@ Return a CONS containing (before . after)."
;; simple custom completion
(format "compgen %s -- %s" (bash-completion-join compgen-args)
stub))))))
+;;;###autoload
(defun bash-completion-reset ()
+ "Force the next completion command to start with a fresh BASH process.
+
+This function kills any existing BASH completion process. This way, the
+next time BASH completion is requested, a new process will be created with
+the latest configuration.
+
+Call this method if you have updated your .bashrc or any bash init scripts
+and would like bash completion in emacs to take these changes into account.
+"
(interactive)
(bash-completion-kill bash-completion-process)
(setq bash-completion-process nil))
(defun bash-completion-kill (process)
+ "Kill PROCESS and its buffer."
(when process
(when (eq 'run (process-status process))
(kill-process process))
@@ -705,12 +773,26 @@ Return a CONS containing (before . after)."
(kill-buffer buffer)))))
(defun bash-completion-buffer ()
+ "Return the buffer of the BASH process, create the BASH process if
necessary."
(process-buffer (bash-completion-require-process)))
(defun bash-completion-is-running ()
+ "Check whether the bash completion process is running."
(and bash-completion-process (eq 'run (process-status
bash-completion-process))))
(defun bash-completion-send (commandline &optional process timeout)
+ "Send a command to the bash completion process.
+
+COMMANDLINE should be a bash command, without the final newline.
+
+PROCESS should be the bash process, if nil this function calls
+`bash-completion-require-process' which might start a new process.
+
+TIMEOUT is the timeout value for this operation, if nil the value of
+bash-completion-process-timeout is used.
+
+Once this command has run without errors, you will find the result
+of the command in the bash completion process buffer."
;;(message commandline)
(let ((process (or process (bash-completion-require-process)))
(timeout (or timeout bash-completion-process-timeout)))
@@ -729,7 +811,8 @@ Return a CONS containing (before . after)."
BUFFER should contains the output of:
complete -p
-Return `bash-completion-alist'."
+Return `bash-completion-alist', which is slightly parsed version
+of the output of \"complete -p\"."
(with-current-buffer buffer
(save-excursion
(setq bash-completion-alist nil)
- [nongnu] elpa/bash-completion 0c4557a5ed 193/313: Integration test for default completion (-D)., (continued)
- [nongnu] elpa/bash-completion 0c4557a5ed 193/313: Integration test for default completion (-D)., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e7869dd68d 200/313: Fix a bug when no process is associated with the current buffer, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 80be2f37a9 205/313: Check the buffer uses comint-mode before using the same process, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 28ec870dd1 019/313: only one -complete method, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6a0ada6278 038/313: completed test cases, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7d6236e6e7 100/313: ignore .elc files, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1aff6d8806 084/313: comment about shell-command, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f5384c6176 051/313: A little refactoring, test case for wordbreak completion, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6f7c2b8b4f 080/313: removed initial version, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a2cf41d7fc 102/313: put in accidentally removed blank line from README, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a8b652d00a 058/313: commented all functions,
ELPA Syncer <=
- [nongnu] elpa/bash-completion b4fe25b51c 060/313: update tests for latest refactorings, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 49ae0ada64 076/313: keep open quote, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion aedcc114dc 105/313: Minor fixes to eliminate byte-compiler warnings., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8c771b10d1 082/313: fix typo, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9ca7e3a77f 085/313: Fixed errors in documentation, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 97cace2287 089/313: Split shopt sets; if one fails the rest can run, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 007765fdd1 111/313: Make bash-completion.el work under emacs trunk., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 102316ebf9 117/313: Test bash-completion-dynamic-complete-standard, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 094da8d6f8 115/313: Fallback to comint-dynamic-simple-complete for shellcommand, even under, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion acdedd0b48 122/313: Remove colon added by mistake in -test.el, ELPA Syncer, 2022/12/03