-
Notifications
You must be signed in to change notification settings - Fork 7
automatic peco install on julia>=1.3 #10
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
Open
rapus95
wants to merge
2
commits into
tkf:master
Choose a base branch
from
rapus95:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,23 +47,34 @@ | |
| using Base: IOError | ||
| using InteractiveUtils: edit, gen_call_with_extracted_types, methodswith | ||
|
|
||
| function _readandwrite(cmds) | ||
| processes = open(cmds, "r+") | ||
| return (processes.out, processes.in, processes) | ||
| end | ||
|
|
||
|
|
||
| abstract type SearchPolicy end | ||
| struct Shallow <: SearchPolicy end | ||
| struct Recursive <: SearchPolicy end | ||
|
|
||
|
|
||
| mutable struct SearchConfig # CONFIG | ||
| open | ||
| interactive_matcher::Cmd | ||
| interactive_matcher::Function | ||
| auto_open::Bool | ||
| end | ||
|
|
||
| function setmatcher!(cmd::Function, obj::SearchConfig) | ||
| obj.interactive_matcher = cmd | ||
| return | ||
| end | ||
|
|
||
| function setmatcher!(cmd::Cmd, obj::SearchConfig) | ||
| setmatcher!(convertCmd(cmd), obj) | ||
| end | ||
|
|
||
| function convertCmd(cmd) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use snake_case. |
||
| maybe_warn_matcher(cmd) | ||
| return function (f) | ||
| maybe_warn_matcher(cmd) | ||
| f(cmd) | ||
| end | ||
| end | ||
|
|
||
| maybe_identifier(s) = !startswith(string(s), "#") | ||
|
|
||
| is_locatable(::Any) = false | ||
|
|
@@ -147,6 +158,12 @@ | |
| return path | ||
| end | ||
|
|
||
| function _readandwrite(matcher) | ||
| proc = matcher() do cmd | ||
| open(`$cmd`, "r+") | ||
| end | ||
| return (proc.out, proc.in, proc) | ||
| end | ||
|
|
||
| """ | ||
| read_stdout(input::AbstractString, cmd) | ||
|
|
@@ -182,7 +199,6 @@ | |
| end | ||
|
|
||
| function run_matcher(input) | ||
| maybe_warn_matcher() | ||
| return String(read_stdout(input, CONFIG.interactive_matcher)) | ||
| end | ||
|
|
||
|
|
@@ -265,8 +281,7 @@ | |
|
|
||
| ## Using InteractiveCodeSearch.jl by default | ||
|
|
||
| Put the following code in your `~/.julia/config/startup.jl` (≥ Julia 0.7) | ||
| or `~/.juliarc.jl` (Julia 0.6): | ||
| Put the following code in your `~/.julia/config/startup.jl`: | ||
|
|
||
| ```julia | ||
| using InteractiveCodeSearch | ||
|
|
@@ -275,7 +290,7 @@ | |
| """ | ||
| const CONFIG = SearchConfig( | ||
| edit, # open | ||
| `peco`, # interactive_matcher | ||
| x->error("uninitialized"), # interactive_matcher | ||
| true, # auto_open | ||
| ) | ||
|
|
||
|
|
@@ -437,10 +452,23 @@ | |
| end | ||
| end | ||
|
|
||
| const preferred_terminal = Cmd[ | ||
| `peco`, | ||
| `percol`, | ||
| ] | ||
| ################################################################################ | ||
| # matcher binaries # | ||
| ################################################################################ | ||
|
|
||
| @static if VERSION<v"1.3-" | ||
| const preferred_terminal = Cmd[ | ||
| `peco`, | ||
| `percol`, | ||
| ] | ||
| else | ||
| using peco_jll | ||
| const preferred_terminal = Union{Function,Cmd}[ | ||
| `peco`, | ||
| peco, | ||
| `percol`, | ||
| ] | ||
| end | ||
|
|
||
| const preferred_gui = Cmd[ | ||
| `rofi -dmenu -i -p "🔎"`, | ||
|
|
@@ -451,43 +479,18 @@ | |
| return !all(isa.(stdstreams, Ref(Base.TTY))) | ||
| end | ||
|
|
||
| function choose_preferred_command(commands::Vector{Cmd}) | ||
| function choose_preferred_command(commands::Vector{<:Union{Function,Cmd}}, default=nothing) | ||
| for cmd in commands | ||
| if Sys.which(cmd.exec[1]) !== nothing | ||
| if !(cmd isa Cmd) || Sys.which(cmd.exec[1]) !== nothing | ||
| return cmd | ||
| end | ||
| end | ||
| return nothing | ||
| end | ||
|
|
||
| function choose_preferred_command(f, commands::Vector{Cmd}) | ||
| cmd = choose_preferred_command(commands) | ||
| if cmd !== nothing | ||
| return cmd | ||
| else | ||
| return f() | ||
| end | ||
| return default | ||
| end | ||
|
|
||
| # Julia 0.6 | ||
| const _preferred_terminal = preferred_terminal | ||
| const _preferred_gui = preferred_gui | ||
|
|
||
| function choose_interactive_matcher(; | ||
| preferred_terminal = _preferred_terminal, | ||
| preferred_gui = _preferred_gui, | ||
| gui = need_gui()) | ||
| if gui | ||
| return choose_preferred_command(preferred_gui) do | ||
| return preferred_gui[1] | ||
| end | ||
| else | ||
| return choose_preferred_command(preferred_terminal) do | ||
| return choose_preferred_command(preferred_gui) do | ||
| return preferred_terminal[1] | ||
| end | ||
| end | ||
| end | ||
| function choose_interactive_matcher() | ||
| need_gui() && return choose_preferred_command(preferred_gui, preferred_gui[1]) | ||
| return choose_preferred_command(vcat(preferred_terminal, preferred_gui), preferred_terminal[1]) | ||
| end | ||
|
|
||
| function matcher_installation_tips(program::AbstractString) | ||
|
|
@@ -509,7 +512,7 @@ | |
| """ | ||
| end | ||
|
|
||
| function maybe_warn_matcher(cmd = CONFIG.interactive_matcher) | ||
| function maybe_warn_matcher(cmd::Cmd) | ||
| if Sys.which(cmd.exec[1]) === nothing | ||
| @warn """ | ||
| Matcher $(cmd.exec[1]) not installed. | ||
|
|
@@ -519,8 +522,7 @@ | |
| end | ||
|
|
||
| function __init__() | ||
| CONFIG.interactive_matcher = choose_interactive_matcher() | ||
| maybe_warn_matcher() | ||
| setmatcher!(choose_interactive_matcher(), CONFIG) | ||
| end | ||
|
|
||
| include("taskmanager.jl") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks backward-compatibility. Let's still support
and just remove
::Cmd. The idea is to use run-time dispatch: #6 (comment)