M2 icon indicating copy to clipboard operation
M2 copied to clipboard

Ctrl+D duplicates persistent readline history

Open mahrud opened this issue 1 year ago • 3 comments

Persistent history in terminal sessions as well as vscode using readline now works (#2819, #3403), but there's a minor issue: exiting the terminal with Ctrl+D causes the last item stored in the history to be duplicated. A few possible solutions:

  1. delete empty history entries before appending
  2. advance lineNumber before exit and restart end the session, then switch to saving lineNumber-1 lines (so Ctrl+D skips one relatively).

Overall, I've forgotten how Ctrl+D interrupts are caught and handled, so clarity there would be useful.

mahrud avatar Aug 13 '24 05:08 mahrud

Another issue, raised by @MichaelABurr, is that currently the history is uncapped. libhistory provides history_truncate_file for keeping the last N entries. I'm not sure what is a good maximum, but maybe we can set a default and make sure it is adjustable in init.m2.

ps: I should note that history is not saved at all when --no-readline is passed, which is the case by default when starting M2 from Emacs.

mahrud avatar Aug 30 '24 11:08 mahrud

Looking at a few other users of readline:

  • Python defaults to unlimited history, but it can be modified by calling readline.set_history_length.
  • R defaults to 512 lines, but it can be modified using the R_HISTSIZE environment variable.
  • Bash defaults to 500 lines, but it can be modified using the HISTSIZE environment variable.

d-torrance avatar Aug 30 '24 12:08 d-torrance

I'm honestly unsure if it's super necessary. Like I mentioned, M2 loads ~480 files on startup! How about something really high like 10000 as default?

mahrud avatar Aug 31 '24 09:08 mahrud