comma vs andalso

Magnus Henoch magnus@REDACTED
Mon Jul 6 13:58:57 CEST 2009


Joel Reymont <joelr1@REDACTED> writes:

> A related pet peeve of mine is that the following does not properly
> indent in the latest Emacs mode
>
> handle_info({tcp, Socket, Bin}, State)
>   when State#state.transport /= undefined,
> State#state.socket == Socket ->
> ...
>
> I have to manually insert spaces to align State#state... above and
> using andalso above does not help either.

I found that this happens because there is a "." in the guard.  This
change to erlang-mode (actually erlware-mode, but the code should be
similar) seems to fix it:

diff --git a/erlang.el b/erlang.el
index 6ad03ea..916037e 100644
--- a/erlang.el
+++ b/erlang.el
@@ -2097,7 +2097,7 @@ Value is list (stack token-start token-type in-what)."
             ((looking-at "when[^->\.]*case[^->\.]*->"))
             ((looking-at "when[^->\.]*receive[^->\.]*->"))
             ;; Normal when case
-            ((looking-at "when [^->\.]*->")
+            ((looking-at "when [^->]*->")
              (erlang-push (list 'when token (current-column)) stack))
             ((looking-at "after[.]+->")
              (erlang-push (list 'icr token (current-column)) stack))

Not sure what other cases that would mess up, though.  The comment above
mentions one possible gotcha:

            ;; In test suites you may want to do something like
            ;; ?match(Mem when integer(Mem), mnesia:table_info(Tab,
            ;; memory)), and then the following if/case/receive
            ;; statement will mess up the indentation by fooling the
            ;; erlang mode to think the 'when' in the argument is a
            ;; "real" when. The following three clauses will avoid
            ;; this problem.

-- 
Magnus Henoch, magnus@REDACTED
Erlang Training and Consulting
http://www.erlang-consulting.com/


More information about the erlang-questions mailing list