[erlang-questions] Vim Editor Erlang Indentation
Csaba Hoch
csaba.hoch@REDACTED
Fri Jun 5 19:35:00 CEST 2009
> Hello everyone,
> I like vim editor, but indented output is not the same quality as my
> colleagues in emacs. why is this? is the limitation in vim or vim indent
> file?
>
> thank you,
>
> Felipe.
Hi,
I wrote the indentation file that ships with Vim since version 7.2,
probably that is what you are using. (That's the same file Oscar
pointed to.)
In Vim, you can implement any custom indentation algorithm. You just
write a function that returns the desired indentation level of a given
line, and execute the command ":set indentexpr=MyIndentFun()".
However, most indentation scripts do the followings:
- Search the last non-comment-and-non-blank line above the current
line.
- Analyse that line and try to calculate the correct indentation level
of the current line from that.
The Erlang indentation script also follows this principle.
At the time of writing the script, I was writing Erlang code on my
own, and created my own indentation conventions that seemed sensible
to me, based on my experience on how Vim indents source code written
in other languages. Now (that I work in "real" projects) it seems to
me that the de facto Erlang indentation (or "alignment" as Oscar would
say ;) ) is the Emacs one. I edit Erlang code with Vim, but if I don't
get the Emacs indentation (which happens mostly with multi-line
terms), I just manually indent the code.
Another point I'd like to make: the script does not handle all
combinations of all language constructs, so sometimes the indentation
is visibly incorrect. I think these problems can be fixed only if we
stop following the usual principle of Vim indentation files and come
up with a more complicated model.
Maybe the Erlang indentation code of Emacs should be translated from
Emacs to Vimscript. But I think that if that was done, the Erlang
indentation file would be the most complicated of all Vim indentation
scripts.
Csaba
More information about the erlang-questions
mailing list