Erlang mode for Emacs
Possibly the most important feature of an editor designed for programmers is the ability to indent a line of code in accordance with the structure of the programming language. The Erlang mode does, of course, provide this feature. The layout used is based on the common use of the language. The mode also provides things as syntax highlighting, electric commands, module name verification, comment support including paragraph filling, skeletons, tags support etc.
In the following descriptions the use of the word Point means: "Point can be seen as the position of the cursor. More precisely, the point is the position between two characters while the cursor is drawn over the character following the point".
The following command are directly available for indentation.
erlang-indent-command) - Indents the current line of code.
indent-region) - Indents all lines in the region.
indent-for-comment) - Insert a comment character to the right of the code on the line (if any).
Lines containing comment are indented differently depending on the number of %-characters used:
comment-column, by default column 48 is used.
erlang-indent-function) - Indents the current Erlang function.
M-x erlang-indent-clause RET
M-x erlang-indent-current-buffer RET- Indent the entire buffer.
When editing normal text in text mode you can let Emacs reformat the text by the
fill-paragraph command. This command will not work for comments since it will treat the comment characters as words.
The Erlang editing mode provides a command that knows about the Erlang comment structure and can be used to fill text paragraphs in comments. Ex:
%% This is just a very simple test to show %% how the Erlang fill %% paragraph command works.
Clearly, the text is badly formatted. Instead of formatting this paragraph line by line, let's try
erlang-fill-paragraph by pressing
M-q. The result is:
%% This is just a very simple test to show how the Erlang fill %% paragraph command works.
C-c C-c will put comment characters at the beginning of all lines in a marked region. If you want to have two comment characters instead of one you can do
C-u 2 C-c C-c
C-c C-u will undo a comment-region command.
erlang-beginning-of-function) - Move the point to the beginning of the current or preceding Erlang function. With an numeric argument (ex
C-u 2 C-a M-a) the function skips backwards over this many Erlang functions. Should the argument be negative the point is moved to the beginning of a function below the current function.
erlang-beginning-of-clause) - As above but move point to the beginning of the current or preceding Erlang clause.
erlang-end-of-function) - Move to the end of the current or following Erlang function. With an numeric argument (ex
C-u 2 C-a M-e) the function skips backwards over this many Erlang functions. Should the argument be negative the point is moved to the end of a function below the current function.
erlang-end-of-clause) - As above but move point to the end of the current or following Erlang clause.
erlang-mark-function) - Put the region around the current Erlang function. The point is placed in the beginning and the mark at the end of the function.
erlang-mark-clause) Put the region around the current Erlang clause. The point is placed in the beginning and the mark at the end of the function.
erlang-generate-new-clause) - Create a new clause in the current Erlang function. The point is placed between the parentheses of the argument list.
erlang-clone-arguments) - Copy the function arguments of the preceding Erlang clause. This command is useful when defining a new clause with almost the same argument as the preceding.
C-c C-a (
erlang-align-arrows) - aligns arrows after clauses inside a region.
Example: sum(L) -> sum(L, 0). sum([H|T], Sum) -> sum(T, Sum + H); sum(, Sum) -> Sum. becomes: sum(L) -> sum(L, 0). sum([H|T], Sum) -> sum(T, Sum + H); sum(, Sum) -> Sum.
The syntax highlighting can be activated from the Erlang menu. There are four different alternatives:
For the tag commands to work it requires that you have generated a tag file. See
Erlang mode users guide
find-tag) - Find a function definition. The default value is the function name under the point.
erlang-find-tag) - Like the Elisp-function `find-tag'. Capable of retrieving Erlang modules. Tags can be given on the forms `tag', `module:', `module:tag'.
erlang-find-next-tag) - Find the next occurrence of tag.
erlang-complete-tag) - Perform completion on the tag entered in a tag search. Completes to the set of names listed in the current tags table.
tags-apropos) - Display list of all tags in tags table REGEXP matches.
C-x t s(
tags-search) - Search through all files listed in tags table for match for REGEXP. Stops when a match is found.
A skeleton is a piece of pre-written code that can be inserted into the buffer. Erlang mode comes with a set of predefined skeletons. The skeletons can be accessed either from the Erlang menu of from commands named
tempo-template-erlang-*, as the skeletons is defined using the standard Emacs package "tempo". Here follows a brief description of the available skeletons:
-author('my@home').. They can be used directly, but are also used as part of the full headers described below.
erlang-shell) - Starts a new Erlang shell.
erlang-shell-display) - Displays an Erlang shell, or starts a new one if there is no shell started.
erlang-compile) - Compiles the Erlang module in the current buffer. You can also use
C-u C-c C-kto debug compile the module with the debug options
erlang-compile-display) - Display compilation output.
C-u C-x`Start parsing the compiler output from the beginning. This command will place the point on the line where the first error was found.
erlang-next-error) - Move the point on to the next error. The buffer displaying the compilation errors will be updated so that the current error will be visible.
On unix you can view the manual pages in emacs. In order to find the manual pages, the variable `erlang-root-dir' should be bound to the name of the directory containing the Erlang installation. The name should not include the final slash. Practically, you should add a line on the following form to your ~/.emacs,
(setq erlang-root-dir "/the/erlang/root/dir/goes/here")
M-x imenu-add-to-menubar RET- This command will create the IMenu menu containing all the functions in the current buffer.The command will ask you for a suitable name for the menu. Not supported by Xemacs.
M-x erlang-version RET- This command displays the version number of the Erlang editing mode. Remember to always supply the version number when asking questions about the Erlang mode.
© 2010–2017 Ericsson AB
Licensed under the Apache License, Version 2.0.