unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Juri Linkov <juri@linkov.net>, Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi@gnus.org>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: [External] : Re: Sorting command completions by recency
Date: Wed, 17 Feb 2021 22:02:53 +0000	[thread overview]
Message-ID: <SA2PR10MB44747DC053D033AB357B3B55F3869@SA2PR10MB4474.namprd10.prod.outlook.com> (raw)
In-Reply-To: <87o8gifoci.fsf@mail.linkov.net>

> 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	other threads:[~2021-02-17 22:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 17:53 Sorting command completions by recency Juri Linkov
2021-02-17 18:33 ` Lars Ingebrigtsen
2021-02-17 19:55   ` Stefan Monnier
2021-02-17 20:03     ` Clemens
2021-02-17 20:58       ` Stefan Monnier
2021-02-18 17:34         ` Juri Linkov
2021-02-17 20:09     ` Juri Linkov
2021-02-17 22:02       ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SA2PR10MB44747DC053D033AB357B3B55F3869@SA2PR10MB4474.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).