>> That being said, yes this may be nice. But minibuffer-completion-help >> already does sort the completions using display-sort-function, just like >> completion-all-sorted-completions, so what's causing the difference in >> behavior? > > It seems this is implementable in minibuffer-completion-help > by copying this code from completion-all-sorted-completions: > > (setq all (minibuffer--sort-by-position > (minibuffer--sort-preprocess-history > (substring string 0 base-size)) > all)) Oh, very interesting! Maybe completions-sort should accept a new symbol 'history to behave this way? I already think this would be very nice for project-switch-project, for example, since I'm often switching between a few related projects. Perhaps 'history should break ties by alphabetizing, otherwise e.g. filenames you haven't visited before would be unsorted randomly. Hmm, actually the case of filenames is a bit complex. Because for filenames, the strings we're completing over don't appear verbatim in the history. So perhaps read-file-name would need its own specialized sorting function, which whenever you're completing in some directory, sorts to the front any files in that directory whose full path appears in file-name-history. >> Honestly the main place I find myself wanting different sorting of >> completions is for buffer completion - I'd prefer buffers to be sorted >> by most-recently-used. Maybe we can just add such an option? > > Such an option would be nice. Maybe the right way to support it > is to add a new sort function with the code above. Then the caller > could provide such a function in the completion metadata. Oh, that's also interesting. So there would be a function that the completion metadata could specify as display-sort-function, which would have the behavior of sorting based on history? That also makes a lot of sense, and would allow commands like project-switch-project and read-buffer to opt in on a command-by-command basis, which might be more sensible. So maybe adding 'history as a new option for completions-sort isn't a good idea. Instead we should just add user options for enabling history sorting for files and buffers. (And perhaps we could just enable history sorting by default for project-switch-project.) Also: it might be nice to switch between history-sorting and alphabetized-sorting during the course of completion, both for files and buffers. Maybe we could do that by making a command which puts completion into a mode where it just ignores the display-sort-function specified by the completion metadata, and just always uses completions-sort.