erlang.el(3erl)
πΈ NAME
okay bestie, welcome to erlang.el(3erl) β the Erlang mode for Emacs, from the 3erl manual. This is the whole vibe, and yes, itβs iconic. π
β¨ DESCRIPTION
ngl, possibly the most important feature of an editor made for programmers is being able to indent a line of code according to the structure of the programming language. The Erlang mode absolutely does this, of course. The layout it uses is based on the common use of the language. The mode also gives you syntax highlighting, electric commands, module name verification, comment support including paragraph filling, skeletons, tags support, etc. Itβs giving full main-character editor energy. π
In the descriptions below, 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.β π―
π INDENT
These commands are directly available for indentation. No cap, theyβre right there. β¨
TAB(erlang-indent-command) β indents the current line of code.M-C-\(indent-region) β indents all lines in the region.M-l(indent-for-comment) β inserts a comment character to the right of the code on the line (if any).
Lines containing comments are indented differently depending on how many %-characters you use:
- Lines with one
%-character are indented to the right of the code. The column is specified by the variablecomment-column, and by default column48is used. - Lines with two
%-characters will be indented to the same depth as code would have been in the same situation. - Lines with three or more
%-characters are indented to the left margin. C-c C-q(erlang-indent-function) β indents the current Erlang function.M-x erlang-indent-clause RETβ-Indentthe current Erlang clause.M-x erlang-indent-current-buffer RETβ indents the entire buffer.
π EDIT - FILL COMMENT
When youβre editing normal text in text mode, you can let Emacs reformat the text with the fill-paragraph command. But bestie, this command will not work for comments, because it treats the comment characters as words. π
The Erlang editing mode provides a command that knows about the Erlang comment structure and can fill text paragraphs in comments. Example:
%% 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.
Ate. π
π¦ EDIT - COMMENT/UNCOMMENT REGION
C-c C-c will put comment characters at the beginning of all lines in a marked region. If you want 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. π«Ά
πΈ EDIT - MOVING THE MARKER
C-a M-a(erlang-beginning-of-function) β move the point to the beginning of the current or preceding Erlang function. With a numeric argument (ex.C-u 2 C-a M-a) the function skips backwards over this many Erlang functions. If the argument is negative, the point is moved to the beginning of a function below the current function.M-C-a(erlang-beginning-of-clause) β as above, but move point to the beginning of the current or preceding Erlang clause.C-a M-e(erlang-end-of-function) β move to the end of the current or following Erlang function. With a numeric argument (ex.C-u 2 C-a M-e) the function skips backwards over this many Erlang functions. If the argument is negative, the point is moved to the end of a function below the current function.M-C-e(erlang-end-of-clause) β as above, but move point to the end of the current or following Erlang clause.
π EDIT - MARKING
C-c M-h(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.M-C-h(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.
π EDIT - FUNCTION HEADER COMMANDS
C-c C-j(erlang-generate-new-clause) β create a new clause in the current Erlang function. The point is placed between the parentheses of the argument list.C-c C-y(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 one.
β EDIT - ARROWS
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.
Periodt. π₯
π SYNTAX HIGHLIGHTING
Syntax highlighting can be activated from the Erlang menu. There are four different alternatives:
- Off: normal black and white display.
- Level 1: function headers, reserved words, comments, strings, quoted atoms, and character constants will be colored.
- Level 2: the above, plus attributes, Erlang bif:s, guards, and words in comments enclosed in single quotes will be colored.
- Level 3: the above, plus variables, records, and macros will be colored. (This level is also known as the Christmas tree level. π)
π¦ TAGS
For the tag commands to work, you need to have generated a tag file. See Erlang mode users guide. β¨
M-.(find-tag) β find a function definition. The default value is the function name under the point.- Find Tag (
erlang-find-tag) β like the Elisp-functionfind-tag. Capable of retrieving Erlang modules. Tags can be given on the formstag,module:,module:tag. M-+(erlang-find-next-tag) β find the next occurrence of tag.M-TAB(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 aprops (
tags-apropos) β display list of all tags in tags tableREGEXPmatches. C-x t s(tags-search) β search through all files listed in tags table for match forREGEXP. Stops when a match is found.
π§ SKELETONS
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 or from commands named tempo-template-erlang-*, since the skeletons are defined using the standard Emacs package "tempo". Hereβs a brief description of the available skeletons: π
- Simple skeletons:
If,Case,Receive,Receive After,Receive Loopβ basic code constructs. - Header elements:
Module,Authorβ these commands insert lines on the form-module(xxx).and-author('my@home').. They can be used directly, but are also used as part of the full headers described below. - Full Headers:
Small(minimum requirement),Medium(with fields for basic information about the module), andLarge Header(medium header with some extra layout structure). - Small Server β skeleton for a simple server not using OTP.
- Application β skeletons for the OTP application behavior.
- Supervisor β skeleton for the OTP supervisor behavior.
- Supervisor Bridge β skeleton for the OTP supervisor bridge behavior.
- gen_server β skeleton for the OTP gen_server behavior.
- gen_event β skeleton for the OTP gen_event behavior.
- gen_fsm β skeleton for the OTP gen_fsm behavior.
- gen_statem (StateName/3) β skeleton for the OTP gen_statem behavior using state name functions.
- gen_statem (handle_event/4) β skeleton for the OTP gen_statem behavior using one state function.
- Library module β skeleton for a module that does not implement a process.
- Corba callback β skeleton for a Corba callback module.
- Erlang test suite β skeleton for a callback module for the erlang test server.
π SHELL
- New shell (
erlang-shell) β starts a new Erlang shell. C-c C-z, (erlang-shell-display) β displays an Erlang shell, or starts a new one if there is no shell started.
π₯ COMPILE
C-c C-k, (erlang-compile) β compiles the Erlang module in the current buffer. You can also useC-u C-c C-kto debug compile the module with the debug optionsdebug_infoandexport_all.C-c C-l, (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.C-x`(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.
π MAN
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")
π STARTING IMENU
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.
β VERSION
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. π
xoxo, Ericsson AB π version tools 3.5.3 β¨ erlang.el(3erl) β thatβs the footer, periodt (no date in it, bestie). π«Ά
π¦ where this page comes from
- debian bookworm: erlang-manpages 1:25.2.3+dfsg-1+deb12u1 Β· Apache-2.0
- debian bookworm: erlang-manpages 1:25.2.3+dfsg-1+deb12u4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms