emacs-devel
[Top][All Lists]
Advanced

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

RE: [External] : Re: Sorting command completions by recency


From: Drew Adams
Subject: RE: [External] : Re: Sorting command completions by recency
Date: Wed, 17 Feb 2021 22:02:53 +0000

> Maybe a new option should allow switching the sorting order.
> Perhaps, it should have a form of an alist:
> 
>   '(("alphabetical" . identity)
>     ("by recency" .
>?      (lambda (commands)
>        (if (minibufferp)
>            (let ((hist
>                   (symbol-value
>                     minibuffer-history-variable)))
>              (sort commands ...

FWIW, Icicles has such an option (but it also lets
you change the option value during completion, by
hitting a key).

Commands can bind it to get relevant sort orders.
For example, this is its let-binding for command
`icicle-complete-keys':

(icicle-sort-orders-alist
  '(("by key name, local bindings first" . icicle-local-keys-first-p)
    ("by key name, prefix keys first" . icicle-prefix-keys-first-p)
    ("by command name" . icicle-command-names-alphabetic-p)
    ("turned OFF")))

,----
| icicle-sort-orders-alist is a variable defined in `icicles-opt.el'.
| Its value is nil.
| 
| Documentation:
| Alist of available sort functions.
| This is a pseudo option - you probably do NOT want to customize this.
| Instead, use macro `icicle-define-sort-command' to define a new sort
| function and automatically add it to this list.
| 
| Each alist element has the form (SORT-ORDER . COMPARER):
| 
|  SORT-ORDER is a short string or symbol describing the sort order.
|  Examples: "by date", "alphabetically", "directories first".
| 
|  COMPARER compares two items.  It must be acceptable as a value of
|  `icicle-sort-comparer'.
| 
| You can customize this variable.
`----

COMPARER here can be a simple predicate; a list
of special predicates, which return (t) for true,
(nil) for false, or nil for undecided; or such a
list followed by a simple predicate.

You can easily combine multiple predicates in a
manner similar to running through hook functions
with `run-hook-with-args-until-(failure|success)',
i.e. until one of the predicates decides:

https://www.emacswiki.org/emacs/ApplesAndOranges

(Bookmark+ makes more use of such predicate
combinations.  It uses the same idea.)
 
Macro `define-sort-command' defines a command to
switch to a given sort order during completion
(or any other time).

Sorting, together with filtering and progressive
completion (aka narrowing), can greatly improve
usability.  Cycling without being able to sort in a
useful way can amount to drudgery.

https://www.emacswiki.org/emacs/Icicles_-_Sorting_Candidates

HTH.



reply via email to

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