[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/frog-menu 94c99cf 08/12: Add support for all collection
From: |
Clemens Radermacher |
Subject: |
[elpa] externals/frog-menu 94c99cf 08/12: Add support for all collection formats of completing-read |
Date: |
Thu, 21 May 2020 11:15:13 -0400 (EDT) |
branch: externals/frog-menu
commit 94c99cfd647c71e8e46c82de8dd8a282d44c9efc
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>
Add support for all collection formats of completing-read
---
frog-menu.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 51 insertions(+), 10 deletions(-)
diff --git a/frog-menu.el b/frog-menu.el
index a8e38b6..512dd64 100644
--- a/frog-menu.el
+++ b/frog-menu.el
@@ -641,27 +641,68 @@ COLLECTION are the arguments from `frog-menu-read'."
(replace-regexp-in-string "\\(: ?\\)?\\'" ": " prompt))
collection args))
-(defun frog-menu-completing-read-function (prompt collection &rest _)
+(defun frog-menu-completing-read-function (prompt collection predicate &rest _)
"Can be used as `completing-read-function'.
-For now all arguments other than PROMPT and COLLECTION are
-ignored. COLLECTION has to use a format `frog-menu-read' can
-understand."
- (frog-menu-read prompt collection))
+PROMPT, COLLECTION and PREDICATE are of format as specified by
+`completing-read'."
+ (let ((strings (frog-menu--collection-to-strings collection predicate)))
+ (frog-menu-read prompt strings)))
;;;###autoload
(defun frog-menu-call (cmds &optional prompt)
"Read a command from CMDS and execute it.
-CMDS is a list of command symbols to choose from. If PROMPT is
-given it should be a string with prompt information for the
-user."
- (let ((cmd (intern-soft (frog-menu-read (or prompt "")
- (mapcar #'symbol-name cmds)))))
+CMDS is of format as specified by `completing-read'
+collections. If PROMPT is given it should be a string with prompt
+information for the user."
+ (let ((cmd (intern-soft (frog-menu-read
+ (or prompt "")
+ (frog-menu--collection-to-strings cmds)))))
(command-execute cmd)))
+(defun frog-menu--collection-to-strings (collection &optional predicate)
+ "Return list of strings representing COLLECTION.
+COLLECTION and PREDICATE should have the format as specified by
+`completing-read'."
+ (cond ((functionp collection)
+ (let ((cands (funcall collection "" predicate t)))
+ (if (stringp (car-safe cands))
+ (copy-sequence cands)
+ (mapcar #'symbol-name cands))))
+ ((listp collection)
+ (let ((strings ()))
+ (dolist (el collection (nreverse strings))
+ (unless (and predicate
+ (funcall predicate el))
+ (let ((cand (or (car-safe el) el)))
+ (push (if (symbolp cand)
+ (symbol-name cand)
+ cand)
+ strings))))))
+ ((hash-table-p collection)
+ (let ((strings ()))
+ (maphash
+ (lambda (key val)
+ (unless (and predicate
+ (funcall predicate key val))
+ (push (if (symbolp el)
+ (symbol-name el)
+ el)
+ strings))))
+ (nreverse strings)))
+ ((vectorp collection)
+ (let ((strings ()))
+ (mapatoms
+ (lambda (el)
+ (unless (and predicate
+ (funcall predicate el))
+ (push (symbol-name el) strings))))
+ (nreverse strings)))))
+
+
;;;###autoload
(defun frog-menu-read (prompt collection &optional actions)
"Read from a menu of variable `frog-menu-type'.
- [elpa] externals/frog-menu updated (927ff01 -> 3d99c10), Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 1bcc95f 01/12: Add menubar example, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 06d5f17 03/12: Add mode menu entry command for example, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu ec633cd 02/12: Update example, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 9b2fd00 06/12: Require tmm for example, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 4ef6586 09/12: Give frog-menu-posframe-background-face a default background color, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 3d99c10 12/12: Bump version, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 6898f09 04/12: Fix example, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 0430a4f 05/12: Update example, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu ac85040 07/12: Add posframe border option as suggested by #7, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu 94c99cf 08/12: Add support for all collection formats of completing-read,
Clemens Radermacher <=
- [elpa] externals/frog-menu 94a24ff 10/12: Fix hash collection types, Clemens Radermacher, 2020/05/21
- [elpa] externals/frog-menu d8e9325 11/12: Fix compiler errors, Clemens Radermacher, 2020/05/21