[erlang-questions] erlang-mode: follow more Emacs idioms
Magnus Henoch
magnus@REDACTED
Tue May 7 12:15:21 CEST 2013
Andrew Pennebaker <andrew.pennebaker@REDACTED> writes:
> In modern Emacs, it's recommended to install
> MELPA<http://melpa.milkbox.net/>and use M-x install-package RET
> erlang-mode RET to get Erlang mode up and
> running. With most major modes, this is all that is required, however
> erlang-mode needs some manual configuration that we should probably work on
> automating during its installation. Currently, Emacs users must modify
> several lines in ~/.emacs in order to setup erlang-mode:
>
> (autoload 'erlang-mode "erlang" "" t)
> (add-to-list 'auto-mode-alist '("\\.erl\\'" . erlang-mode))
> (add-to-list 'auto-mode-alist '("\\.escript\\'" . erlang-mode))
> (add-hook 'erlang-mode-hook
> (lambda ()
> (setq erlang-indent-level tab-width)))
>
> The first three collectively register the ".erl" and ".escript" file
> extensions with erlang-mode. In modern Emacs, the idiom is to register
> these autoloads as part of installation. For example, go-mode successfully
> does this. https://code.google.com/p/go/source/browse/#hg%2Fmisc%2Femacs
The first two of those lines shouldn't be necessary since 22nd March.
Have a look at ~/.emacs.d/elpa/erlang-20130322.1917/erlang-autoloads.el,
and you should see that corresponding forms have been generated already.
There is also a line that enables erlang-mode for files that start with
"#!/usr/bin/env escript" or similar - that covers most of my escript
files. I wouldn't mind adding the rule for "*.escript" files, though.
> Also, it's more idiomatic for Emacs users to set a global tab-width, and
> modify it by file type with hooks. As we see above, erlang-mode in its
> current form does not respect the conventional variable tab-width, using
> erlang-indent-level instead. We can improve this a bit, while maintaining
> backwards compatibility, by defaulting erlang-indent-level to tab-width
> when a buffer enters erlang-mode.
>
> What do you think?
While this might be a good idea, I disagree that it's conventional :)
Most programming language modes have a separate variable for setting the
indentation step (c-basic-offset, sh-basic-offset, ruby-indent-level),
independent of tab-width. (Python and makefile modes are exceptions,
for obvious reasons, and it seems Go mode exclusively uses tab-width.)
Erlang mode indentation depends on the combination erlang-indent-level
and tab-width, so this change wouldn't be backwards compatible. You can
try it by making the change and running "make test_indentation" in
lib/tools/emacs.
So this might be a good policy for a new project, but not as a default
value.
I've been working on changes to erlang-mode to make it more friendly to
the "one indentation level, one tab" indentation style (in particular
deactivating lining up lines with specific elements in a previous line),
but it feels like I keep adding special cases; it would need some
cleanup before I could submit a patch for it. For the curious, here it
is:
https://github.com/legoscia/otp/commits/dogfood-r15b03/lib/tools/emacs/erlang.el
Regards,
Magnus
More information about the erlang-questions
mailing list