<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css"> <title>Erlang -- The Erlang mode for Emacs</title> </head> <body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container"> <script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript"> <!-- function getWinHeight() { var myHeight = 0; if( typeof( window.innerHeight ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; } function setscrollpos() { var objf=document.getElementById('loadscrollpos'); document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } addEvent(window, 'load', setscrollpos); //--></script><div id="leftnav"><div class="innertube"> <img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/tools-2.6.8.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Tools</strong><br><strong>User's Guide</strong><br><small>Version 2.6.8</small></p> <br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p> <ul class="flipMenu" imagepath="../../../../doc/js/flipmenu"> <li id="no" title="cover" expanded="false">cover<ul> <li><a href="cover_chapter.html"> Top of chapter </a></li> <li title="Introduction"><a href="cover_chapter.html#id64809">Introduction</a></li> <li title="Getting Started With Cover"><a href="cover_chapter.html#id62638">Getting Started With Cover</a></li> <li title="Miscellaneous"><a href="cover_chapter.html#id60749">Miscellaneous</a></li> <li title="Using the Web Based User Interface to Cover"><a href="cover_chapter.html#id63969">Using the Web Based User Interface to Cover</a></li> </ul> </li> <li id="no" title="cprof - The Call Count Profiler" expanded="false">cprof - The Call Count Profiler<ul> <li><a href="cprof_chapter.html"> Top of chapter </a></li> <li title="Example: Background work"><a href="cprof_chapter.html#id62155">Example: Background work</a></li> <li title="Example: One module"><a href="cprof_chapter.html#id62215">Example: One module</a></li> <li title="Example: In the code"><a href="cprof_chapter.html#id62262">Example: In the code</a></li> </ul> </li> <li id="loadscrollpos" title="The Erlang mode for Emacs" expanded="true">The Erlang mode for Emacs<ul> <li><a href="erlang_mode_chapter.html"> Top of chapter </a></li> <li title="Purpose"><a href="erlang_mode_chapter.html#id64082">Purpose</a></li> <li title="Pre-requisites"><a href="erlang_mode_chapter.html#id64101">Pre-requisites</a></li> <li title="Elisp"><a href="erlang_mode_chapter.html#id64113">Elisp</a></li> <li title="Setup on UNIX"><a href="erlang_mode_chapter.html#id64126">Setup on UNIX</a></li> <li title="Setup on Windows "><a href="erlang_mode_chapter.html#id64160">Setup on Windows </a></li> <li title="Indentation"><a href="erlang_mode_chapter.html#id64228">Indentation</a></li> <li title="Editing"><a href="erlang_mode_chapter.html#id64277">Editing</a></li> <li title="Syntax highlighting"><a href="erlang_mode_chapter.html#id64373">Syntax highlighting</a></li> <li title="Tags"><a href="erlang_mode_chapter.html#id64396">Tags</a></li> <li title="Etags"><a href="erlang_mode_chapter.html#id64430">Etags</a></li> <li title="Shell"><a href="erlang_mode_chapter.html#id64528">Shell</a></li> <li title="Compilation"><a href="erlang_mode_chapter.html#id64585">Compilation</a></li> </ul> </li> <li id="no" title="fprof - The File Trace Profiler" expanded="false">fprof - The File Trace Profiler<ul> <li><a href="fprof_chapter.html"> Top of chapter </a></li> <li title="Profiling from the source code"><a href="fprof_chapter.html#id64914">Profiling from the source code</a></li> <li title="Profiling a function"><a href="fprof_chapter.html#id64995">Profiling a function</a></li> <li title="Immediate profiling"><a href="fprof_chapter.html#id65025">Immediate profiling</a></li> </ul> </li> <li id="no" title="lcnt - The Lock Profiler" expanded="false">lcnt - The Lock Profiler<ul> <li><a href="lcnt_chapter.html"> Top of chapter </a></li> <li title=" Enabling lock-counting "><a href="lcnt_chapter.html#id65145"> Enabling lock-counting </a></li> <li title="Getting started"><a href="lcnt_chapter.html#id65194">Getting started</a></li> <li title=" Example of usage "><a href="lcnt_chapter.html#id65262"> Example of usage </a></li> <li title=" Example with Mnesia Transaction Benchmark "><a href="lcnt_chapter.html#id65351"> Example with Mnesia Transaction Benchmark </a></li> <li title=" Deciphering the output "><a href="lcnt_chapter.html#id65488"> Deciphering the output </a></li> <li title="See Also"><a href="lcnt_chapter.html#id65506">See Also</a></li> </ul> </li> <li id="no" title="Xref - The Cross Reference Tool" expanded="false">Xref - The Cross Reference Tool<ul> <li><a href="xref_chapter.html"> Top of chapter </a></li> <li title="Module Check"><a href="xref_chapter.html#id65613">Module Check</a></li> <li title="Predefined Analysis"><a href="xref_chapter.html#id65693">Predefined Analysis</a></li> <li title="Expressions"><a href="xref_chapter.html#id65996">Expressions</a></li> <li title="Graph Analysis"><a href="xref_chapter.html#id66325">Graph Analysis</a></li> </ul> </li> </ul> </div></div> <div id="content"> <div class="innertube"> <h1>3 The Erlang mode for Emacs</h1> <h3><a name="id64082">3.1 Purpose</a></h3> <p>The purpose of this user guide is to introduce you to the Erlang mode for Emacs and gives some relevant background information of the functions and features. See also <span class="bold_code"><a href="erlang.el.html">Erlang mode reference manual</a></span> The purpose of the Erlang mode itself is to facilitate the developing process for the Erlang programmer.</p> <h3><a name="id64101">3.2 Pre-requisites</a></h3> <p>Basic knowledge of Emacs and Erlang/OTP. </p> <h3><a name="id64113">3.3 Elisp</a></h3> <p>There are two Elisp modules included in this tool package for Emacs. There is erlang.el that defines the actual erlang mode and there is erlang-start.el that makes some nice initializations.</p> <h3><a name="id64126">3.4 Setup on UNIX</a></h3> <p>To set up the Erlang Emacs mode on a UNIX systems, edit/create the file <span class="code">.emacs</span> in the your home directory.</p> <p>Below is a complete example of what should be added to a user's <span class="code">.emacs</span> provided that OTP is installed in the directory <span class="code">/usr/local/otp </span>: </p> <div class="example"><pre> (setq load-path (cons "/usr/local/otp/lib/tools-<ToolsVer>/emacs" load-path)) (setq erlang-root-dir "/usr/local/otp") (setq exec-path (cons "/usr/local/otp/bin" exec-path)) (require 'erlang-start) </pre></div> <h3><a name="id64160">3.5 Setup on Windows </a></h3> <p>To set up the Erlang Emacs mode on a Windows systems, edit/create the file <span class="code">.emacs</span>, the location of the file depends on the configuration of the system. If the <strong>HOME</strong> environment variable is set, Emacs will look for the <span class="code">.emacs</span> file in the directory indicated by the <strong>HOME</strong> variable. If <strong>HOME</strong> is not set, Emacs will look for the <span class="code">.emacs</span> file in <span class="code">C:\ </span>.</p> <p>Below is a complete example of what should be added to a user's <span class="code">.emacs</span> provided that OTP is installed in the directory <span class="code">C:\Program Files\erl<Ver></span>: </p> <div class="example"><pre> (setq load-path (cons "C:/Program Files/erl<Ver>/lib/tools-<ToolsVer>/emacs" load-path)) (setq erlang-root-dir "C:/Program Files/erl<Ver>") (setq exec-path (cons "C:/Program Files/erl<Ver>/bin" exec-path)) (require 'erlang-start) </pre></div> <div class="note"> <div class="label">Note</div> <div class="content"><p> <p>In .emacs, the slash character "/" can be used as path separator. But if you decide to use the backslash character "\", please not that you must use double backslashes, since they are treated as escape characters by Emacs.</p> </p></div> </div> <h3><a name="id64228">3.6 Indentation</a></h3> <p>The "Oxford Advanced Learners Dictionary of Current English" says the following about the word "indent":</p> <p>"start (a line of print or writing) farther from the margin than the others".</p> <p>The Erlang mode does, of course, provide this feature. The layout used is based on the common use of the language.</p> <p>It is strongly recommend to use this feature and avoid to indent lines in a nonstandard way. Some motivations are:</p> <ul> <li>Code using the same layout is easy to read and maintain. </li> <li>Since several features of Erlang mode is based on the standard layout they might not work correctly if a nonstandard layout is used. </li> </ul> <p>The indentation features can be used to reindent large sections of a file. If some lines use nonstandard indentation they will be reindented.</p> <h3><a name="id64277">3.7 Editing</a></h3> <ul> <li> <strong><span class="code">M-x erlang-mode RET</span></strong> - This command activates the Erlang major mode for the current buffer. When this mode is active the mode line contain the word "Erlang".</li> </ul> <p>When the Erlang mode is correctly installed, it is automatically activated when a file ending in <span class="code">.erl</span> or <span class="code">.hrl</span> is opened in Emacs.</p> <p>When a file is saved the name in the <span class="code">-module().</span> line is checked against the file name. Should they mismatch Emacs can change the module specifier so that it matches the file name. By default, the user is asked before the change is performed.</p> <p>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. The electric commands are as follows: </p> <ul> <li> <strong><span class="code">erlang-electric-comma</span></strong> - Insert a comma character and possibly a new indented line. </li> <li> <strong><span class="code">erlang-electric-semicolon</span></strong> - Insert a semicolon character and possibly a prototype for the next line.</li> <li> <strong><span class="code">erlang-electric-gt</span></strong> - "Insert a '>'-sign and possible a new indented line.</li> </ul> <p>To disable all electric commands set the variable <span class="code">erlang-electric-commands</span> to the empty list. In short, place the following line in your <span class="code">.emacs</span>-file:</p> <div class="example"><pre> (setq erlang-electric-commands '())</pre></div> <h3><a name="id64373">3.8 Syntax highlighting</a></h3> <p>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.</p> <p>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.</p> <h3><a name="id64396">3.9 Tags</a></h3> <a name="tags"></a> <p>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.</p> <p>In order to use the Tags system a file named <span class="code">TAGS</span> must be created. The file can be seen as a database over all functions, records, and macros in all files in the project. The <span class="code">TAGS</span> file can be created using two different methods for Erlang. The first is the standard Emacs utility "etags", the second is by using the Erlang module <span class="code">tags</span>.</p> <h3><a name="id64430">3.10 Etags</a></h3> <p><span class="code">etags</span> is a program that is part of the Emacs distribution. It is normally executed from a command line, like a unix shell or a DOS box.</p> <p>The <span class="code">etags</span> program of fairly modern versions of Emacs and XEmacs has native support for Erlang. To check if your version does include this support, issue the command <span class="code">etags --help</span> at a the command line prompt. At the end of the help text there is a list of supported languages. Unless Erlang is a member of this list I suggest that you should upgrade to a newer version of Emacs.</p> <p>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!) -- <span class="code">etags</span> associate the file extensions <span class="code">.erl</span> and <span class="code">.hrl</span> with Erlang.</p> <p>Basically, the <span class="code">etags</span> utility is ran using the following form:</p> <div class="example"><pre> etags file1.erl file2.erl</pre></div> <p>This will create a file named <span class="code">TAGS</span> in the current directory.</p> <p>The <span class="code">etags</span> utility can also read a list of files from its standard input by supplying a single dash in place of the file names. This feature is useful when a project consists of a large number of files. The standard UNIX command <span class="code">find</span> can be used to generate the list of files, e.g:</p> <div class="example"><pre> find . -name "*.[he]rl" -print | etags -</pre></div> <p>The above line will create a <span class="code">TAGS</span> file covering all the Erlang source files in the current directory, and in the subdirectories below.</p> <p>Please see the GNU Emacs Manual and the etags man page for more info.</p> <h3><a name="id64528">3.11 Shell</a></h3> <p>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: </p> <ul> <li> <strong><span class="code">C-up </span></strong> or <strong><span class="code">M-p </span></strong> (<span class="code">comint-previous-input</span>) - Move to the previous line in the input history.</li> <li> <strong><span class="code">C-down </span></strong> or <strong><span class="code">M-n </span></strong> (<span class="code">comint-next-input</span>) - Move to the next line in the input history.</li> </ul> <p>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.</p> <h3><a name="id64585">3.12 Compilation</a></h3> <p>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.</p> <p>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.</p> </div> <div class="footer"> <hr> <p>Copyright © 1997-2012 Ericsson AB. All Rights Reserved.</p> </div> </div> </div></body> </html>