If you want to get started immediately, the chapters
"
Emacs has been the text editor of choice for programmers in the UNIX community for many years. Thanks to a continuing development process, Emacs is the most powerful editor available. Today, Emacs runs under most operating systems including MS-Windows, OS/2, Macintosh, and several dialects of UNIX.
Emacs has editing support for all major programming languages and quite a lot of minor and unknown languages are supported as well.
Emacs is designed to be extendible. In the unlikely event that you would miss a feature in Emacs you can add it yourself, or you might find it in the large number of add-on packages that people all over the world have written.
This book is the documentation to the Emacs package
Emacs is written by the Free Software Foundation and is part of the GNU project. Emacs, including the source code and documentation, is released under the GNU General Public License.
This book can be divided into the following sections:
The terminology used in this book is the terminology used in the
documentation to Emacs. The chapter "
The intended readers of this book are Emacs users. The book contains some examples on how to customize this package using the Emacs extension language Emacs Lisp. You can safely skip those sections.
The first component needed to get this package up and running is, of course, an Emacs editor. You can use either the standard Emacs distribution from FSF or XEmacs, an alternative distribution. Both brands have their advantages and disadvantages.
Regardless of the brand, it is recommended to use a modern version. If an old version is used it is possible that some of the features provided by the editing mode cannot be used.
The chapter "
Once Emacs has been installed, it must be informed about the presence of the Erlang support packages.
If you do not know if the packages have been installed open, an Erlang source file. The mode line should contain the word "Erlang". You can check the version of the installed package by selecting the "version" entry in the Erlang menu in Emacs. Should no Erlang menu be present, or if the menu does not contain a "Version" item, you are using an old version.
The packages can either be installed for all users by the system
administrator, or each individual user can install it in their own
Emacs setup. The chapter "
The Erlang editing for Emacs provides a number of features described in this and the following chapters. The editing mode can work with either Erlang source mode or Mnesia database rules. The Erlang editing mode for Emacs is in Emacs terminology a Major mode .
When Erlang mode is correctly installed, it is automatically activated
when a file ending in
The editing mode provides a menu containing a selection of commands structured into logical subgroups. The menu is designed to help new users get an overview of the features provided by the Erlang packages while still giving full power to more advanced users.
Erlang mode has got a local key map that contains keyboard bindings
for a number of commands. In the chapter
"
It is possible for the users to perform advanced customizations by
adding their own functions to the "hook" variables provided by this
package. This will be described in the "
This command activates the Erlang major mode for the current buffer. When this mode is active the mode line contain the word "Erlang".
This command displays the version number of the Erlang editing mode. Remember to always supply the version number when asking questions about Erlang mode.
Should this command not be present in your setup (after Erlang mode has been activated) you probably have a very old version of the Erlang editing mode.
When a file is saved the name in the
This variable controls the behavior of the module name check system.
When it is
There are several variables that control the behavior of the Erlang Editing mode.
Functions to run when the Erlang mode is activated. See chapter
"
Functions to run when a new file is created. See chapter "
Functions to run when the
The "Oxford Advanced Learners Dictionary of Current English" says the following about the word "indent":
"start (a line of print or writing) farther from the margin than the others".
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.
It is strongly recommend to use this feature and avoid to indent lines in a nonstandard way. Some motivations are:
The basic layout is that the clause headers start in the first column, and the bodies of clauses and complex expressions (e.g. "case" and "if") are indented more that the surrounding code. For example:
remove_bugs([]) ->
[];
remove_bugs([X | Xs])
case X of
bug ->
test(Xs);
_ ->
[X | test(Xs)]
end.
The depth of the indentation is controlled by the variable
"erlang-indent-level", see section "
Lines containing comment are indented differently depending on the number of %-characters used:
Example:
%%%
%%% Function: remove_bugs
%%%
remove_bugs([]) ->
[];
remove_bugs([X | Xs])
case X of
bug -> % Oh no, a bug!
% Remove it.
test(Xs);
%% This element is not a bug, let's keep it.
_ ->
[X | test(Xs)]
end.
The following command are directly available for indentation.
Indent the current line of code.
Indent all lines in the region.
Insert a comment character to the right of the code on the line (if any). The comment character is placed in the column specified by the variable "comment-column", by default column 48 is used.
Indent the current Erlang function.
Indent the current Erlang clause.
Indent the entire buffer.
The most common customization of the indentation system is to bind the
return key to
There are several Emacs variables that control the indentation system.
The amount of indentation for normal Erlang functions and complex expressions. Should, for example, the value of this variable be 2 the example above would be indented like:
remove_bugs([]) ->
[];
remove_bugs([X | Xs])
case X of
bug ->
test(Xs);
_ ->
[X | test(Xs)]
end.
The amount of indentation for Erlang guards.
The amount of indentation for function calls that span several lines.
Example:
foo() ->
a_very_long_function_name(
AVeryLongVariableName),
When non-
This chapter contains a group of commands that are not found in any other category. Unlike most other books we do not have a chapter named "Miscellaneous xxx" found at the end of most books. This chapter is placed near the beginning to reflect the importance and usefulness of the commands.
How many times have you edited a section of text in a comment only to wind up with a unevenly formatted paragraph? Or even worse, have you ever decided not to edit a comment just because the formatting would look bad?
When editing normal text in text mode you can let Emacs reformat the
text by the
The Erlang editing mode provides a command that known about the Erlang comment structure and can be used to fill text paragraphs in comments.
Example:
For the sake of this example, let's assume that
%% This is just a test to show
%% how the Erlang fill
%% paragraph command works.
Assume that you would add the words "very simple" before the word "test":
%% 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
%% This is just a very simple
%% test to show how the Erlang
%% fill paragraph command
%% works.
As you can see the paragraph is now evenly formatted.
In Erlang it is possible to write comments to the right of the code. The indentation system described in the chapter "Indentation" above is able to indent lines containing only comments, and gives support for end-of-the-line comments.
The standard command
It is possible for Emacs to use colors when displaying a buffer. By "syntax highlighting", we mean that syntactic components, for example keywords and function names, will be colored.
The basic idea of syntax highlighting is to make the structure of a program clearer. For example, the highlighting will make it easier to spot simple bugs. Have not you ever written a variable in lower-case only? With syntax highlighting a variable will colored while atoms will be shown with the normal text color.
The syntax highlighting can be activated from the Erlang menu. There are four different alternatives:
The syntax highlighting is based on the standard Emacs package "font-lock". It is possible to use the font-lock commands and variables to enable syntax highlighting. The commands in question are:
This command activates syntax highlighting for the current buffer.
Activate syntax highlighting for all buffers.
The variable
It is possible to change the color used. It is even possible to use
bold, underlined, and italic fonts in combination with colors.
However, the method to do this differs between Emacs and XEmacs; and
between different versions of Emacs. For Emacs 19.34, the variable
Font-lock mode is activated in different ways in different versions of
Emacs. For modern versions of GNU Emacs place the following lines in
your
(setq font-lock-maximum-decoration t)
(global-font-lock-mode 1)
For modern versions of XEmacs the following code can be used:
(setq auto-font-lock-mode 1)
For older versions of Emacs and XEmacs, font-lock mode must be activated individually for each buffer. The following will add a function to the Erlang mode hook that activates font-lock mode for all Erlang buffers.
(defun my-erlang-font-lock-hook ()
(font-lock-mode 1))
(add-hook 'erlang-mode-hook 'my-erlang-font-lock-hook)
Emacs has one problem with the syntactic structure of Erlang, namely
the
ascii_value_of_a() -> $a.
In order to get the font-lock mechanism to work for the next example, the $ character must be marked as an "escape" character that changes the ordinary Emacs interpretation of the following double-quote character.
ascii_value_of_quote() -> $".
The problem is that Emacs will also treat the
the_id() -> "$id: $".
Fortunately, there are ways around this. From Erlang's point of view
the following two strings are equal:
This work-around cannot always be used. For example, when the string is
used by an external version control program. In this situation we can
try to avoid placing the
-vsn(" $Revision: 1.1 $ ").
Should this not be possible we can try to create an artificial end of the string by placing an extra quote sign in the file. We do this as a comment:
-vsn("$Revision: 1.1 $"). % "
The comment will be ignored by Erlang since it is a comment. From Emacs point of view the comment character is part of the string.
This problem is a generic problem for languages with similar syntax. For example, the major mode for Perl suffers from the same problem.
An "electric" command is a character that in addition to just inserting the character performs some type of action. For example the ";" character is typed in a situation where is ends a function clause a new function header is generated.
Since some people find electric commands annoying they can be
deactivated, see section "
Insert a semicolon. When ending a function or the body of a
case clause, and the next few lines are empty, the special action will
be performed. For functions, a new function header will be generated
and the point will be placed between the parentheses. (See the
command
Insert a comma. If the point is at the end of the line and the next few lines are empty, a new indented line is created.
Insert a
The special action of this command is normally off by default. When
bound to the return key the following line will be indented. Should
the current line contain a comment the initial comment characters will
be copied to the new line. For example, assume that the point is at
the end of a line (denoted by "
When pressing return (and
This command has a second feature. When issued directly after another
electric command that created a new line this command does nothing.
The motivation is that it is in the fingers of many programmers to hit
the return key just when they have, for example, finished a function
clause with the
%% A comment
%% A comment
%%
All electric command will set an undo marker after the initial
character has been inserted but before the special action has been
performed. By executing the undo command (
The electric commands are controlled by a number of variables.
This variable controls if an electric command is active or not. This
variable should contain a list of electric commands to be active. To
activate all electric commands bind this variable to the atom
When non-
A list of electric commands. The command
There is one variable of this form for each electric command. The variable is used to decide if the special action of an electric command should be used. The variable contains a list of criteria functions that are called in the order they appear in the list.
If a criteria function returns the atom
Should the function
To disable all electric commands set the variable
(setq erlang-electric-commands '())
To activate all electric commands, including
(setq erlang-electric-commands t)
The Erlang editing mode has a set of commands that are aware of the Erlang functions and function clauses. The commands can be used to move the point (cursor) to the end of, or to the beginning of Erlang functions, or to jump between functions. The region can be placed around a function. Function headers can be cloned (copied).
There is a set of commands that can be used to move the point to the beginning or the end of an Erlang clause or function. The commands are also designed for movement between Erlang functions and clauses.
Move the point to the beginning of the current or preceding Erlang function. With an argument skip 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.
This function returns
As above but move point to the beginning of the current or preceding Erlang clause.
This function returns
Move to the end of the current or following Erlang function. With an argument to it that many times. Should the argument be negative move to the end of a function above the current functions.
As above but move point to the end of the current or following Erlang clause.
When one of the movement commands is executed and the point is already placed at the beginning or end of a function or clause, the point is moved to the previous/following function or clause.
When the point is above the first or below the last function in the
buffer, and an
The functions described above can be used both as user commands and
called as functions in programs written in Emacs Lisp.
Example:
The sequence below will move the point to the beginning of the current
function even if the point should already be positioned at the
beginning of the function:
Example:
To repeat over all the function in a buffer the following code can be
used. It will first move the point to the beginning of the buffer,
then it will locate the first Erlang function. Should the buffer
contain no functions at all the call to
(end-of-line)
(erlang-beginning-of-function)
(goto-char (point-min))
(erlang-end-of-function 1)
(let ((found-func (erlang-beginning-of-function 1)))
(while found-func
;; Do something with this function.
;; Go to the beginning of the next function.
(setq found-func (erlang-beginning-of-function -1))))
Put the region around the current Erlang function. The point is placed in the beginning and the mark at the end of the function.
Put the region around the current Erlang clause. The point is placed in the beginning and the mark at the end of the function.
Create a new clause in the current Erlang function. The point is placed between the parentheses of the argument list.
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.
Several clauses are considered to be part of the same Erlang function if they have the same name. It is possible that in the future the arity of the function also will be checked. To avoid to perform a full parse of the entire buffer the functions described in the chapter only look at lines where the function starts in the first column. This means that the commands does not work properly if the source code contain non-standardized indentation.
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
ranging from simple
The skeletons can be accessed either from the Erlang menu of from
commands named
The skeletons is defined using the standard Emacs package "tempo". It is possible to define new skeletons for your favorite erlang constructions.
In a skeleton certain positions are marked. These two commands move the point between such positions.
These commands inserts lines on the form
These commands generate three variants of file headers.
The following skeletons will complete almost ready-to-run modules.
It is possible to define new Erlang skeletons. The skeletons are defined using the standard package "tempo". The skeleton is described using the following variables:
Each skeleton is described by a variable. It contains a list of Tempo rules. See below for two examples of skeleton definitions. See the Tempo Reference Manual for a complete description of tempo rules.
This variable describes all Erlang skeletons. It is used to define the skeletons and to add them to the Erlang menu. The variable is a list where is each entry is either the empty list, representing a vertical bar in the menu, or a list on the form:
(Menu-name tempo-name erlang-skel-X)
The Menu-name is name to use in the menu. A named function is created
for each skeleton, it is
The best time to change this variable is right after the Erlang mode has been loaded but before it has been activated. See the "Example" section below.
Below is two example on skeletons and one example on how to add an
entry to the
Example 1:
The "If" skeleton is defined by the following variable (slightly rearranged for pedagogical reasons):
(defvar erlang-skel-if
'((erlang-skel-skip-blank) ;; 1
o ;; 2
> ;; 3
"if" ;; 4
n> ;; 5
p ;; 6
" ->" ;; 7
n> ;; 8
p ;; 9
"ok" ;; 10
n> ;; 11
"end" ;; 12
p)) ;; 13
Each line describes an action to perform:
Example 2:
This example contains very few entries. Basically, what it does is to include other skeletons in the correct place.
(defvar erlang-skel-small-header
'(o ;; 1
(erlang-skel-include erlang-skel-module ;; 2
erlang-skel-author)
n ;; 3
(erlang-skel-include erlang-skel-compile ;; 4
erlang-skel-export ;; 5
erlang-skel-vc))) ;; 6
The lines performs the following actions:
Example 3:
Here we assume that we have defined a new skeleton named
(defun my-erlang-skel-hook ()
(setq erlang-skel
(append erlang-skel
'(()
("Example" "example" erlang-skel-example)))))
(add-hook 'erlang-load-hook 'my-erlang-skel-hook)
The UNIX version of Erlang tools contain a set of manual pages that can be accessed by the standard UNIX command "man". The Erlang mode place a list of all available manual pages in the "Erlang" menu.
Unfortunately this feature is not available in the Windows version of the Erlang editing mode since the Erlang tools are not delivered with the manual pages.
In the Erlang menu a list of all Erlang manual pages can be found. The menu item "Man Pages". The sub-menu to this menu item contains a list of categories, normally "Man - Commands" and "Man - Modules". Under these is a menu containing the names of the man pages. Should this menu be to large it is split alphabetically into a number of sub-menus.
The menu item "Man - Function" is capable of finding the man page of a
named Erlang function. This commands understands the
The following variables control the manual page feature.
This variable is a list representing the sub-menu to the "Man Pages"
menu item in the Erlang menu. Each element is a list with three
elements. The first is the name of the menu, e.g. "Man - Modules" or
"Man - Local Stuff". The second is the name of a directory. The
third is a flag that control the interpretation of the directory.
When
The maximum number of menu items in a manual page menu. If the number of manual pages would be more than this variable the menu will be split alphabetically into chunks each not larger than the value of this variable.
Tags is a standard Emacs package used to record information about source files in large development projects. In addition to listing the files of a project, a tags file normally contains information about all functions and variables that are defined. By far, the most useful command of the tags system is its ability to find the definition of functions in any file in the project. However the Tags system is not limited to this feature, for example, it is possible to do a text search in all files in a project, or to perform a project-wide search and replace.
In order to use the Tags system a file named
The
The
As seen in the help text -- unless you have not upgraded your Emacs yet
(well, what are you waiting around here for? Off you go and upgrade!)
--
Basically, the
etags file1.erl file2.erl
This will create a file named
The
file . -name "*.[he]rl" -print | etags -
The above line will create a
Please see the GNU Emacs Manual and the etags man page for more info.
The code implementing the Erlang support for the
One of the tools in the Erlang distribution is a module named
The following are examples of useful functions in this module. Please see the reference manual on tags for details.
Create a
Create a tags file containing all Erlang source files in the directory
Create a
The standard Tags system has only support for simple names. The
naming convention
The Erlang mode supplies an alternative set of Tags functions that is
aware of the format
Currently, the additional Erlang module name support is not compatible
with the
Find a function definition. The default value is the function name
under the point. Should the function name lack the module specifier
the
The
As above, but the new file will be shown in another window in the same frame.
As
This command is used to fill in the end of a partially written
function name. For example, assume that the point is at the end of
the string
This command will search through all the files in a project for a string. (Actually, it search for a pattern described by a regular expression.)
Move the point to the next search match.
IMenu is a standard package of GNU Emacs. With IMenu it is possible to get a menu in the menu bar containing all the functions in the buffer. Erlang mode provides support for Erlang source files.
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.
See chapter "
To automatically create the IMenu menu for all Erlang buffers, place
the lines below into the appropriate init file (e.g. ~/.emacs). The
function
(add-hook 'erlang-mode-hook 'my-erlang-imenu-hook)
(defun my-erlang-imenu-hook ()
(if (and window-system (fboundp 'imenu-add-to-menubar))
(imenu-add-to-menubar "Functions")))
One of the strengths of Emacs is its ability to start slave processes. Since Emacs is extendible it is possible let Emacs be a part of a large application. For example, Emacs could be used as the user interface for Erlang applications.
The Erlang editing mode provides two simple, yet very useful, applications. The first is to start an Erlang shell and use an Emacs buffer for input and output. The second is a compile commands that makes it possible to compile Erlang modules and to locate the lines containing the compilation errors.
The actual communication between Emacs and Erlang can be performed by different low-level techniques. The Erlang editing mode provides a technique called "inferior" processes. The add on package Erl'em supplies a technically much more advanced communication technique known as an Erl'em link. All the commands that are provided by the editing mode can use either technique. However, more advanced packages will probably need features only provided by the Erl'em package.
The editing mode is capable of starting a so called "inferior" Erlang process. This is a normal subprocess that use one Emacs buffer for input and output. The effect is that a command line shell, or an Erlang shell, can be displayed inside Emacs.
The big drawback with an inferior process is that the communication
between Emacs and the process is limited to commands issued at the
command line. Since this is the interface that is used by the user it
is difficult, to say the least, to write an Emacs application that
communicate with the inferior process. For example, the
The Erl'em package established a low-level communication channel between Emacs and an Erlang node. This communication channel can be used by Emacs to issue several independent Erlang commands, to start Erlang processes and to open several Erlang IO streams. It is also possible for Erlang to call Emacs functions.
In short the Erl'em package is designed to be the base of complex application that is partially implemented in Emacs and partially in Erlang.
It is the hope of the author that the Erl'em link in the future will be used as the base for porting the user interface of the Erlang debugger to Emacs. If this could be possible, Emacs could be used as an Integrated Debugger Environment (IDE) for Erlang.
The structure of the Erl'em link and its programming interface is described in the text "Erl'em Developers Manual".
It is possible to start an Erlang shell inside Emacs. The shell will use an Emacs buffer for input and output. Normal Emacs commands can be used to edit the command line and to recall lines from the command line history.
The output will never be erased from the buffer so you will never risk letting important output fall over the top edge of the display.
As discussed in the previous chapter there are two low-level methods for Emacs to communicate with Erlang. The first is by starting an inferior process, the second is by using an Erl'em link. When using inferior processes each new shell will start a new Erlang node. Should the Erl'em link be used it is possible to start several shells on the same node, a feature not normally available.
In this section we describe how to start a shell. In the next we cover how to use it once it has been started.
Start a new Erlang shell. When an inferior process is used a new Erlang node is started for each shell. Should the Erl'em link package be installed several shells can be started on the same Erlang node.
A word of warning. The Erlang function
Display one Erlang shell. If there are no Erlang shells active a new will be started.
The look and feel on an Erlang shell inside Emacs should be the same as in a normal Erlang shell. There is just one major difference, the cursor keys will actually move the cursor around just like in any normal Emacs buffer. The command line history can be accessed by the following commands:
Move to the previous line in the input history.
Move to the next line in the input history.
If the Erlang shell buffer would be killed the command line history is saved to a file. The command line history is automatically retrieved when a new Erlang shell is started.
The buffers that are used to run Erlang shells use the major mode
Enter Erlang shell mode. To operate correctly the buffer should be in Comint mode when this command is called.
In this section we present the variables that control the behavior of the Erlang shell. See also the next section "Inferior Erlang Variables".
Function to run when this mode is activated. See chapter "
The file name used to save the command line history.
This variable contain the low-level function to call to start an Erlang shell. This variable will be changed by the Erl'em installation.
This variable contain the low-level function to call when the
The variables described in this chapter are only used when inferior Erlang processes are used. They do not affect the behavior of the shell when using an Erl'em link.
When this variable is
There are two different variants of the Erlang shell, named the old and the new shell. The old is a simple variant that does not provide command line editing facilities. The new, on the other hand, provide full edition features. Apart from this major difference, they differ on some subtle points. Since Emacs itself takes care of the command line edition features you can switch between the two shell types if your shell behaves strange.
To use the new or the old shell bind this variable to
The command name of the Erlang runtime system.
A list of strings containing command line options that is used when starting an inferior Erlang.
The base name of the Erlang shell buffer. Should several Erlang shell
buffers be used they will be named
The classic edit-compile-bugfix cycle for Erlang is to edit the source file in an editor, save it to a file and switch to an Erlang shell. In the shell the compilation command is given. Should the compilation fail you have to bring out the editor and locate the correct line.
With the Erlang editing mode the entire edit-compile-bugfix cycle can be performed without leaving Emacs. Emacs can order Erlang to compile a file and it can parse the error messages to automatically place the point on the erroneous lines.
This command compiles the file in the current buffer.
The action performed by this command depend on the low-level communication method used. Should an inferior Erlang process be used Emacs tries to issue a compile command at the Erlang shell prompt. The compilation output will be sent to the shell buffer. This command will fail if it is not possible to issue a command at the Erlang shell prompt.
Should an Erl'em link be used the compile command sent to Erlang will be independent of any active shell. The output will be sent to a dedicated buffer.
This command will place the point on the line where the first error was found. Each successive use of this command will move the point to the next error. The buffer displaying the compilation errors will be updated so that the current error will be visible.
You can reparse the compiler output from the beginning by preceding
this command by
Show the output generated by the compile command.
In some versions of Erlang the
Should this variable be set to
The low-level function to use to compile an Erlang module.
The low-level function to call when the result of a compilation should be shown.
The low-level function to use when
One of the strengths of Emacs is that users can fairly easy customize the behavior of almost every detail. The Erlang editing mode is not an exception to this rule.
Normally, Emacs is customized through the user and system init files,
In this section we show the basic constructions of Emacs Lisp needed to perform customizations.
In addition to placing the expressions in the init file, they can be
evaluated while Emacs is started. One method is to use the
Below is a series of example that we use to demonstrate simple Emacs Lisp constructions.
In this example we set the variable
(setq foo (+ 10 a))
In this example we first define a function
(defun bar (a b c d)
(+ a b c d))
(message "The sum becomes %d" (bar 1 2 3 4))
Among the Emacs Lisp data types we have atoms. However, in
the following expressions we assign the variable
(setq foo bar)
To assign the variable
(setq foo 'bar)
A hook variable is a variable that contain a list of functions to run. In Emacs there is a large number of hook variables, each is runed at a special situation. By adding functions to hooks the user make Emacs automatically perform anything (well, almost).
To add a function to a hook you must use the function
See chapter "The Editing Mode" above for a list of hooks defined by the Erlang editing mode.
In this example we add
(add-hook 'erlang-new-file-hook 'tempo-template-erlang-large-header)
Here we define a new function that sets a few variables when it is
called. We then add the function to the hook
(defun my-erlang-mode-hook ()
(setq erlang-electric-commands t))
(add-hook 'erlang-mode-hook 'my-erlang-mode-hook)
It is possible to bind keys to your favorite commands. Emacs use a number of key-maps: the global key-map defines the default value of keys, local maps are used by the individual major modes, minor modes can have their own key map etc.
The commands
If we would like to redefine a key in the Erlang editing mode we can
do that by activating Erlang mode and call
Example:
Here we bind
(defun my-erlang-keymap-hook ()
(local-set-key (read-kbd-macro "C-c C-c") 'erlang-compile)
(local-set-key (read-kbd-macro "") 'erlang-shell)
(local-set-key (read-kbd-macro "M-") 'erlang-shell-display))
(add-hook 'erlang-mode-hook 'my-erlang-keymap-hook)
The function
Example:
In Erlang mode the tags commands understand the Erlang module naming
convention. However, the normal tags commands does not. This line
will bind
(global-set-key (read-kbd-macro "M-." 'erlang-find-tag))
Today there are two major Emacs development streams. The first is GNU Emacs from Free Software Foundation and the second is XEmacs. Both have advantages and disadvantages, you have to decide for yourself which Emacs you prefer.
This is the standard distribution from The Free Software Foundation, an organization lead by the original author of Emacs, Richard M. Stallman.
The source code for the latest version of Emacs can be fetched from
This is an alternative version of Emacs. Historically XEmacs is based on Lucid Emacs that in turn was based on an early version of Emacs 19. The big advantage of XEmacs is that it can handle graphics much better. One difference is a list of icons that contains a number of commonly used commands. Another is the ability to display graphical images in the buffer.
The major drawback is that when a new feature turns up in GNU Emacs, it will often take quite a long time before it will be incorporated into XEmacs.
The latest distribution can be fetched from
The source distributions usually comes in a tared and gzipped format. Unpack this with the following command:
tar zxvf .tar.gz
If your tar command do not know how to handle the "z" (unpack) option you can unpack it separately:
gunzip .tar.gz
tar xvf .tar
The program
Next, read the file named
In the OTP installation, the Erlang editing mode is already installed. All that is needed is that the system administrator or the individual user configures their Emacs Init files to use it.
If we assume that OTP has been installed in
OTP_ROOT, the editing mode can be found in
OTP_ROOT
The
emacs -batch -q -no-site-file -f batch-byte-compile erlang.el
System administrators edit
On UNIX systems, individuals should edit/create the file
On Windows NT/95, individuals should also edit/create their
The directory with the editing mode,
OTP_ROOT
Add the following line to the selected initialization file (replace
Note: When running under Windows, use
Some functions in the Erlang editing mode require that the OTP
installation directory is known. The following is an example where we
assume that they are installed in the directory
To use inferior Erlang Shells, you need to do the following
configuration. If your PATH environment variable already
includes the location of the
You can either extend the PATH environment variable with the
location of the
You can also extend the execution path for Emacs as described
below. If the executable is located in
Finally, add the following line to the init file:
This will inform Emacs that the Erlang editing mode is available. It
will associate the file extensions
Below is a complete example of what should be added to a user's
Any additional user configurations can be added after this. See for
instance section "
Below is a complete example of what should be added to a user's
Any additional user configurations can be added after this. See for
instance section "
Restart the Emacs and load or create an Erlang file (with the
(setq load-path (cons "OTP_ROOT/misc/emacs" load-path))
(setq erlang-root-dir "OTP_ROOT")
(setq exec-path (cons "OTP_ROOT/bin" exec-path))
(require 'erlang-start)
(setq load-path (cons "/usr/local/otp/misc/emacs"
load-path))
(setq erlang-root-dir "/usr/local/otp")
(setq exec-path (cons "/usr/local/otp/bin" exec-path))
(require 'erlang-start)
(setq load-path (cons "C:/Program Files/erl-4.7/misc/emacs"
load-path))
(setq erlang-root-dir "C:/Program Files/erl-4.7")
(setq exec-path (cons "C:/Program Files/erl-4.7/bin" exec-path))
(require 'erlang-start)
In this book we use the same terminology used in the Emacs documentation. This chapter contain a short glossary of words and their meaning in the Emacs world.
A buffer is used by Emacs to handle text. When editing a file the content is loaded into a buffer. However buffers can contain other things as well. For example, a buffer can contain a list of files in a directory, it can contain generated help texts, or it is possible to start processes that use a buffer in Emacs for input and output. A buffer need not be visible, but if it is, it is shown in a window.
Emacs is written in two languages. The Emacs core is written in C. The major part, as well as most add-on packages, are written in Emacs Lisp. This is also the language used by the init files.
This is what most other systems refer to as a window . Emacs use frame since the word window was used for another feature long before window systems were invented.
Files read by Emacs at startup. The user startup file is named
A major mode provides support for edit text of a particular sort. For example, the Erlang editing mode is a major mode. Each buffer have exactly one major mode active.
A minor mode provides some additional support. Each buffer can have
several minor modes active at the same time. One example is
The line at the bottom of each Emacs window that contain information about the buffer. E.g. the name of the buffer, the line number, and the name of the the current major mode.
The value used in Emacs Lisp to represent false. True can be
represented by any non-
The 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 value
An area where text is visible in Emacs. A frame (which is a window in non-Emacs terminology) can contain one or more windows. New windows can be created by splitting windows either vertically or horizontally.
All commands in Emacs have names. A named command can be executed by
pressing
In this chapter I present some references to material on Emacs. They are divided into the two categories "Usage" and "Development". The first is for normal Emacs users who would like to know how to get more power out of their editor. The second is for people who would like to develop their own applications in Emacs Lisp.
Personally, I would recommend the series of books from the Free Software Foundation, they are written by the people that wrote Emacs and they form a coherent series useful for everyone from beginners to experienced Emacs Lisp developers.
This is the Bible on using Emacs. It is written by the principle author of Emacs. An on-line version of this manual is part of the standard Emacs distribution, see the "Help->Browse Manuals" menu.
General Emacs group, everything is discussed here from beginners to complex development issues.
This group cover XEmacs only.
This group is like "comp.emacs" except that the topic only should cover GNU Emacs, not XEmacs or any other Emacs derivate.
In this group a lot of interesting Emacs packages are posted. In fact only source code is permitted, questions should be redirected to one of the other Emacs groups.
If you have found a bug in Emacs you should post it here. Do not post bug reports on packages that are nor part of the standard Emacs distribution, they should be sent to the maintainer of the package.
This a good introduction to Lisp in general and Emacs Lisp in
particular. Just like the other books form FSF, this book is free and
can be downloaded from
This is the main source of information for any serious Emacs
developer. This manual covers every aspect of Emacs Lisp. This
manual, like Emacs itself, is free. The manuscript can be downloaded
from
This is a good tutorial on how to write Emacs packages.
This text covers the architecture of the Erl'em communication link and the application programmers interface to it.
The tempo package is presented in this manual. The latest version can
be found at
Please send bug reports to the following email address:
support@erlang.ericsson.se
Please state as accurate as possible:
Should the Emacs generate an error, please set the emacs variable
To set the variable you can use the following command:
M-x set-variable RET debug-on-error RET t RET