emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/frog-menu 3e0d9b9 1/3: Add frog-menu-sort-function vari


From: Clemens Radermacher
Subject: [elpa] externals/frog-menu 3e0d9b9 1/3: Add frog-menu-sort-function variable
Date: Tue, 30 Apr 2019 09:46:20 -0400 (EDT)

branch: externals/frog-menu
commit 3e0d9b9237b35919b1bf750d9d66d3b110496213
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>

    Add frog-menu-sort-function variable
---
 frog-menu.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/frog-menu.el b/frog-menu.el
index 1fd85a2..4f39ad7 100644
--- a/frog-menu.el
+++ b/frog-menu.el
@@ -592,6 +592,15 @@ user."
                                           (mapcar #'symbol-name cmds)))))
     (command-execute cmd)))
 
+(defvar frog-menu-sort-function nil
+  "A function to sort displayed strings for `frog-menu-read'.
+
+If this variable is bound to a function `frog-menu-read' will
+pass the strings to be displayed and the function to `sort':
+
+    (let ((frog-menu-sort-function #'string<))
+      (frog-menu-read \"Example\" '(\"z\" \"a\")))")
+
 
 ;;;###autoload
 (defun frog-menu-read (prompt collection &optional actions)
@@ -602,7 +611,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. Users can switch to `completing-read' from COLLECTION
-using the TAB key.
+using the TAB key. For sorting the displayed strings see
+`frog-menu-sort-function'.
 
 ACTIONS is an additional list of actions that can be given to let
 the user choose an action instead an item from COLLECTION.
@@ -624,6 +634,9 @@ RETURN will be the returned value if KEY is pressed."
          (strings (if convf
                       (mapcar convf collection)
                     collection))
+         (strings (if frog-menu-sort-function
+                      (sort strings frog-menu-sort-function)
+                    strings))
          (buf (frog-menu--init-buffer (get-buffer-create frog-menu--buffer)
                                       prompt
                                       strings



reply via email to

[Prev in Thread] Current Thread [Next in Thread]