Skip to content

Commit

Permalink
Merge pull request #4761 from elehcim/patch-2
Browse files Browse the repository at this point in the history
Use readlink to identify the default editor. ref #4728
  • Loading branch information
JeffBezanson committed Nov 21, 2013
2 parents 689bd57 + 4850e81 commit c328218
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,46 @@ function edit(file::String, line::Integer)
default_editor = "emacs"
end
editor = get(ENV,"JULIA_EDITOR", get(ENV,"VISUAL", get(ENV,"EDITOR", default_editor)))
if ispath(editor)
if isreadable(editor)
edpath = realpath(editor)
edname = basename(edpath)
else
error("edit: can't find \"$editor\"")
end
else
edpath = edname = editor
end
issrc = length(file)>2 && file[end-2:end] == ".jl"
if issrc
file = find_source_file(file)
end
if editor == "emacs"
if edname == "emacs"
jmode = joinpath(JULIA_HOME, "..", "..", "contrib", "julia-mode.el")
if issrc && isreadable(jmode)
run(`emacs $file --eval "(progn
run(`$edpath $file --eval "(progn
(require 'julia-mode \"$jmode\")
(julia-mode)
(goto-line $line))"`)
else
run(`emacs $file --eval "(goto-line $line)"`)
run(`$edpath $file --eval "(goto-line $line)"`)
end
elseif editor == "vim"
run(`vim $file +$line`)
elseif editor == "textmate" || editor == "mate"
spawn(`mate $file -l $line`)
elseif editor == "subl"
spawn(`subl $file:$line`)
elseif OS_NAME == :Windows && (editor == "start" || editor == "open")
elseif edname == "vim"
run(`$edpath $file +$line`)
elseif edname == "textmate" || edname == "mate"
spawn(`$edpath $file -l $line`)
elseif edname == "subl"
spawn(`$edpath $file:$line`)
elseif OS_NAME == :Windows && (edname == "start" || edname == "open")
spawn(`start /b $file`)
elseif OS_NAME == :Darwin && (editor == "start" || editor == "open")
elseif OS_NAME == :Darwin && (edname == "start" || edname == "open")
spawn(`open -t $file`)
elseif editor == "kate"
spawn(`kate $file -l $line`)
elseif editor == "nano"
spawn(`nano +$line $file`)
elseif edname == "kate"
spawn(`$edpath $file -l $line`)
elseif edname == "nano"
run(`$edpath +$line $file`)
else
run(`$(shell_split(editor)) $file`)
run(`$(shell_split(edpath)) $file`)
end
nothing
end
Expand Down

0 comments on commit c328218

Please sign in to comment.