Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fzf #216

Merged
merged 3 commits into from
Sep 1, 2020
Merged

Fzf #216

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.5.6"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
JLFzf = "1019f520-868f-41f5-a6de-eb00f4b6a39c"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand All @@ -13,6 +14,7 @@ Tokenize = "0796e94c-ce3b-5d07-9a54-7f471281c624"
[compat]
Crayons = "1, 2, 3, 4"
Tokenize = "0.5"
JLFzf = "^0.1.1"
julia = "1.0"

[extras]
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
julia 0.7-
Crayons
Tokenize
JLFzf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUIRE. Good times 😄

21 changes: 19 additions & 2 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ version = "0.25.2"
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JLFzf]]
deps = ["Pipe", "REPL", "Random", "fzf_jll"]
git-tree-sha1 = "cf18655fe5cb3ab4c6d129207c750337b3f2ad14"
uuid = "1019f520-868f-41f5-a6de-eb00f4b6a39c"
version = "0.1.1"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
Expand All @@ -56,8 +62,8 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[OhMyREPL]]
deps = ["Crayons", "Markdown", "Pkg", "Printf", "REPL", "Tokenize"]
git-tree-sha1 = "7184cf792033092d6c0bcd5a5059deae89205e04"
deps = ["Crayons", "JLFzf", "Markdown", "Pkg", "Printf", "REPL", "Tokenize"]
path = ".."
uuid = "5fb14364-9ced-5910-84b2-373655c76a03"
version = "0.5.6"

Expand All @@ -67,6 +73,11 @@ git-tree-sha1 = "8077624b3c450b15c087944363606a6ba12f925e"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.10"

[[Pipe]]
git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d"
uuid = "b98c9c47-44ae-5843-9183-064241ee97a0"
version = "1.3.0"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand Down Expand Up @@ -107,3 +118,9 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[fzf_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "d1aec59bb46c05f3881aaedf0deac2df37b05374"
uuid = "214eeab7-80f7-51ab-84ad-2988db7cef09"
version = "0.21.1+0"
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ makedocs(
"features/prompt.md",
"features/rainbow_brackets.md",
"features/markdown_highlight.md",
"features/fzf.md",
],
"Internals" => Any[
"internals/passes.md"
Expand Down
13 changes: 13 additions & 0 deletions docs/src/features/fzf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Fuzzy REPL history search

![](fzf.png)

By default (on Julia 1.3+ and non-Windows installations), OhMyREPL will use
[fzf](https://github.com/junegunn/fzf) to search in the REPL history (initiated
by pressing Ctrl-R). This is a [fuzzy
searcher](https://en.wikipedia.org/wiki/Approximate_string_matching) which means
that you don't need to verbatim enter what you want to match. So if you wrote
`@eval Base foo(x) = x+1` at some time you can search for e.g. `@eval foo` to
find it.

This feature can be turned on/off using `enable_fzf(::Bool)`.
Binary file added docs/src/features/fzf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Pages = [
"features/bracket_complete.md",
"features/rainbow_brackets.md",
"features/markdown_highlight.md",
"features/fzf.md",
"internals/passes.md"
]
Depth = 1
Expand Down
9 changes: 8 additions & 1 deletion src/OhMyREPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ module OhMyREPL

using Tokenize
using Crayons
if VERSION > v"1.3"
import JLFzf
end

import REPL

export colorscheme!, colorschemes, enable_autocomplete_brackets, enable_highlight_markdown, test_colorscheme
export colorscheme!, colorschemes, enable_autocomplete_brackets, enable_highlight_markdown, enable_fzf, test_colorscheme

include("repl_pass.jl")
include("repl.jl")
Expand Down Expand Up @@ -78,6 +82,9 @@ showpasses(io::IO = stdout) = Base.show(io, PASS_HANDLER)
const HIGHLIGHT_MARKDOWN = Ref(true)
enable_highlight_markdown(v::Bool) = HIGHLIGHT_MARKDOWN[] = v

const ENABLE_FZF = Ref(!Sys.iswindows())
enable_fzf(v::Bool) = ENABLE_FZF[] = v

function __init__()
options = Base.JLOptions()
# command-line
Expand Down
16 changes: 13 additions & 3 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function create_keybindings()
# Meta B
D["\eb"] = (s, data, c) -> (LineEdit.edit_move_word_left(s) ; rewrite_with_ANSI(s))
# Meta F
D["\ef"] = (s, data, c) -> (LineEdit.edit_move_word_right(s); rewrite_with_ANSI(s))
D["\ef"] = (s, data, c) -> (LineEdit.edit_move_word_right(s); rewrite_with_ANSI(s))
# Meta Enter
D["\e\r"] = (s, data, c) -> (LineEdit.edit_insert(buffer(s), '\n'); rewrite_with_ANSI(s))
D["^A"] = (s, data, c) -> (LineEdit.move_line_start(s); rewrite_with_ANSI(s))
Expand Down Expand Up @@ -267,6 +267,18 @@ function create_keybindings()
rewrite_with_ANSI(s)
end

#replace search with Fzf fuzzy search
D["^R"] = function (s, data, c)
if VERSION >= v"1.3" && OhMyREPL.ENABLE_FZF[]
JLFzf = OhMyREPL.JLFzf
line = JLFzf.inter_fzf(JLFzf.read_repl_hist(), "--read0", "--tiebreak=index");
JLFzf.insert_history_to_repl(s, line)
rewrite_with_ANSI(s)
else
p = Base.active_repl.interface.modes[4]
LineEdit.enter_search(s, p, true)
end
end
return D
end
NEW_KEYBINDINGS = create_keybindings()
Expand All @@ -287,8 +299,6 @@ function insert_keybindings(repl = Base.active_repl)
Prompt.rewrite_with_ANSI(s)
end



main_mode.keymap_dict = LineEdit.keymap([NEW_KEYBINDINGS, main_mode.keymap_dict])
end

Expand Down