Skip to content

Commit

Permalink
Add user preference "HistoryBackwardSearchSkipIdenticalEntries" (#5366)
Browse files Browse the repository at this point in the history
When a command is executed multiple times, it is also stored in history
multiple times. Setting this option to <K>true</K> skips identical entries
when searching backwards in history.
  • Loading branch information
zickgraf authored Mar 15, 2024
1 parent 226c77b commit a447299
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/ref/user_pref_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ Try <C>HelpViewers:= [ "screen", "firefox", "xpdf" ];</C>.
Defaults: <C>[ [ "screen" ], "", "" ]</C>.
</Item>
<Mark>
<Index Key='HistoryBackwardSearchSkipIdenticalEntries'><C>HistoryBackwardSearchSkipIdenticalEntries</C></Index>
<C>HistoryBackwardSearchSkipIdenticalEntries</C>
</Mark>
<Item>
When a command is executed multiple times, it is also stored in history
multiple times. Setting this option to <K>true</K> skips identical entries
when searching backwards in history.

<P/>

Admissible values:
<K>true</K>,
<K>false</K>.

<P/>

Default: <K>false</K>.
</Item>
<Mark>
<Index Key='HistoryMaxLines'><C>HistoryMaxLines</C></Index>
<Index Key='SaveAndRestoreHistory'><C>SaveAndRestoreHistory</C></Index>
<C>HistoryMaxLines</C>,
Expand Down
15 changes: 15 additions & 0 deletions lib/cmdledit.g
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ readline support.",
default := "default",
) );

DeclareUserPreference( rec(
name:= "HistoryBackwardSearchSkipIdenticalEntries",
description:= [
"When a command is executed multiple times, it is also stored in history \
multiple times. Setting this option to <K>true</K> skips identical entries \
when searching backwards in history."
],
default:= false,
values:= [ true, false ],
multi:= false,
) );


if GAPInfo.CommandLineOptions.E then
############################################################################
Expand Down Expand Up @@ -543,6 +555,9 @@ GAPInfo.CommandLineEditFunctions.Functions.BackwardHistory := function(l)
while n > 1 do
n := n - 1;
if PositionSublist(hist[n], start) = 1 then
if UserPreference("HistoryBackwardSearchSkipIdenticalEntries") and hist[n] = l[3] then
continue;
fi;
GAPInfo.History.Pos := n;
GAPInfo.History.Last := n;
return [1, Length(l[3])+1, hist[n], l[4]];
Expand Down

0 comments on commit a447299

Please sign in to comment.