I often use @which
but would also like to use @edit
.
On Windows @edit
doesn’t seem to work for me by default, so I did some investigating and managed to get something that works.
Sharing here in case it helps any other long-suffering Windows users.
Also some questions below:
I managed to get @edit
working with Atom
, Sublime Text
and Notepad++
.
If you don’t want to read the long story below, just put one of these into your .juliarc.jl
file.
ENV["JULIA_EDITOR"] = "\"C:\\Users\\plowman\\AppData\\Local\\atom\\bin\\atom.cmd\""
ENV["JULIA_EDITOR"] = "\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""
ENV["JULIA_EDITOR"] = "\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""
Note the extra escaped quotes \"
Notepad++
requires some extra steps, read on.
Firstly it seems the default editor for Windows is open
which results in edit()
running the command:
`cmd /c start /b $path`
This doesn’t work for me.
So I tried setting JULIA_EDITOR, but without “double”-quoting the path gets split.
julia> ENV["JULIA_EDITOR"] = "C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
"C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
julia> Base.editor()
4-element Array{AbstractString,1}:
"C:Program"
"FilesSublime"
"Text"
"3sublime_text.exe"
editor()
calls shell_split()
.
1. Is this the expected behaviour of shell_split()
?
One way around this is to “double”-quote the path:
julia> ENV["JULIA_EDITOR"] = "\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""
"\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""
julia> Base.editor()
1-element Array{AbstractString,1}:
"C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
This it relatively easy (although unintuitive) when setting JULIA_EDITOR from within Julia.
However, I couldn’t find a way to make this work by setting the Windows environment variable JULIA_EDITOR.
2. Does anyone know how to set JULIA_EDITOR in Windows so path is preserved as single string?
OK so this works for Atom
, Sublime Text
and Notepad++
.
ENV["JULIA_EDITOR"] = "\"C:\\Users\\plowman\\AppData\\Local\\atom\\bin\\atom.cmd\""
ENV["JULIA_EDITOR"] = "\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\""
ENV["JULIA_EDITOR"] = "\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""
For Atom
and SublimeText
, existing code in edit()
(in interactiveutil.jl
) handles the command line options to open the file at the appropriate line number.
For Notepad++
the following snippet needs to be inserted into edit()
:
elseif startswith(name, "notepad++")
cmd = line != 0 ? `$command $path -n$line` : `$command $path`
3. Does anyone else use Notepad++
? Is this worth adding to base?
Hope this helps.
Would also like to hear other Windows users experience with @edit