randy3k / SendCode

Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, Terminus; R (RStudio), Julia, IPython.
MIT License
204 stars 28 forks source link

How do I send request to open the help in Julia? #108

Open PetrKryslUCSD opened 5 years ago

PetrKryslUCSD commented 5 years ago

Binding the key as

// Send code to display help information
    {
        "keys": ["ctrl+shift+h", "ctrl+h"], "command": "send_code",
        "args": {"cmd": " ?$selection"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.julia" }
        ]
    }

results in an error: ERROR: syntax: invalid identifier name "?"

What am I missing?

PetrKryslUCSD commented 5 years ago

Actually, it also does the same thing with no leading space ("args": {"cmd": "?$selection"},).

PetrKryslUCSD commented 5 years ago

To clarify: this is what gets printed:

julia> ?collect                                                                   
ERROR: syntax: invalid identifier name "?"    

when the selection is "collect".

randy3k commented 5 years ago

It does not work because julia interprets ?$selection as a whole thing. There is no easy workaround for now. Basically, you'll need to send the ? and the selection seperately.

PetrKryslUCSD commented 5 years ago

I am not sure I follow. Even sending the ? by itself results in an error:

julia> ?                                                                          
ERROR: syntax: invalid identifier name "?"          
randy3k commented 5 years ago

It is because SendCode sends ?\n rather than just ? , there is no user option to choose not to commit the text.

PetrKryslUCSD commented 5 years ago

Hmm. When I type in ? into the REPL, and then I press return, I don't get an error, I get

help?>                                                                            
search: ⊻ ⊋ ⊊ ⊉ ⊈ ⊇ ⊆ ≥ ≤ ≢ ≡ ≠ ≉ ≈ ∪ ∩ ∛ √ ∘ ∌ ∋ ∉ ∈ ℯ π ÷ ~ | ^ \ > < : / - + * 

  Welcome to Julia 1.0.1. The full manual is available at                         

  https://docs.julialang.org/                                                     

  as well as many great tutorials and learning resources:                         

  https://julialang.org/learning/                                                 

  For help on a specific function or macro, type ? followed by its name, e.g.     
  ?cos, or ?@time, and press enter. Type ; to enter shell mode, ] to enter        
  package mode.   

Does that have something to do with carriage return versus newline?

Anyway, at the moment I think it's solved reasonably well with

// Send code to display help information. Thanks to @mbauman for the suggestion.
    {
        "keys": ["ctrl+shift+x", "ctrl+h"], "command": "send_code",
        "args": {"cmd": "REPL.@repl $selection"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.julia" }
        ]
    }

Thanks for your help.

randy3k commented 5 years ago

Perhaps, most standard keyboards send \r.