Open yuyichao opened 8 years ago
I think this is relevant:
longfunctionname(; # Wrong, in my opinion
hello=nothing,
world=nothing,
)
longfunctionname( # Right
hello,
world,
)
Current state:
function1(a, b, c,
d, e, f)
function2(
a, b, c,
d, e, f)
for i in Float64[1, 2, 3, 4
5, 6, 6, 8]
end
for i in Float64[
1, 2, 3, 4,
5, 6, 7, 8]
end
a = function3(function ()
return 1
end)
a = function4(
function ()
return 1
end)
With the possible exception of function3
and function4
, this
matches my expectation and how I would indent code if I were doing so
manually.
I think the major problem here is that the indentation is completely lost in cases like:
hl = Highlighter((h,data,i,j)->begin
id = div(i-1, 3)
sim_id = id*num_cols + j
if sims_status[sim_id] == 1
return crayon"black bg:green"
else
return crayon"bg:yellow"
end
I've worked out a package to use JuliaFormatter.jl as backend to correctly code while typing:
https://codeberg.org/FelipeLema/julia-formatter.el
It's not the same experience as having correct native indentation (has small quirks), but I find it usable when coupled along aggressive-indent
.
Please, try it out so I can improve it and provide a stable solution to this issue.
I think this is a variation not mentioned above:
f(a, b, c) do i
sin(i)
end
f(a, b,
c) do i
sin(i) # I would prefer if this had the same indention as above
end
I don't know (and could not find) the style convention for calls involving only keyword parameters.
But for me they often occur (e.g., because of using Parameters.jl
for type definitions) and what I used to write was
long_func_name(;
some_kw = 1.0
)
I think that indentation style fits well because it is similar to the indentation for function calls if only regular arguments are provided. In julia-mode the default indendation is
long_func_name(;
some_kw = 1.0
)
Of course I could easily put the semi-colon into the next line :sweat_smile: Was just wondering if anyone else knows the conventions for this case.
I don't know (and could not find) the style convention for calls involving only keyword parameters.
Best take on this matter that I know of is JuliaFormatter styles. You can check the docs for very detailed info.
Thanks for the hint! Unfortunately, the docs do not seem to list the special case of keyword-arguments only. However, JuliaFormatter does seem to use the first style from my initial comment https://github.com/JuliaEditorSupport/julia-emacs/issues/11#issuecomment-1188955182 if the function name is long enough or if there are many keyword arguments. It is also the indentation style that the REPL applied when I tested JuliaFormatter just now. So I guess there is a discrepancy between JuliaFormatter and julia-mode.
Ref https://github.com/JuliaLang/julia/issues/8971 Ref https://github.com/JuliaLang/julia/issues/11498
A few cases right now.
Some proposed changes