Skip to content

Fix M-r history search losing newest-first order - #44

Open
mrcnski wants to merge 1 commit into
xenodium:mainfrom
mrcnski:fix/search-history-sort-order
Open

Fix M-r history search losing newest-first order#44
mrcnski wants to merge 1 commit into
xenodium:mainfrom
mrcnski:fix/search-history-sort-order

Conversation

@mrcnski

@mrcnski mrcnski commented Aug 30, 2026

Copy link
Copy Markdown

Issue: see PR title. Found in agent-shell.

Details

shell-maker-search-history builds its candidates from (ring-elements comint-input-ring), which is already ordered newest first, but hands them to
completing-read as a bare list. Without display-sort-function metadata, the
completion frontend applies its own order: vertico re-sorts by length and then
alphabetically, default completion sorts the *Completions* buffer
alphabetically. Recent prompts end up buried.

Repro

In any shell-maker shell with vertico at default settings, submit bbb, then
a, then cc, and hit M-r — candidates show as a, cc, bbb instead of
cc, a, bbb.

Fix

Wrap the candidates in a completion table that declares display-sort-function
and cycle-sort-function as identity, so every frontend keeps the ring order
and M-r matches comint's own newest-first history commands. A plain closure
rather than a newer metadata helper, to stay within the emacs "27.1" floor.

(delete-dups keeping the first — i.e. most recent — occurrence of a repeated
prompt is intentional and unchanged.)

🤖 Generated with Claude Code

Hand completing-read a completion table whose display-sort-function
and cycle-sort-function metadata preserve the input ring's
newest-first order, instead of a bare list that completion frontends
re-sort (vertico: by length then alphabetically; default completion:
alphabetically).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant