Skip to content

Commit 07579a6

Browse files
committed
Retire > history search mode in favour of prefix>
This allows for search strings to be typed out as they are at the REPL, e.g. "julia> test123" (only in word mode). This seems natural enough that the > search mode is no longer needed.
1 parent d9231bc commit 07579a6

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

stdlib/REPL/src/History/resumablefiltering.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const FILTER_SEPARATOR = ';'
2424
2525
List of single-character prefixes that set search modes.
2626
"""
27-
const FILTER_PREFIXES = ('!', '`', '=', '/', '~', '>')
27+
const FILTER_PREFIXES = ('!', '`', '=', '/', '~')
2828

2929
"""
3030
FILTER_SHORTHELP_QUERY
@@ -53,20 +53,22 @@ const FILTER_SHORTHELP = S"""
5353
5454
See more information on behaviour and keybindings with '{REPL_History_search_prefix:??}'.
5555
56+
By default, each word in the search string is looked for in any order.
57+
Should the search string start with {REPL_History_search_prefix:xyz>}, then only xyz-mode entries are considered.
58+
5659
Different search modes are available via prefixes, as follows:
5760
{emphasis:•} {REPL_History_search_prefix:=} looks for exact matches
5861
{emphasis:•} {REPL_History_search_prefix:!} {italic:excludes} exact matches
5962
{emphasis:•} {REPL_History_search_prefix:/} performs a regexp search
6063
{emphasis:•} {REPL_History_search_prefix:~} looks for fuzzy matches
61-
{emphasis:•} {REPL_History_search_prefix:>} looks for a particular REPL mode
6264
{emphasis:•} {REPL_History_search_prefix:`} looks for an initialism (text with matching initials)
6365
6466
You can also apply multiple restrictions with the separator '{REPL_History_search_separator:$FILTER_SEPARATOR}'.
6567
6668
For example, {region:{REPL_History_search_prefix:/}^foo{REPL_History_search_separator:$FILTER_SEPARATOR}\
6769
{REPL_History_search_prefix:`}bar{REPL_History_search_separator:$FILTER_SEPARATOR}\
68-
{REPL_History_search_prefix:>}shell} will look for history entries that start with "{code:foo}",
69-
contains "{code:b... a... r...}", {italic:and} is a shell history entry.
70+
{REPL_History_search_prefix:shell>}} will look for history entries that start with "{code:foo}",
71+
contains "{code:b... a... r...}", {italic:and} are a shell history entry.
7072
"""
7173

7274
const FILTER_LONGHELP = S"""
@@ -108,9 +110,9 @@ function ConditionSet(spec::S) where {S <: AbstractString}
108110
function addcond!(condset::ConditionSet, cond::SubString)
109111
isempty(cond) && return
110112
kind = first(cond)
111-
if kind ('!', '=', '`', '/', '>', '~')
113+
if kind ('!', '=', '`', '/', '~')
112114
value = @view cond[2:end]
113-
if kind ('`', '>', '~')
115+
if kind ('`', '~')
114116
value = strip(value)
115117
elseif !all(isspace, value)
116118
value = if kind == '/'
@@ -128,16 +130,23 @@ function ConditionSet(spec::S) where {S <: AbstractString}
128130
push!(condset.initialisms, value)
129131
elseif startswith(cond, '/')
130132
push!(condset.regexps, value)
131-
elseif startswith(cond, '>')
132-
push!(condset.modes, SubString(lowercase(value)))
133133
elseif startswith(cond, '~')
134134
push!(condset.fuzzy, value)
135135
end
136136
else
137137
if startswith(cond, '\\') && !(length(cond) > 1 && cond[2] == '\\')
138138
cond = @view cond[2:end]
139+
else
140+
rang = something(findfirst('>', cond), typemax(Int))
141+
if rang == something(findfirst(isspace, cond), ncodeunits(cond) + 1) - 1
142+
mode = @view cond[1:prevind(cond, rang)]
143+
push!(condset.modes, SubString(lowercase(mode)))
144+
cond = @view cond[rang + 1:end]
145+
end
139146
end
140-
push!(condset.words, strip(cond))
147+
cond = strip(cond)
148+
isempty(cond) && return
149+
push!(condset.words, cond)
141150
end
142151
nothing
143152
end

stdlib/REPL/test/history.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ end
206206
@test cset.regexps == [SubString("foo.*bar")]
207207
end
208208
@testset "Mode" begin
209-
cset = ConditionSet(">shell")
209+
cset = ConditionSet("shell>")
210210
@test cset.modes == [SubString("shell")]
211211
end
212212
@testset "Fuzzy" begin
@@ -233,7 +233,7 @@ end
233233
@test cset.exacts == [SubString("exact")]
234234
end
235235
@testset "Complex query" begin
236-
cset = ConditionSet("some = words ;; !error ;> julia;/^def.*;")
236+
cset = ConditionSet("some = words ;; !error ; julia> ;/^def.*;")
237237
@test cset.words == [SubString("some = words")]
238238
@test cset.negatives == [SubString("error")]
239239
@test cset.modes == [SubString("julia")]
@@ -254,7 +254,7 @@ end
254254
@test isempty(spec2.regexps)
255255
end
256256
@testset "Complex query" begin
257-
cset = ConditionSet("=exact;!neg;/foo.*bar;>julia")
257+
cset = ConditionSet("=exact;!neg;/foo.*bar;julia>")
258258
spec = FilterSpec(cset)
259259
@test spec.exacts == ["exact"]
260260
@test spec.negatives == ["neg"]
@@ -332,7 +332,7 @@ end
332332
end
333333
@testset "Mode" begin
334334
empty!(results)
335-
cset = ConditionSet(">shell")
335+
cset = ConditionSet("shell>")
336336
spec = FilterSpec(cset)
337337
@test filterchunkrev!(results, entries, spec) == 0
338338
@test results == [entries[7]]

0 commit comments

Comments
 (0)