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

[Sublime Text 3] Arrows break indentation #133

Open
voger opened this issue Aug 19, 2017 · 1 comment
Open

[Sublime Text 3] Arrows break indentation #133

voger opened this issue Aug 19, 2017 · 1 comment

Comments

@voger
Copy link

voger commented Aug 19, 2017

I have this .exs file

defmodule Bob do
  import String
  def hey(input) do
    cond do
      "" == trim(input) -> 
        "Fine. Be that way!"
      ends_with?(input, "?") -> 
        "Sure."
      input == upcase(input) && input != downcase(input) -> 
        "Whoa, chill out!"
      true ->  
        "Whatever."
    end
  end
end

And in my keybindings I have

{"keys": ["ctrl+alt+/"], "command": "reindent", "args": {"single_line": false}},

But when I reident the file I get

defmodule Bob do
  import String
  def hey(input) do
    cond do
      "" == trim(input) ->
        "Fine. Be that way!"
        ends_with?(input, "?") ->
          "Sure."
          input == upcase(input) && input != downcase(input) ->
            "Whoa, chill out!"
            true ->
              "Whatever."
            end
          end
        end

This happens when the arrow -> is at the end of the line. If the statement is in the same line then the code formatting works fine.

defmodule Bob do
  import String
  def hey(input) do
    cond do
      "" == trim(input) -> "Fine. Be that way!"
      ends_with?(input, "?") -> "Sure."
      input == upcase(input) && input != downcase(input) -> "Whoa, chill out!"
      true ->  "Whatever."
    end
  end
end

And here is an example what happens with a longer file.

defmodule BinarySearch do
  @spec search(tuple, integer) :: {:ok, integer} | :not_found
  def search(numbers, key) do
    high = tuple_size(numbers) - 1
    _search(numbers, key, 0, high)
  end

  defp _search(numbers, key, low, high) do
    midpoint = low + div((high - low), 2)
    cond do
      low > high ->
        :not_found
        elem(numbers, midpoint) == key ->
          {:ok, midpoint}
          elem(numbers, midpoint) > key ->
            _search(numbers, key, low, midpoint - 1)
            elem(numbers, midpoint) < key ->
              _search(numbers, key, midpoint + 1, high)
            end
          end
        end
@voger
Copy link
Author

voger commented Aug 19, 2017

I did some minor change to Indent.tmPreferences which breaks indentation under conditionals and function definitions for the lines that end with arrow. But at least it is better than before. My regexp skills are very primitive and I haven't touched a sublime plugin before.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>name</key>
		<string>Indent</string>
		<key>scope</key>
		<string>source.elixir</string>
		<key>settings</key>
		<dict>
			<key>decreaseIndentPattern</key>
			<string>^\s*((\}|\])\s*$|(after|else|catch|rescue|end)\b)|^.*(\-&gt;)\s*$</string>
			<key>increaseIndentPattern</key>
			<string>^\s*(after|else|catch|rescue|^.*(do|&lt;\-|\-&gt;|\{|\[))\s*$</string>
		</dict>
		<key>uuid</key>
		<string>313112A0-FC40-4025-97AE-3E85DC0DB08F</string>
	</dict>
</plist>
defmodule Bob do
  import String
  def hey(input) do
    cond do
    "" == trim(input) ->
      "Fine. Be that way!"
    ends_with?(input, "?") ->

      "Sure."
    input == upcase(input) && input != downcase(input) ->
      "Whoa, chill out!"
    true ->
      "Whatever."
    end

    case true do
    true ->
      test
    {:something. :else} ->
      {:it, :works}
      {test}
    true ->
    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

1 participant