JuliaEditorSupport / julia-emacs

Julia support in Emacs.
Other
288 stars 62 forks source link

Indentation inside parenthesis #11

Open yuyichao opened 8 years ago

yuyichao commented 8 years ago

Ref https://github.com/JuliaLang/julia/issues/8971 Ref https://github.com/JuliaLang/julia/issues/11498

A few cases right now.

function1(a, b, c
          d, e, f)
function2(
          a, b, c
          d, e, f)
for i in Float64[1, 2, 3, 4
                 5, 6, 7, 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)

Some proposed changes

function1(a, b, c
          d, e, f)
# Or
function1(a, b, c
    d, e, f)
function2(
    a, b, c
    d, e, f)
for i in Float64[1, 2, 3, 4
                 5, 6, 7, 8]
end
# Or
for i in Float64[1, 2, 3, 4
        5, 6, 7, 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)
christopher-dG commented 6 years ago

I think this is relevant:

longfunctionname(;  # Wrong, in my opinion
                 hello=nothing,
                 world=nothing,
                 )
longfunctionname(  # Right
    hello,
    world,
)
non-Jedi commented 4 years ago

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.

ronisbr commented 4 years ago

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
FelipeLema commented 4 years ago

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.

jagot commented 4 years ago

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
manuelbb-upb commented 2 years ago

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.

FelipeLema commented 2 years ago

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.

manuelbb-upb commented 2 years ago

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.