~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/tools/doc/src/erlang_mode_chapter.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
 
3
 
 
4
<chapter>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>2003</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>The Erlang mode for Emacs</title>
 
27
    <prepared></prepared>
 
28
    <docno></docno>
 
29
    <date></date>
 
30
    <rev></rev>
 
31
  </header>
 
32
 
 
33
  <section>
 
34
    <title>Purpose</title>
 
35
    <p>The purpose of this user guide is to introduce you to the
 
36
      Erlang mode for Emacs and gives some relevant background
 
37
      information of the functions and features. See also <seealso marker="erlang_mode">Erlang mode reference manual</seealso> The
 
38
      purpose of the Erlang mode itself is to facilitate the developing
 
39
      process for the Erlang programmer.</p>
 
40
  </section>
 
41
 
 
42
  <section>
 
43
    <title>Pre-requisites</title>
 
44
    <p>Basic knowledge of Emacs and Erlang/OTP. </p>
 
45
  </section>
 
46
 
 
47
  <section>
 
48
    <title>Elisp</title>
 
49
    <p>There are two Elsip modules include in this tool package
 
50
      for Emacs. There is erlang.el that defines the actual erlang mode
 
51
      and there is erlang-start.el that makes some nice initializations.</p>
 
52
  </section>
 
53
 
 
54
  <section>
 
55
    <title>Setup on UNIX</title>
 
56
    <p>To set up the Erlang Emacs mode on a UNIX systems, edit/create
 
57
      the file <c>.emacs</c> in the your home directory.</p>
 
58
    <p>Below is a complete example of what should be added to a user's
 
59
      <c>.emacs</c> provided that OTP is installed in the directory
 
60
      <c>/usr/local/otp </c>: </p>
 
61
    <code type="none"><![CDATA[
 
62
      (setq load-path (cons  "/usr/local/otp/lib/tools-<ToolsVer>/emacs"
 
63
      load-path))
 
64
      (setq erlang-root-dir "/usr/local/otp")
 
65
      (setq exec-path (cons "/usr/local/otp/bin" exec-path))
 
66
      (require 'erlang-start)
 
67
    ]]></code>
 
68
  </section>
 
69
 
 
70
  <section>
 
71
    <title>Setup on Windows </title>
 
72
    <p>To set up the Erlang Emacs mode on a Windows systems,
 
73
      edit/create the file <c>.emacs</c>, the location of the file
 
74
      depends on the configuration of the system. If the <em>HOME</em>
 
75
      environment variable is set, Emacs will look for the
 
76
      <c>.emacs</c> file in the directory indicated by the
 
77
      <em>HOME</em> variable. If <em>HOME</em> is not set, Emacs
 
78
      will look for the <c>.emacs</c> file in <c>C:\\ </c>.</p>
 
79
    <p>Below is a complete example of what should be added to a user's
 
80
      <c>.emacs</c> provided that OTP is installed in the directory
 
81
      <c><![CDATA[C:\\Program Files\\erl<Ver>]]></c>: </p>
 
82
    <code type="none"><![CDATA[
 
83
      (setq load-path (cons  "C:/Program Files/erl<Ver>/lib/tools-<ToolsVer>/emacs"
 
84
      load-path))
 
85
      (setq erlang-root-dir "C:/Program Files/erl<Ver>")
 
86
      (setq exec-path (cons "C:/Program Files/erl<Ver>/bin" exec-path))
 
87
      (require 'erlang-start)
 
88
    ]]></code>
 
89
    <note>
 
90
      <p>In .emacs, the slash character "/" can be used as path
 
91
        separator. But if you decide to use the backslash character "\\",
 
92
        please not that you must use double backslashes, since they are
 
93
        treated as escape characters by Emacs.</p>
 
94
    </note>
 
95
  </section>
 
96
 
 
97
  <section>
 
98
    <title>Indentation</title>
 
99
    <p>The "Oxford Advanced Learners Dictionary of Current English" says the
 
100
      following about the word "indent":</p>
 
101
    <quote>
 
102
      <p>"start (a line of print or writing) farther from
 
103
        the margin than the others".</p>
 
104
    </quote>
 
105
    <p>The Erlang mode does, of course, provide this feature. The layout
 
106
      used is based on the common use of the language.</p>
 
107
    <p>It is strongly recommend to use this feature and avoid to indent lines
 
108
      in a nonstandard way.  Some motivations are:</p>
 
109
    <list type="bulleted">
 
110
      <item>Code using the same layout is easy to read and maintain. </item>
 
111
      <item>Since several features of Erlang mode is based on the
 
112
       standard layout they might not work correctly if a nonstandard layout
 
113
       is used. </item>
 
114
    </list>
 
115
    <p>The indentation features can be used to reindent large sections
 
116
      of a file.  If some lines use nonstandard indentation they will
 
117
      be reindented.</p>
 
118
  </section>
 
119
 
 
120
  <section>
 
121
    <title>Editing</title>
 
122
    <list type="bulleted">
 
123
      <item><em><c>M-x erlang-mode RET</c></em> - This command activates
 
124
       the Erlang major mode for the current buffer.  When this
 
125
       mode is active the mode line contain the word "Erlang".</item>
 
126
    </list>
 
127
    <p>When the Erlang mode is correctly installed, it is
 
128
      automatically activated when a file ending in <c>.erl</c> or
 
129
      <c>.hrl</c> is opened in Emacs.</p>
 
130
    <p>When a file is saved the name in the <c>-module().</c> line is
 
131
      checked against the file name. Should they mismatch Emacs can
 
132
      change the module specifier so that it matches the file name.
 
133
      By default, the user is asked before the change is performed.</p>
 
134
    <p>An "electric" command is a character that in addition to just
 
135
      inserting the character performs some type of action.  For
 
136
      example the ";" character is typed in a situation where is ends
 
137
      a function clause a new function header is generated. The electric
 
138
      commands are as follows: </p>
 
139
    <list type="bulleted">
 
140
      <item><em><c>erlang-electric-comma</c></em> - Insert a comma
 
141
       character and possibly a new indented line. </item>
 
142
      <item><em><c>erlang-electric-semicolon</c></em> - Insert a
 
143
       semicolon character and possibly a prototype for the next line.</item>
 
144
      <item><em><c>erlang-electric-gt</c></em> - "Insert a '>'-sign
 
145
       and possible a new indented line.</item>
 
146
    </list>
 
147
    <p>To disable all electric commands set the variable
 
148
      <c>erlang-electric-commands</c> to the empty list.  In short,
 
149
      place the following line in your <c>.emacs</c>-file:</p>
 
150
    <code type="none">
 
151
      (setq erlang-electric-commands '())</code>
 
152
  </section>
 
153
 
 
154
  <section>
 
155
    <title>Syntax highlighting</title>
 
156
    <p>It is possible for Emacs to use colors when displaying a buffer. By
 
157
      "syntax highlighting", we mean that syntactic components, for example
 
158
      keywords and function names, will be colored.</p>
 
159
    <p>The basic idea of syntax highlighting is to make the structure of a
 
160
      program clearer. For example, the highlighting will make it easier to
 
161
      spot simple bugs.  Have not you ever written a variable in lower-case
 
162
      only?  With syntax highlighting a variable will colored while atoms
 
163
      will be shown with the normal text color.</p>
 
164
  </section>
 
165
 
 
166
  <section>
 
167
    <marker id="tags"></marker>
 
168
    <title>Tags</title>
 
169
    <p>Tags is a standard Emacs package used to record information
 
170
      about source files in large development projects. In addition to
 
171
      listing the files of a project, a tags file normally contains
 
172
      information about all functions and variables that are defined.
 
173
      By far, the most useful command of the tags system is its ability
 
174
      to find the definition of functions in any file in the project.
 
175
      However the Tags system is not limited to this feature, for
 
176
      example, it is possible to do a text search in all files in a
 
177
      project, or to perform a project-wide search and replace.</p>
 
178
    <p>In order to use the Tags system a file named <c>TAGS</c> must be
 
179
      created.  The file can be seen as a database over all functions,
 
180
      records, and macros in all files in the project.  The
 
181
      <c>TAGS</c> file can be created using two different methods for
 
182
      Erlang.  The first is the standard Emacs utility "etags", the
 
183
      second is by using the Erlang module <c>tags</c>.</p>
 
184
  </section>
 
185
 
 
186
  <section>
 
187
    <title>Etags</title>
 
188
    <p><c>etags</c> is a program that is part of the Emacs
 
189
      distribution.  It is normally executed from a command line, like
 
190
      a unix shell or a DOS box.</p>
 
191
    <p>The <c>etags</c> program of fairly modern versions of Emacs and XEmacs
 
192
      has native support for Erlang.  To check if your version does include
 
193
      this support, issue the command <c>etags --help</c> at a the command
 
194
      line prompt.  At the end of the help text there is a list of supported
 
195
      languages.  Unless Erlang is a member of this list I suggest that you
 
196
      should upgrade to a newer version of Emacs.</p>
 
197
    <p>As seen in the help text -- unless you have not upgraded your
 
198
      Emacs yet (well, what are you waiting around here for?  Off you go and
 
199
      upgrade!)  -- <c>etags</c> associate the file extensions <c>.erl</c>
 
200
      and <c>.hrl</c> with Erlang.</p>
 
201
    <p>Basically, the <c>etags</c> utility is runed using the following form:</p>
 
202
    <code type="none">
 
203
      etags file1.erl file2.erl</code>
 
204
    <p>This will create a file named <c>TAGS</c> in the current directory.</p>
 
205
    <p>The <c>etags</c> utility can also read a list of files from its
 
206
      standard input by supplying a single dash in place of the file
 
207
      names.  This feature is useful when a project consists of a
 
208
      large number of files.  The standard UNIX command <c>find</c>
 
209
      can be used to generate the list of files, e.g:</p>
 
210
    <code type="none">
 
211
      find . -name "*.[he]rl" -print | etags -</code>
 
212
    <p>The above line will create a <c>TAGS</c> file covering all the
 
213
      Erlang source files in the current directory, and in the
 
214
      subdirectories below.</p>
 
215
    <p>Please see the GNU Emacs Manual and the etags man page for more
 
216
      info.</p>
 
217
  </section>
 
218
 
 
219
  <section>
 
220
    <title>Shell</title>
 
221
    <p>The look and feel on an Erlang shell inside Emacs should be the
 
222
      same as in a normal Erlang shell.  There is just one major
 
223
      difference, the cursor keys will actually move the cursor around
 
224
      just like in any normal Emacs buffer. The command line history
 
225
      can be accessed by the following commands: </p>
 
226
    <list type="bulleted">
 
227
      <item><em><c>C-up </c></em>  or <em><c>M-p </c></em>
 
228
       (<c>comint-previous-input</c>) -
 
229
       Move to the previous line in the input history.</item>
 
230
      <item><em><c>C-down </c></em> or <em><c>M-n </c></em>
 
231
       (<c>comint-next-input</c>) - Move to the next line in the
 
232
       input history.</item>
 
233
    </list>
 
234
    <p>If the Erlang shell buffer would be killed the command line
 
235
      history is saved to a file.  The command line history is
 
236
      automatically retrieved when a new Erlang shell is started.</p>
 
237
  </section>
 
238
 
 
239
  <section>
 
240
    <title>Compilation</title>
 
241
    <p>The classic edit-compile-bugfix cycle for Erlang is to edit the
 
242
      source file in an editor, save it to a file and switch to an
 
243
      Erlang shell. In the shell the compilation command is given.
 
244
      Should the compilation fail you have to bring out the editor and
 
245
      locate the correct line.</p>
 
246
    <p>With the Erlang editing mode the entire edit-compile-bugfix cycle can
 
247
      be performed without leaving Emacs.  Emacs can order Erlang to compile
 
248
      a file and it can parse the error messages to automatically place the
 
249
      point on the erroneous lines.</p>
 
250
  </section>
 
251
</chapter>
 
252