+1
On Wednesday, October 29, 2014 9:56:33 PM UTC+1, Elliot Saba wrote: > > I really like the concept; I can't tell you how many times I've tried to > tab-complete dict keys. > -E > > On Wed, Oct 29, 2014 at 1:36 PM, Ivar Nesje <[email protected] > <javascript:>> wrote: > >> Nice. What do people think about adding this functionality to Base? >> >> If anyone likes to read code in a gist, rather than in an email, I made >> a link <https://gist.github.com/ivarne/d232c1a815222fc5f896> >> >> Regards Ivar >> >> kl. 21:07:45 UTC+1 onsdag 29. oktober 2014 skrev [email protected] >> følgende: >> >>> I get it work ^ ^ Haha!! >>> Thank you for your information! >>> >>> First, insert below code in the beginning of "completions" function in >>> /base/REPLCompletions.jl >>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FJuliaLang%2Fjulia%2Fblob%2Fmaster%2Fbase%2FREPLCompletions.jl%23L185&sa=D&sntz=1&usg=AFQjCNHzQ0VkvZjQihp3roolMlmxAe9LHQ> >>> : >>> try >>> if isdefined(Main, :CUSTOM_AUTOCOMPLETION_HOOK) >>> t=Main.CUSTOM_AUTOCOMPLETION_HOOK(string, pos) >>> if t[3] >>> return t >>> end >>> end >>> catch err >>> println("Error in CUSTOM_AUTOCOMPLETION_HOOK:") >>> println(err) >>> end >>> And recompile Julia. Now I have a hook for the custom-autocompletion. >>> >>> Second, I define such function: >>> function CUSTOM_AUTOCOMPLETION_HOOK(txt,pos) >>> m=match(r"(\w+)\[\"([^\"]*)$",txt[1:pos]) >>> if !isa(m,Nothing) >>> #For String key >>> if !isdefined(Main,parse(m.captures[1])) >>> return UTF8String[], 0:-1, false >>> end >>> var=eval(parse(m.captures[1])) >>> if !applicable(keys,var) >>> return UTF8String[], 0:-1, false >>> end >>> ky=keys(var) >>> if length(ky)>500 >>> return UTF8String[], 0:-1, false >>> end >>> ky=[filter(x->isa(x,String),ky)...] >>> lst=convert(Vector{UTF8String},[filter(x->beginswith(x,m. >>> captures[2]),ky)...]) >>> if !(length(txt)>=pos+1 && txt[pos+1]=='\"') >>> if length(txt)>=pos+1 && txt[pos+1]==']' >>> lst=map(x->x*"\"",lst) >>> else >>> lst=map(x->x*"\"]",lst) >>> end >>> end >>> return lst, (pos-length(m.captures[2])+1):pos, true >>> else >>> #For symbol key >>> m=match(r"(\w+)\[\:(\w*)$",txt[1:pos]) >>> if isa(m,Nothing) || !isdefined(Main,parse(m.captures[1])) >>> return UTF8String[], 0:-1, false >>> end >>> var=eval(parse(m.captures[1])) >>> if !applicable(keys,var) >>> return UTF8String[], 0:-1, false >>> end >>> ky=keys(var) >>> if length(ky)>500 >>> return UTF8String[], 0:-1, false >>> end >>> ky=map(string,[filter(x->isa(x,Symbol),ky)...]) >>> lst=convert(Vector{UTF8String},[filter(x->beginswith(x,m. >>> captures[2]),ky)...]) >>> if !(length(txt)>=pos+1 && txt[pos+1]==']') >>> lst=map(x->x*"]",lst) >>> end >>> return lst, (pos-length(m.captures[2])+1):pos, true >>> end >>> end >>> >>> Now it is work on string and symbol key, really cool! >>> It can also auto-complete the method of python object ^ ^v >>> >>> On Wednesday, October 29, 2014 11:47:32 AM UTC+1, Ivar Nesje wrote: >>>> >>>> That would be cool! >>>> >>>> Currently there isn't any hooks you can use for that purpose (I >>>> believe), but as most of Julia is written in Julia, it should be a >>>> reasonable project to include the required functionality in >>>> /base/REPLCompletions.jl >>>> <https://github.com/JuliaLang/julia/blob/master/base/REPLCompletions.jl#L185> >>>> and submit a pull request on Github. This would likely be nice for >>>> other associative structures (PyCall anyone?) also. >>>> >>>> You will have to look for unclosed `[` that is either empty or continue >>>> with a `:` indicating a symbol or `"` indicating a string index. >>>> >>>> Ivar >>>> >>>> kl. 10:06:19 UTC+1 onsdag 29. oktober 2014 skrev [email protected] >>>> følgende: >>>>> >>>>> Is there any way to add an customal autocomplete list to Julia REPL? >>>>> For example, I really hope the Dict can be as convenient as MATLAB >>>>> structure that the keys can be autpcompleted in command line. >>>>> >>>> >
