Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent indentation in with #397

Open
Trevoke opened this issue Jun 25, 2017 · 2 comments
Open

Inconsistent indentation in with #397

Trevoke opened this issue Jun 25, 2017 · 2 comments

Comments

@Trevoke
Copy link
Contributor

Trevoke commented Jun 25, 2017

I have this gem of indentation in my code right now (and yes, that's how emacs wants it indented):

      def move_to_random_location(%{location_id: loc_id, id: id, exits: exits} = state) do
        with true <- Enum.any?(exits),
             info <- public_info(state),
               %{from_id: new_loc_id} <- Enum.random(exits),
               :ok <- World.Location.depart(loc_id, {{__MODULE__, id}, info, new_loc_id}),
             {:ok, new_exits} <- World.Location.arrive(new_loc_id, {{__MODULE__, id}, info, loc_id}) do
          %{state | location_id: new_loc_id, exits: new_exits}
        else
          false -> state
        :not_in_location -> state
        end
      end
@pmontrasio
Copy link

pmontrasio commented Aug 1, 2017

I'm on Elixir mode 20170102.942 from melpa. I get the code indented like this

    with {:ok, body} <- File.read(filename),
         {:ok, json} <- Poison.decode(body), do: {:ok, json}
  else
    _ ->
      return {:error, "#{filename} does not exist or is not JSON"}
  end

It's ok if I omit the : in the do:

    with {:ok, body} <- File.read(filename),
         {:ok, json} <- Poison.decode(body), do {:ok, json}
    else
      _ ->
        return {:error, "#{filename} does not exist or is not JSON"}
    end

but there should really be a : there.

@guillaumebrunerie
Copy link

Here are two more examples of indentation of with. The second one really seems to be driving emacs crazy.

defmodule Test do
  def f(x) do
    with y <- x,
         z <- y,
           w <- z,
           t <- w,
           u <- t do
      u
    end
  end
  
  def g(a) do
    with <<b::binary-size(3)>> <- a,
      c <- 3,
                       d <- 3,
    <<e::binary>> <- b do
                      e
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants