[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-diffs] master 8404fe8b: Provide generic completion functions
From: |
auctex-commit |
Subject: |
[AUCTeX-diffs] master 8404fe8b: Provide generic completion functions |
Date: |
Fri, 6 May 2022 14:42:02 -0400 (EDT) |
branch: master
commit 8404fe8b1843ef1f7189df7221f58ffe9f262167
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Provide generic completion functions
* latex.el (TeX-read-completing-read, TeX-arg-completing-read)
(TeX-read-completing-read-multiple)
(TeX-arg-completing-read-multiple): Add generic functions to read
and insert arguments with completion.
---
latex.el | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 119 insertions(+)
diff --git a/latex.el b/latex.el
index 7ec66cd9..a6ab5220 100644
--- a/latex.el
+++ b/latex.el
@@ -3245,6 +3245,125 @@ returning an alist. Use PROMPT as the prompt string."
(t
key-val-alist))))
+(defun TeX-read-completing-read (optional collection &optional prompt complete
+ predicate require-match
+ initial-input hist def
+ inherit-input-method)
+ "Read a string in the minibuffer, with completion and return it.
+If OPTIONAL is non-nil, indicate it in the prompt.
+
+COLLECTION provides elements for completion and is passed to
+`completing-read'. It can be:
+ - A List or an alist
+ - A symbol returning a list
+ - A function call
+
+PROMPT replaces the standard one where ' (cr): ' is appended to
+it. If you want the full control over the prompt, set COMPLETE
+to non-nil and then provide a full PROMPT.
+
+PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF and
+INHERIT-INPUT-METHOD are passed to `completing-read', which see."
+ (completing-read
+ (TeX-argument-prompt optional
+ (cond ((and prompt (not complete))
+ (concat prompt " (cr)"))
+ ((and prompt complete)
+ prompt)
+ (t "Option (cr)"))
+ complete)
+ (cond ((and (symbolp collection)
+ (boundp collection))
+ (symbol-value collection))
+ ((and (listp collection)
+ (symbolp (car collection))
+ (fboundp (car collection)))
+ (if (> (length collection) 1)
+ (eval collection t)
+ (funcall (car collection))))
+ (t collection))
+ predicate require-match initial-input hist def inherit-input-method))
+
+(defun TeX-arg-completing-read (optional collection &optional prompt complete
+ prefix predicate require-match
+ initial-input hist def
+ inherit-input-method)
+ "Read a string in the minibuffer, with completion and insert it.
+If OPTIONAL is non-nil, indicate it in the minibuffer and insert
+the result in brackets if not empty.
+
+For PROMPT and COMPLETE, refer to `TeX-read-completing-read'.
+For PREFIX, see `TeX-argument-insert'.
+PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF and
+INHERIT-INPUT-METHOD are passed to `completing-read', which see."
+ (TeX-argument-insert
+ (TeX-read-completing-read optional collection prompt complete
+ predicate require-match initial-input
+ hist def inherit-input-method)
+ optional prefix))
+
+(defun TeX-read-completing-read-multiple (optional table &optional prompt
complete
+ predicate require-match
+ initial-input hist def
+ inherit-input-method)
+ "Read multiple strings in the minibuffer, with completion and return them.
+If OPTIONAL is non-nil, indicate it in the prompt.
+
+COLLECTION provides elements for completion and is passed to
+`completing-read'. It can be:
+ - A List or an alist
+ - A symbol returning a list
+ - A function call
+
+PROMPT replaces the standard one where ' (crm): ' is appended to
+it. If you want the full control over the prompt, set COMPLETE
+to non-nil and then provide a full PROMPT.
+
+PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF and
+INHERIT-INPUT-METHOD are passed to
+`TeX-completing-read-multiple', which see."
+ (TeX-completing-read-multiple
+ (TeX-argument-prompt optional
+ (cond ((and prompt (not complete))
+ (concat prompt " (crm)"))
+ ((and prompt complete)
+ prompt)
+ (t "Options (crm)"))
+ complete)
+ (cond ((and (symbolp table)
+ (boundp table))
+ (symbol-value table))
+ ((and (listp table)
+ (symbolp (car table))
+ (fboundp (car table)))
+ (if (> (length table) 1)
+ (eval table t)
+ (funcall (car table))))
+ (t table))
+ predicate require-match initial-input hist def inherit-input-method))
+
+(defun TeX-arg-completing-read-multiple (optional table &optional prompt
complete
+ prefix predicate
require-match
+ initial-input hist def
+ inherit-input-method)
+ "Read multiple strings in the minibuffer, with completion and insert them.
+If OPTIONAL is non-nil, indicate it in the minibuffer and insert
+the result in brackets if not empty.
+
+For PROMPT and COMPLETE, refer to `TeX-read-completing-read-multiple'.
+For PREFIX, see `TeX-argument-insert'.
+PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF and
+INHERIT-INPUT-METHOD are passed to
+`TeX-completing-read-multiple', which see."
+ (TeX-argument-insert
+ (mapconcat #'identity
+ (TeX-read-completing-read-multiple optional table prompt
+ complete predicate
+ require-match initial-input
+ hist def inherit-input-method)
+ ",")
+ optional prefix))
+
(defun TeX-arg-key-val (optional key-val-alist &optional prompt)
"Prompt for keys and values in KEY-VAL-ALIST.
Insert the given value as a TeX macro argument. If OPTIONAL is
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [AUCTeX-diffs] master 8404fe8b: Provide generic completion functions,
auctex-commit <=