vim-erlang / vim-erlang-runtime

Erlang indentation and syntax for Vim
https://vim-erlang.github.io
101 stars 29 forks source link

Indenting differences compared to erlang-mode #32

Closed ghost closed 6 years ago

ghost commented 8 years ago

Since vim-erlang is designed to follow erlang-mode indenting style (see https://github.com/vim-erlang/vim-erlang-runtime/issues/31#issuecomment-189942651), I did a quick test of some of the rebar code.

rebar_port_compiler:os_env/0:

erlang.el:

os_env() ->
    ReOpts = [{return, list}, {parts, 2}, unicode],
    Os = [list_to_tuple(re:split(S, "=", ReOpts)) ||
             S <- lists:filter(fun discard_deps_vars/1, os:getenv())],
    %% Drop variables without a name (win32)
    [T1 || {K, _V} = T1 <- Os, K =/= []].

vim-erlang:

os_env() ->
    ReOpts = [{return, list}, {parts, 2}, unicode],
    Os = [list_to_tuple(re:split(S, "=", ReOpts)) ||
          S <- lists:filter(fun discard_deps_vars/1, os:getenv())],
    %% Drop variables without a name (win32)
    [T1 || {K, _V} = T1 <- Os, K =/= []].

diff after vim-erlang indent:

diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 906bcb0..b8c50c6 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -524,7 +524,7 @@ erts_dir() ->
 os_env() ->
     ReOpts = [{return, list}, {parts, 2}, unicode],
     Os = [list_to_tuple(re:split(S, "=", ReOpts)) ||
-             S <- lists:filter(fun discard_deps_vars/1, os:getenv())],
+          S <- lists:filter(fun discard_deps_vars/1, os:getenv())],
     %% Drop variables without a name (win32)
     [T1 || {K, _V} = T1 <- Os, K =/= []].

rebar:set_log_level/3:

erlang.el:

set_log_level(Config, Options) ->
    {IsVerbose, Level} =
        case proplists:get_bool(quiet, Options) of
            true ->
                {false, rebar_log:error_level()};
            false ->
                DefaultLevel = rebar_log:default_level(),
                case proplists:get_all_values(verbose, Options) of
                    [] ->
                        {false, DefaultLevel};
                    Verbosities ->
                        {true, DefaultLevel + lists:last(Verbosities)}
                end
        end,

    case IsVerbose of
        true ->
            Config1 = rebar_config:set_xconf(Config, is_verbose, true),
            rebar_config:set_global(Config1, verbose, Level);
        false ->
            rebar_config:set_global(Config, verbose, Level)
    end.

vim-erlang:

set_log_level(Config, Options) ->
    {IsVerbose, Level} =
    case proplists:get_bool(quiet, Options) of
        true ->
            {false, rebar_log:error_level()};
        false ->
            DefaultLevel = rebar_log:default_level(),
            case proplists:get_all_values(verbose, Options) of
                [] ->
                    {false, DefaultLevel};
                Verbosities ->
                    {true, DefaultLevel + lists:last(Verbosities)}
            end
    end,

    case IsVerbose of
        true ->
            Config1 = rebar_config:set_xconf(Config, is_verbose, true),
            rebar_config:set_global(Config1, verbose, Level);
        false ->
            rebar_config:set_global(Config, verbose, Level)
    end.

diff after vim-erlang indent:

diff --git a/src/rebar.erl b/src/rebar.erl
index 2fceb19..86588cc 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -341,18 +341,18 @@ save_options(Config, {Options, NonOptArgs}) ->
 %%
 set_log_level(Config, Options) ->
     {IsVerbose, Level} =
-        case proplists:get_bool(quiet, Options) of
-            true ->
-                {false, rebar_log:error_level()};
-            false ->
-                DefaultLevel = rebar_log:default_level(),
-                case proplists:get_all_values(verbose, Options) of
-                    [] ->
-                        {false, DefaultLevel};
-                    Verbosities ->
-                        {true, DefaultLevel + lists:last(Verbosities)}
-                end
-        end,
+    case proplists:get_bool(quiet, Options) of
+        true ->
+            {false, rebar_log:error_level()};
+        false ->
+            DefaultLevel = rebar_log:default_level(),
+            case proplists:get_all_values(verbose, Options) of
+                [] ->
+                    {false, DefaultLevel};
+                Verbosities ->
+                    {true, DefaultLevel + lists:last(Verbosities)}
+            end
+    end,

     case IsVerbose of
         true ->

rebar:is_command*:

erlang.el:

is_command_name_candidate(Command, Candidate) ->
    lists:prefix(Command, Candidate)
        orelse is_command_name_sub_word_candidate(Command, Candidate).

is_command_name_sub_word_candidate(Command, Candidate) ->
    %% Allow for parts of commands to be abbreviated, i.e. create-app
    %% can be shortened to "create-a", "c-a" or "c-app" (but not
    %% "create-" since that would be ambiguous).
    ReOpts = [{return, list}],
    CommandSubWords = re:split(Command, "-", ReOpts),
    CandidateSubWords = re:split(Candidate, "-", ReOpts),
    is_command_name_sub_word_candidate_aux(CommandSubWords, CandidateSubWords).

is_command_name_sub_word_candidate_aux([CmdSW | CmdSWs],
                                       [CandSW | CandSWs]) ->
    lists:prefix(CmdSW, CandSW) andalso
        is_command_name_sub_word_candidate_aux(CmdSWs, CandSWs);
is_command_name_sub_word_candidate_aux([], []) ->
    true;
is_command_name_sub_word_candidate_aux(_CmdSWs, _CandSWs) ->
    false.

vim-erlang:

is_command_name_candidate(Command, Candidate) ->
    lists:prefix(Command, Candidate)
    orelse is_command_name_sub_word_candidate(Command, Candidate).

is_command_name_sub_word_candidate(Command, Candidate) ->
    %% Allow for parts of commands to be abbreviated, i.e. create-app
    %% can be shortened to "create-a", "c-a" or "c-app" (but not
    %% "create-" since that would be ambiguous).
    ReOpts = [{return, list}],
    CommandSubWords = re:split(Command, "-", ReOpts),
    CandidateSubWords = re:split(Candidate, "-", ReOpts),
    is_command_name_sub_word_candidate_aux(CommandSubWords, CandidateSubWords).

is_command_name_sub_word_candidate_aux([CmdSW | CmdSWs],
                                       [CandSW | CandSWs]) ->
    lists:prefix(CmdSW, CandSW) andalso
    is_command_name_sub_word_candidate_aux(CmdSWs, CandSWs);
is_command_name_sub_word_candidate_aux([], []) ->
    true;
is_command_name_sub_word_candidate_aux(_CmdSWs, _CandSWs) ->
    false.

diff after vim-erlang indent:

diff --git a/src/rebar.erl b/src/rebar.erl
index 86588cc..905902f 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -610,7 +610,7 @@ get_command_name_candidates(Command) ->

 is_command_name_candidate(Command, Candidate) ->
     lists:prefix(Command, Candidate)
-        orelse is_command_name_sub_word_candidate(Command, Candidate).
+    orelse is_command_name_sub_word_candidate(Command, Candidate).

 is_command_name_sub_word_candidate(Command, Candidate) ->
     %% Allow for parts of commands to be abbreviated, i.e. create-app
@@ -624,7 +624,7 @@ is_command_name_sub_word_candidate(Command, Candidate) ->
 is_command_name_sub_word_candidate_aux([CmdSW | CmdSWs],
                                        [CandSW | CandSWs]) ->
     lists:prefix(CmdSW, CandSW) andalso
-        is_command_name_sub_word_candidate_aux(CmdSWs, CandSWs);
+    is_command_name_sub_word_candidate_aux(CmdSWs, CandSWs);
 is_command_name_sub_word_candidate_aux([], []) ->
     true;
 is_command_name_sub_word_candidate_aux(_CmdSWs, _CandSWs) ->
hcs42 commented 8 years ago

Thanks for the testing. Yeah, this all falls into the "expressions like this" category that I mentioned in my comment you refer to. To be more precise, these are expressions with infix operators (=, orelse, andalso, ||) that are broken into multiple lines without extra parentheses.

ghost commented 6 years ago

Closing due to inactivity.

kjnilsson commented 6 years ago

I’d like this to be kept open as this is a fairly frustrating shortcoming if the indent support. On Thu, 31 May 2018 at 13:26, Tuncer Ayaz notifications@github.com wrote:

Closing due to inactivity.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vim-erlang/vim-erlang-runtime/issues/32#issuecomment-393500197, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIDlFKulmXepQOA6M0Go4eT0ndqg7cWks5t39N5gaJpZM4Hq1iq .

fisher commented 5 years ago

if you close your eyes, it won't solve the problem. Please consider adjusting the indent, second case is really frequent and annoying in wild life.