[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion f639154925 134/313: Add bash-completion-dy
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion f639154925 134/313: Add bash-completion-dynamic-complete-nocomint for issue #13 |
Date: |
Sat, 3 Dec 2022 10:59:24 -0500 (EST) |
branch: elpa/bash-completion
commit f63915492574c6da806010c1fb7d203563c47d96
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Add bash-completion-dynamic-complete-nocomint for issue #13
This commit introduces a function that can safely be called outside of a
comint buffer. It is passed the region to complete and returns the same
result as bash-completion-dynamic-complete without accessing any
comint-specific function.
The refactoring removes bash-completion-dynamic-complete-0 and
bash-completion-dynamic-try-wordbreak-complete. Obsolete wrappers are
left for now, to avoid making a breaking change, for now.
---
bash-completion.el | 105 ++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 72 insertions(+), 33 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 8a6baac957..cefdc2f420 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -290,40 +290,51 @@ before it is needed. For an autoload version, add:
;;;###autoload
(defun bash-completion-dynamic-complete ()
- "Returns the completion table for bash command at point.
+ "Return the completion table for bash command at point.
This function is meant to be added into
`shell-dynamic-complete-functions'. It uses `comint' to figure
out what the current command is and returns a completion table or
-nil if no completions available."
- (if bash-completion-comint-uses-standard-completion
- (cdr (bash-completion-dynamic-complete-0))
- ;; pre-emacs 24.1 compatibility code
- (let ((result (bash-completion-dynamic-complete-0)))
- (when result
- (let ((stub (car result))
- (completions (nth 3 result))
- ;; Setting comint-completion-addsuffix overrides
- ;; configuration for comint-dynamic-simple-complete.
- ;; Bash adds a space suffix automatically.
- (comint-completion-addsuffix nil))
- (with-no-warnings
- (comint-dynamic-simple-complete stub completions)))))))
+nil if no completions available.
-(defun bash-completion-dynamic-complete-0 ()
- "Returns completion information for bash command at point.
-
-This function returns enough information for both standard and
-legacy modes of `bash-completion-dynamic-complete' It is not
-meant to be called directly.
-
-Returns (list unescaped-stub stub-start pos completions)"
- (when bash-completion-enabled
+When doing completion outside of a comint buffer, call
+`bash-completion-dynamic-complete-nocomint' instead."
(when (not (window-minibuffer-p))
(message "Bash completion..."))
- (let* ((start (comint-line-beginning-position))
- (pos (point))
- (tokens (bash-completion-tokenize start pos))
+ (let ((result (bash-completion-dynamic-complete-nocomint
+ (comint-line-beginning-position)
+ (point))))
+ (if bash-completion-comint-uses-standard-completion
+ result
+ ;; pre-emacs 24.1 compatibility code
+ (let ((result (bash-completion-dynamic-complete-0)))
+ (when result
+ (let ((stub (buffer-substring-no-properties
+ (nth 0 result)
+ (nth 1 result)))
+ (completions (nth 2 result))
+ ;; Setting comint-completion-addsuffix overrides
+ ;; configuration for comint-dynamic-simple-complete.
+ ;; Bash adds a space suffix automatically.
+ (comint-completion-addsuffix nil))
+ (with-no-warnings
+ (comint-dynamic-simple-complete stub completions))))))))
+
+(defun bash-completion-dynamic-complete-nocomint (start pos)
+ "Return completion information for bash command at an arbitrary position.
+
+The bash command to be completed begins at START in the current
+buffer. POS is the point where completion should happen.
+
+This function is meant to be usable even in non comint buffers.
+It is meant to be called directly from any completion engine.
+
+Returns (list stub-start stub-end completions) with
+ - stub-start, the position at which the completed region starts
+ - stub-end, the position at which the completed region ends
+ - completions, a possibly empty list of completion candidates"
+ (when bash-completion-enabled
+ (let* ((tokens (bash-completion-tokenize start pos))
(open-quote (bash-completion-tokenize-open-quote tokens))
(parsed (bash-completion-process-tokens tokens pos open-quote))
(line (cdr (assq 'line parsed)))
@@ -334,12 +345,12 @@ Returns (list unescaped-stub stub-start pos completions)"
(stub (nth cword words))
(completions (bash-completion-comm line point words cword
open-quote)))
(if completions
- (list stub stub-start pos completions)
+ (list stub-start pos completions)
;; fallback to default (file) completion after a wordbreak
- (bash-completion-dynamic-try-wordbreak-complete
+ (bash-completion--try-wordbreak-complete
stub stub-start pos open-quote)))))
-(defun bash-completion-dynamic-try-wordbreak-complete (stub stub-start pos
open-quote)
+(defun bash-completion--try-wordbreak-complete (stub stub-start pos open-quote)
"Try wordbreak completion on STUB if the complete completion failed.
Split STUB using the wordbreak list and apply compgen default
@@ -361,9 +372,8 @@ This function is not meant to be called outside of
(bash-completion-quote after-wordbreak)))
(let ((completions
(bash-completion-extract-candidates after-wordbreak open-quote)))
- (list after-wordbreak
- (+ stub-start (length before-wordbreak))
- pos
+ (list (+ stub-start (length before-wordbreak))
+ pos
completions)))))
;;; ---------- Functions: parsing and tokenizing
@@ -1122,5 +1132,34 @@ Return the status code of the command, as a number."
;; (point-min) (point-max)))
status-code))))
+;; Backward compatibility
+
+(defun bash-completion-dynamic-complete-0 ()
+ "Obsolete function, kept for backward compatibility.
+
+Call `bash-completion-dynamic' or `bash-completion-nocomint'."
+ (let ((result (bash-completion-dynamic-complete-nocomint
+ (comint-line-beginning-position)
+ (point))))
+ (cons (buffer-substring-no-properties (nth 0 result) (nth 1 result))
+ result)))
+(make-obsolete
+ 'bash-completion-dynamic-complete-0
+ "call bash-completion-dynamic or bash-completion-dynamic-nocomint")
+
+(defun bash-completion-dynamic-try-wordbreak-complete (stub stub-start pos
open-quote)
+ "Obsolete function, kept for backward compatibility.
+
+`bash-completion-dynamic-try-wordbreak-complete' became
+`bash-completion--try-wordbreak-complete' and its return value
+changed. This shouldn't be a problem, since the function isn't meant to
+be called from outside bash-completion.
+"
+ (let ((result (bash-completion--try-wordbreak-complete stub stub-start pos
open-quote)))
+ (cons (buffer-substring-no-properties (car result) pos) result)))
+(make-obsolete
+ 'bash-completion-dynamic-try-wordbreak-complete
+ 'bash-completion--try-wordbreak-complete)
+
(provide 'bash-completion)
;;; bash-completion.el ends here
- [nongnu] elpa/bash-completion 49ae0ada64 076/313: keep open quote, (continued)
- [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
- [nongnu] elpa/bash-completion 4e8090c081 128/313: Wrap use of obsolete fn in backward compatibility code path., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f639154925 134/313: Add bash-completion-dynamic-complete-nocomint for issue #13,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 8fa510a174 136/313: Fix comments in header of bash-completion.el:, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion dda29cb470 137/313: Fix backward-compatibility code for supporting pre-24 Emacs versions,, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f3b11e1221 139/313: Preserve original, quoted version of the string being completed when, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2010d8bf9e 210/313: Fix history uncluttering, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion ffe0640440 212/313: Cosmetic changes, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion bb044ff2f0 213/313: Try to handle prompts with ANSI escape sequences, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion e7ee0a5e07 214/313: Add a new prop to completion process to detect if it has been setup, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f1bd7b0e17 215/313: Use more meaningful names for the functions returning completion processes, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1e13f6ffa4 216/313: Apply the name changes introduced by the previous commit in the test files, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4d6fb40bec 217/313: Accept output only from the process performing completion, ELPA Syncer, 2022/12/03