User's Guide
Reference Manual
Release Notes
PDF
Top

Tools
Reference Manual
Version 2.8.2

Expand All
Contract All

Table of Contents

- cover
  - Top of manual page
  - start/0
  - start/1
  - compile/1
  - compile/2
  - compile_module/1
  - compile_module/2
  - compile_directory/0
  - compile_directory/1
  - compile_directory/2
  - compile_beam/1
  - compile_beam_directory/0
  - compile_beam_directory/1
  - analyse/0
  - analyse/1
  - analyse/1
  - analyse/1
  - analyse/2
  - analyse/2
  - analyse/2
  - analyse/3
  - analyse_to_file/0
  - analyse_to_file/1
  - analyse_to_file/1
  - analyse_to_file/2
  - async_analyse_to_file/1
  - async_analyse_to_file/2
  - async_analyse_to_file/2
  - async_analyse_to_file/3
  - modules/0
  - imported_modules/0
  - imported/0
  - which_nodes/0
  - is_compiled/1
  - reset/1
  - reset/0
  - export/1
  - export/2
  - import/1
  - stop/0
  - stop/1
  - flush/1
- cprof
  - Top of manual page
  - analyse/0
  - analyse/1
  - analyse/1
  - analyse/2
  - pause/0
  - pause/1
  - pause/2
  - pause/3
  - restart/0
  - restart/1
  - restart/2
  - restart/3
  - start/0
  - start/1
  - start/2
  - start/3
  - stop/0
  - stop/1
  - stop/2
  - stop/3
- eprof
  - Top of manual page
  - start/0
  - start_profiling/1
  - start_profiling/2
  - start_profiling/3
  - stop_profiling/0
  - profile/1
  - profile/2
  - profile/1
  - profile/2
  - profile/3
  - profile/4
  - profile/5
  - profile/6
  - analyze/0
  - analyze/1
  - analyze/2
  - log/1
  - stop/0
- erlang.el
- fprof
  - Top of manual page
  - start/0
  - stop/0
  - stop/1
  - apply/2
  - apply/3
  - apply/3
  - apply/4
  - trace/2
  - trace/2
  - trace/2
  - trace/1
  - trace/1
  - trace/1
  - trace/1
  - profile/0
  - profile/2
  - profile/1
  - profile/1
  - profile/1
  - analyse/0
  - analyse/2
  - analyse/1
  - analyse/1
  - analyse/1
- instrument
  - Top of manual page
  - allocator_descr/2
  - block_header_size/1
  - class_descr/2
  - descr/1
  - holes/1
  - mem_limits/1
  - memory_data/0
  - memory_status/1
  - read_memory_data/1
  - read_memory_status/1
  - sort/1
  - store_memory_data/1
  - store_memory_status/1
  - sum_blocks/1
  - type_descr/2
  - type_no_range/1
- lcnt
  - Top of manual page
  - start/0
  - stop/0
  - collect/0
  - collect/1
  - clear/0
  - clear/1
  - conflicts/0
  - conflicts/1
  - locations/0
  - locations/1
  - inspect/1
  - inspect/2
  - information/0
  - swap_pid_keys/0
  - load/1
  - save/1
  - apply/1
  - apply/2
  - apply/3
  - pid/2
  - pid/3
  - port/1
  - port/2
  - rt_collect/0
  - rt_collect/1
  - rt_clear/0
  - rt_clear/1
  - rt_opt/1
  - rt_opt/2
- make
  - Top of manual page
  - all/0
  - all/1
  - files/1
  - files/2
- tags
  - Top of manual page
  - file/1
  - files/1
  - dir/1
  - dirs/1
  - subdir/1
  - subdirs/1
  - root/1
- xref
  - Top of manual page
  - add_application/2
  - add_directory/2
  - add_module/2
  - add_release/2
  - analyze/2
  - d/1
  - forget/1
  - forget/2
  - format_error/1
  - get_default/1
  - get_default/2
  - get_library_path/1
  - info/1
  - info/2
  - info/3
  - m/1
  - m/1
  - q/2
  - remove_application/2
  - remove_module/2
  - remove_release/2
  - replace_application/3
  - replace_module/3
  - set_default/3
  - set_default/2
  - set_library_path/2
  - start/1
  - start/2
  - stop/1
  - update/1
  - variables/1

# erlang.el

### MODULE

erlang.el

### MODULE SUMMARY

Erlang mode for Emacs

### DESCRIPTION

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".

### Indent

The following command are directly available for indentation.

- 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) - 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:

- Lines with one %-character is indented to the right of the code. The column is specified by the variable comment-column, by default column 48 is used.
- Lines with two %-characters will be indented to the same depth as code would have been in the same situation.
- Lines with three of 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
  -Indent the current Erlang clause.
- M-x erlang-indent-current-buffer RET - Indent the entire buffer.

### Edit - Fill Comment

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.

### 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 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.

### 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 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.
- 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 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.
- 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.

### 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.

### Syntax highlighting

The 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, attributes, Erlang bif:s, guards, and words in comments enclosed in single quotes will be colored.
- Level 3: The above, variables, records, and macros will be colored. (This level is also known as the Christmas tree level.)

### Tags

For the tag commands to work it requires that you 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-function `find-tag'. Capable of retrieving Erlang modules. Tags can be given on the forms `tag', `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 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.

### 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 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:

- 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), and Large 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
- 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 use C-u C-c C-k to debug compile the module with the debug options debug_info and export_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.