Skip to content

Commit

Permalink
Add user preference "HistoryBackwardSearchUntilChanged"
Browse files Browse the repository at this point in the history
When executing the same command multiple times, it is stored in history
multiple times and also appears multiple times when doing a backward search
in the history. Setting this option to <K>true</K> ensures that during a
backward search a history item is selected which actually changes the
currently displayed line. Note: This does not affect forward searches.
  • Loading branch information
zickgraf committed Mar 13, 2023
1 parent 361953a commit 723a4bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions doc/ref/user_pref_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ Try <C>HelpViewers:= [ "screen", "firefox", "xpdf" ];</C>.
Defaults: <C>[ [ "screen" ], "", "" ]</C>.
</Item>
<Mark>
<Index Key='HistoryBackwardSearchUntilChanged'><C>HistoryBackwardSearchUntilChanged</C></Index>
<C>HistoryBackwardSearchUntilChanged</C>
</Mark>
<Item>
When executing the same command multiple times, it is stored in history
multiple times and also appears multiple times when doing a backward search in
the history. Setting this option to <K>true</K> ensures that during a backward
search a history item is selected which actually changes the currently
displayed line. Note: This does not affect forward searches.

<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
17 changes: 17 additions & 0 deletions lib/cmdledit.g
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ readline support.",
default := "default",
) );

DeclareUserPreference( rec(
name:= "HistoryBackwardSearchUntilChanged",
description:= [
"When executing the same command multiple times, it is stored in history \
multiple times and also appears multiple times when doing a backward search \
in the history. Setting this option to <K>true</K> ensures that during a \
backward search a history item is selected which actually changes the \
currently displayed line. Note: This does not affect forward searches."
],
default:= false,
values:= [ true, false ],
multi:= false,
) );


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

Check warning on line 562 in lib/cmdledit.g

View check run for this annotation

Codecov / codecov/patch

lib/cmdledit.g#L560-L562

Added lines #L560 - L562 were not covered by tests
GAPInfo.History.Pos := n;
GAPInfo.History.Last := n;
return [1, Length(l[3])+1, hist[n], l[4]];
Expand Down

0 comments on commit 723a4bd

Please sign in to comment.