function f()
for i in 1:10
if i > 5
println(i)
end
end
end
from your editor to your Julia REPL, you get the following result:
julia> function f()
for i in 1:10
if i > 5
println(i)
end
end
end
f (generic function with 1 method)
Notice, that Julia automatically indents the code which is pasted, but the code is already indented so the result does not look nice. This gets really bad when you paste 50 lines of highly nested code.
There is an open PR to fix this issue here, but since it did not get into Julia 1.0.2 I thought that I would post the hack I use to disable auto-indentation. Run the following lines in your Julia REPL:
import REPL
REPL.GlobalOptions.auto_indent = false
REPL.LineEdit.options(s::REPL.LineEdit.PromptState) = REPL.GlobalOptions
julia> function f()
for i in 1:10
if i > 5
println(i)
end
end
end
f (generic function with 1 method)
and all is formatted as expected.
The solution overwrites REPL.LineEdit.options method to make sure that we always use REPL.GlobalOptions with auto-indentation disabled. It is not ideal, but I find it good enough till the issue is resolved.
If you would want to use this solution by default you can put the proposed code in your ~/.julia/config/startup.jl file.
This is very nice and worked for me just as discussed above.
ReplyDelete