web-mode icon indicating copy to clipboard operation
web-mode copied to clipboard

Indentation in case/cond blocks EEx (Elixir)

Open ssbb opened this issue 4 years ago • 4 comments

I think PR for #1005 brokes it.

Example block of code:

<%= cond do %>
  <% @filter.min_price && filter.max_price -> %>
    both
  <% @filter.min_price ->  %>
    min
  <% @filter.max_price ->  %>
    max
<% end %>

So it should be formatted this way. Right now it indents after each -> block and looks like:

<%= cond do %>
  <% @filter.min_price && filter.max_price -> %>
    both
    <% @filter.min_price ->  %>
      min
      <% @filter.max_price ->  %>
        max
      <% end %>

Probably parser should check if we inside cond/case block and do not indent in this case.

ssbb avatar Apr 29 '20 16:04 ssbb

@ssbb @lukad what should I do ? Is -> %> for anonymous function ?

fxbois avatar Apr 29 '20 17:04 fxbois

@fxbois as I know -> in Elixir is used only for 2 things:

  1. Anonymous functions
  2. Branches in do ... end blocks.

there is no so much do ... end blocks with branches support. I think in templates only case and cond is used. Is there a way to check for current context? Something like:

"If nearest parent is <%= cond/case ... do %> then do not increase indentation level"?

ssbb avatar Apr 29 '20 19:04 ssbb

@ssbb I can not indent under <% @filter.min_price -> %> if there is not an ending block

fxbois avatar May 01 '20 07:05 fxbois

A naive workaround could be to only indent after -> if it's after an fn ... Can't really help here though. I'm no longer using emacs.

lukad avatar May 01 '20 09:05 lukad