I see, I should use meta-Backspace instead. And the undocumented shortcut 
for function arguments is cool! I didn't find that before!
Just for fun, I changed my code a little, to show help by function_name?\t, 
like:
julia> sin?\t
Base.sin(x)

   Compute sine of "x", where "x" is in radians
julia> sin?

function CUSTOM_AUTOCOMPLETION_HOOK(txt,pos)
    if txt[pos]=='?' && pos>1
        #Show help of function
        m=match(r"([\w\!]+)$",txt[1:pos-1])
        if !isa(m,Nothing)
            S=m.captures[1]
            if isdefined(parse(S))
                println("")
                help(S)
            end
            return UTF8String[], 0:-1, true
        end
    end
    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
            println("\nToo many keys to be auto-completed.")
            return UTF8String[], 0:-1, true
        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
            println("\nToo many keys to be auto-completed.")
            return UTF8String[], 0:-1, true
        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




On Thursday, October 30, 2014 10:39:43 AM UTC+1, Ivar Nesje wrote:
>
> We have different level of experience with key bindings, and we are used 
> to different things. You won't get far with "It really make me crazy" that 
> Julia doesn't work exactly as Matlab or R, but there are definitely still 
> possibilities to change behaviour if you manage to convince the community 
> that some other way is better. See also the docs 
> <http://docs.julialang.org/en/release-0.3/manual/interacting-with-julia/> 
> where 
> we attempt to describe the different key bindings, and it seems like you 
> are confusing meta-Backspace with ^w.
>
> We also have a really nice shortcut (that I can't find in the 
> documentation) where you can press TAB just after a left parens, and get a 
> list of the methods on the function. That is often more directly useful 
> than the help, when you need to lookup the order of the arguments.
>
> julia> sin(\t
> sin(a::Complex{Float16}) at float16.jl:141  sin(x::Real) at math.jl:125
> sin(z::Complex{T<:Real}) at complex.jl:518 
>  sin{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) at sparse/sparsematrix.jl:450
> sin(x::Float64) at math.jl:123             
>  sin{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:358
> sin(x::Float32) at math.jl:124             
>  sin{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:359
> sin(a::Float16) at float16.jl:140           
> sin{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:361
> sin(x::BigFloat) at mpfr.jl:488
>
>  This trick also works when you have started typing some of the arguments, 
> if you ensure that the cursor is right after the parens.
>
> Ivar
>
> kl. 10:07:37 UTC+1 torsdag 30. oktober 2014 skrev [email protected] 
> følgende:
>>
>> It will be prefect if the Tab can also auto-complete the argument names 
>> of a function, like what R did.
>>
>> Actually I have other complaints about REPL:
>> 1. Ctrl+w delected all the line rather than only the last word. It really 
>> make me crazy....
>> 2. If I push F1 in the REPL in termnal window (it is running in the 
>> server), the whole system clashed:
>> julia> ERROR: key not found: '\0'
>>  in match_input at LineEdit.jl:734 (repeats 3 times)
>>  in match_input at LineEdit.jl:731
>>  in anonymous at LineEdit.jl:833
>>  in prompt! at ./LineEdit.jl:1349
>>  in run_interface at ./LineEdit.jl:1324
>>  in run_interface_3B_9747 at 
>> /home/JXiong/programs/julia_0.3/julia/usr/bin/../lib/julia/sys.so
>>  in run_frontend at ./REPL.jl:819
>>  in run_repl at ./REPL.jl:170
>>  in _start at ./client.jl:399
>>  in _start_3B_9614 at 
>> /home/JXiong/programs/julia_0.3/julia/usr/bin/../lib/julia/sys.so
>>
>> I really like that in MATLAB, I can see the help of the function I am 
>> typing just by push F1. I think REPL could also support some hot-keys, like 
>> showing help, showing current directory, showing data tip, showing function 
>> argument hint, showing command history, and run a custom function during 
>> typing the command. In many time, I cannot remember the function argument 
>> order when I type command, I have to delete the whole line, check help, and 
>> retype it again. How do you think about it?
>>
>> On Wednesday, October 29, 2014 11:02:54 PM UTC+1, Max Suster wrote:
>>>
>>> +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]> 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.
>>>>>>>>
>>>>>>>
>>>>

Reply via email to