[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/frog-menu 00a6c59 3/4: Define TAB key to switch to comp
From: |
Clemens Radermacher |
Subject: |
[elpa] externals/frog-menu 00a6c59 3/4: Define TAB key to switch to completing-read |
Date: |
Tue, 30 Apr 2019 03:20:36 -0400 (EDT) |
branch: externals/frog-menu
commit 00a6c59788da4a866625a49f76dee0dcea839c58
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>
Define TAB key to switch to completing-read
---
frog-menu.el | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/frog-menu.el b/frog-menu.el
index 5959963..00d44a3 100644
--- a/frog-menu.el
+++ b/frog-menu.el
@@ -515,7 +515,9 @@ action result. ACTIONS is the argument of `frog-menu-read'."
(setq frog-menu--avy-action-map (make-sparse-keymap))
(dolist (action actions)
(define-key frog-menu--avy-action-map (kbd (car action))
- (lambda () (car (cddr action))))))
+ (lambda () (car (cddr action)))))
+ ;; space must not be used by actions
+ (define-key frog-menu--avy-action-map "\t" 'frog-menu--complete))
(defun frog-menu-query-with-avy (buffer window actions)
"Query handler for avy-posframe.
@@ -550,6 +552,9 @@ ACTIONS is the argument of `frog-menu-read'."
;; get rid of the padding
(replace-regexp-in-string
"\\`_ *" "" (buffer-substring start end)))))
+ ((eq pos 'frog-menu--complete)
+ ;; switch to completion from `frog-menu-read'
+ pos)
((functionp pos)
;; action
(funcall pos))))
@@ -563,6 +568,18 @@ ACTIONS is the argument of `frog-menu-read'."
;; * Entry point
+(defun frog-menu--complete (prompt collection &rest args)
+ "PROMPT for `completing-read' COLLECTION.
+
+Remaining ARGS are passed to `completing-read'. PROMPT and
+COLLECTION are the arguments from `frog-menu-read'."
+ (apply #'completing-read
+ ;; make sure prompt is "completing readable"
+ (if (string-empty-p prompt)
+ ": "
+ (replace-regexp-in-string "\\(: ?\\)?\\'" ": " prompt))
+ collection args))
+
;;;###autoload
(defun frog-menu-call (cmds &optional prompt)
@@ -584,7 +601,8 @@ PROMPT is a string with prompt information for the user.
COLLECTION is a list from which the user can choose an item. It
can be a list of strings or an alist mapping strings to return
-values.
+values. Users can switch to `completing-read' from COLLECTION
+using the TAB key.
ACTIONS is an additional list of actions that can be given to let
the user choose an action instead an item from COLLECTION.
@@ -603,11 +621,12 @@ RETURN will be the returned value if KEY is pressed."
(let* ((frog-menu-type (funcall frog-menu-type-function))
(convf (and collection (consp (car collection))
#'car))
+ (strings (if convf
+ (mapcar convf collection)
+ collection))
(buf (frog-menu--init-buffer (get-buffer-create frog-menu--buffer)
prompt
- (if convf
- (mapcar convf collection)
- collection)
+ strings
actions))
(dhandler (cdr (assq frog-menu-type
frog-menu-display-handler-alist)))
@@ -623,6 +642,8 @@ RETURN will be the returned value if KEY is pressed."
(setq res (funcall qhandler buf window actions))
(when cuhandler
(funcall cuhandler buf window)))
+ (when (eq res 'frog-menu--complete)
+ (setq res (frog-menu--complete prompt strings)))
(cond ((eq convf #'car)
(cdr (assoc res collection)))
(t res))))
@@ -632,3 +653,6 @@ RETURN will be the returned value if KEY is pressed."
(provide 'frog-menu)
;;; frog-menu.el ends here
+
+
+