📄 emacs.sgml
字号:
<LIST><ITEM><EM> Variable: </EM> <C>erlang-indent-level</C> (default 4)<BR><P>The amount of indentation for normal Erlang functions and complexexpressions. Should, for example, the value of this variable be 2 theexample above would be indented like:</P><CODE>remove_bugs([]) -> [];remove_bugs([X | Xs]) case X of bug -> test(Xs); _ -> [X | test(Xs)] end.</CODE><ITEM><EM> Variable: </EM> <C>erlang-indent-guard</C> (default 2)<BR><P>The amount of indentation for Erlang guards.</P><ITEM><EM> Variable: </EM> <C>erlang-argument-indent</C> (default 2)<BR><P>The amount of indentation for function calls that span several lines.</P><P><EM> Example: </EM></P><CODE>foo() -> a_very_long_function_name( AVeryLongVariableName),</CODE><ITEM><EM> Variable: </EM> <C>erlang-tab-always-indent</C>(default <C>t</C>)<BR><P>When non-<C>nil</C> the <C>TAB</C> command always indents the line(this is the default). When <C>nil</C>, the line will be indentedonly when the point is in the beginning of any text on the line,otherwise it will insert a tab character into the buffer.</P></LIST></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE> General Commands </TITLE><P>This chapter contains a group of commands that are not found in anyother category. Unlike most other books we do not have a chapter named"Miscellaneous xxx" found at the end of most books. This chapter isplaced near the beginning to reflect the importance and usefulness ofthe commands.</P><SECTION><TITLE>Filling comments</TITLE><P>How many times have you edited a section of text in a comment only towind up with a unevenly formatted paragraph? Or even worse, have youever decided not to edit a comment just because the formatting wouldlook bad?</P><P>When editing normal text in text mode you can let Emacs reformat thetext by the <C>fill-paragraph</C> command. This command will not workfor comments since it will treat the comment characters as words.</P><P>The Erlang editing mode provides a command that known about the Erlangcomment structure and can be used to fill text paragraphs in comments.</P><LIST><ITEM><C>M-q</C> (<C>erlang-fill-paragraph</C>)<BR>Fill the text in an Erlang comment. This command known about theErlang comment characters. The column to perform the word wrap isdefined by the variable <C>fill-column</C>.</LIST><P><EM> Example: </EM></P><P>For the sake of this example, let's assume that <C>fill-column</C> is setto column 30. Assume that we have an Erlang comment paragraph on thefollowing form:</P><CODE>%% This is just a test to show%% how the Erlang fill %% paragraph command works.</CODE><P>Assume that you would add the words "very simple" before the word"test":</P><CODE>%% This is just a very simple test to show%% how the Erlang fill%% paragraph command works.</CODE><P>Clearly, the text is badly formatted. Instead of formatting thisparagraph line by line, let's try <C>erlang-fill-paragraph</C> bypressing <C>M-q</C>. The result is:</P><CODE>%% This is just a very simple%% test to show how the Erlang%% fill paragraph command%% works.</CODE><P>As you can see the paragraph is now evenly formatted.</P></SECTION><SECTION><TITLE> Creating Comments </TITLE><P>In Erlang it is possible to write comments to the right of the code.The indentation system described in the chapter "Indentation" above isable to indent lines containing only comments, and gives support forend-of-the-line comments.</P><LIST><ITEM><C>M-;</C> (<C>indent-for-comment</C>)<BR>This command will create, or reindent, a comment to the right of thecode. The variable <C>comment-column</C> controls the placement of thecomment character.</LIST></SECTION><SECTION><TITLE> Comment Region </TITLE><P>The standard command <C>comment-region</C> can be used to comment outall lines in a region. To uncomment the lines in a region precedethis command with <C>C-u</C>.</P></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Syntax Highlighting</TITLE><P>It is possible for Emacs to use colors when displaying a buffer. By"syntax highlighting", we mean that syntactic components, for examplekeywords and function names, will be colored.</P><P>The basic idea of syntax highlighting is to make the structure of aprogram clearer. For example, the highlighting will make it easier tospot simple bugs. Have not you ever written a variable in lower-caseonly? With syntax highlighting a variable will colored while atomswill be shown with the normal text color.</P><P>The syntax highlighting can be activated from the Erlang menu. Thereare four different alternatives:</P><LIST><ITEM> Off: Normal black and white display.<ITEM> Level 1: Function headers, reserved words, comments, strings, quotedatoms, and character constants will be colored.<ITEM> Level 2: The above, attributes, Erlang bif:s, guards, and wordsin comments enclosed in single quotes will be colored.<ITEM> Level 3: The above, variables, records, and macros will be colored.(This level is also known as the Christmas tree level.)</LIST><P>The syntax highlighting is based on the standard Emacs package"font-lock". It is possible to use the font-lock commands andvariables to enable syntax highlighting. The commands in questionare:</P><LIST><ITEM><C>M-x font-lock-mode RET</C><BR><P>This command activates syntax highlighting for the current buffer.</P><ITEM><C>M-x global-font-lock-mode RET</C><BR><P>Activate syntax highlighting for all buffers.</P></LIST><P>The variable <C>font-lock-maximum-decoration</C> is used to specifythe level of highlighting. If the variable is bound to an integer,that level is used; if it is bound to <C>t</C> the highest possiblelevel is used. (It is possible to set different levels for differentediting modes; please see the font-lock documentation for moreinformation.)</P><P>It is possible to change the color used. It is even possible to usebold, underlined, and italic fonts in combination with colors.However, the method to do this differs between Emacs and XEmacs; andbetween different versions of Emacs. For Emacs 19.34, the variable<C>font-lock-face-attributes</C> controls the colors. For version 20 ofEmacs and XEmacs, the faces can be defined in the interactive customsystem.</P><SECTION><MARKER ID="font-lock"><TITLE>Customization</TITLE><P>Font-lock mode is activated in different ways in different versions ofEmacs. For modern versions of GNU Emacs place the following lines inyour <C>~/.emacs</C> file:</P><CODE>(setq font-lock-maximum-decoration t)(global-font-lock-mode 1)</CODE><!-- TODO: Check this --><P>For modern versions of XEmacs the following code can be used:</P><CODE>(setq auto-font-lock-mode 1)</CODE><P>For older versions of Emacs and XEmacs, font-lock mode must beactivated individually for each buffer. The following will add afunction to the Erlang mode hook that activates font-lock mode for allErlang buffers.</P><CODE>(defun my-erlang-font-lock-hook () (font-lock-mode 1))(add-hook 'erlang-mode-hook 'my-erlang-font-lock-hook)</CODE></SECTION><SECTION><TITLE>Known Problems</TITLE><P>Emacs has one problem with the syntactic structure of Erlang, namelythe <C>$</C> character. The normal Erlang use of the $ character isto denote the ASCII value of a character, for example:</P><CODE>ascii_value_of_a() -> $a.</CODE><P>In order to get the font-lock mechanism to work for the next example,the $ character must be marked as an "escape" character that changesthe ordinary Emacs interpretation of the following double-quotecharacter.</P><CODE>ascii_value_of_quote() -> $".</CODE><P>The problem is that Emacs will also treat the <C>$</C> character as an"escape" character at the end of strings and quoted atoms.Practically, this means that Emacs will not detect the end of thefollowing string:</P> <CODE>the_id() -> "$id: $".</CODE><P>Fortunately, there are ways around this. From Erlang's point of viewthe following two strings are equal: <C>"test$"</C> and<C>"test\$"</C>. The <C>\</C>-character is also marked as an Emacs "escape"character, hence it will change the Emacs interpretation of the<C>$</C>-character.</P><P>This work-around cannot always be used. For example, when the string isused by an external version control program. In this situation we cantry to avoid placing the <C>$</C>-character at the end of the string, forexample:</P><CODE>-vsn(" $Revision: 1.1 $ ").</CODE><P>Should this not be possible we can try to create an artificial end ofthe string by placing an extra quote sign in the file. We do this as acomment:</P><CODE>-vsn("$Revision: 1.1 $"). % "</CODE><P>The comment will be ignored by Erlang since it is a comment. FromEmacs point of view the comment character is part of the string.</P><P>This problem is a generic problem for languages with similar syntax.For example, the major mode for Perl suffers from the same problem.</P></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Electric Commands</TITLE><P>An "electric" command is a character that in addition to justinserting the character performs some type of action. For example the";" character is typed in a situation where is ends a function clausea new function header is generated.</P><P>Since some people find electric commands annoying they can bedeactivated, see section "<SEEALSO MARKER="#unplug_elec">Unpluggingthe Electric Commands</SEEALSO>" below.</P><SECTION><TITLE>The Commands</TITLE><LIST><ITEM><C> ; </C> (<C>erlang-electric-semicolon</C>)<BR><P>Insert a semicolon. When ending a function or the body of acase clause, and the next few lines are empty, the special action willbe performed. For functions, a new function header will be generatedand the point will be placed between the parentheses. (See thecommand <C>erlang-clone-arguments</C>.) For other clauses the string"<C> -></C>" will be inserted and the point will be placed in from ofthe arrow.</P><ITEM><C> , </C> (<C>erlang-electric-comma</C>)<BR><P>Insert a comma. If the point is at the end of the lineand the next few lines are empty, a new indented line is created.</P><ITEM><C> > </C> (<C>erlang-electric-arrow</C>)<BR><P>Insert a <C>></C> character. If it is inserted at the end of a lineafter a <C>-</C> character so that an arrow "<C>-></C>" is beingformed, a new indented line is created. This requires that the nextfew lines are empty.<ITEM><C> RET </C> (<C>erlang-electric-newline</C>)<BR><P>The special action of this command is normally off by default. Whenbound to the return key the following line will be indented. Shouldthe current line contain a comment the initial comment characters willbe copied to the new line. For example, assume that the point is atthe end of a line (denoted by "<C><point></C>" below).</P><CODE> %% A comment<point></CODE><P>When pressing return (and <C>erlang-electric-newline</C> is active)the result will be:</P><CODE> %% A comment %% <point></CODE><P>This command has a second feature. When issued directly after anotherelectric command that created a new line this command does nothing.The motivation is that it is in the fingers of many programmers to hitthe return key just when they have, for example, finished a functionclause with the <C>;</C> character. Without this feature both theelectric semicolon and this command would insert one line each whichis probably not what the user wants.</P></LIST></SECTION><SECTION><TITLE> Undo </TITLE><P>All electric command will set an undo marker after the initialcharacter has been inserted but before the special action has beenperformed. By executing the undo command (<C>C-x u</C>) the effect ofthe special action will be undone while leaving the character.Execute undo a second time to remove the character itself.</P></SECTION><SECTION><TITLE> Variables </TITLE><P>The electric commands are controlled by a number of variables.</P><LIST> <ITEM><C>erlang-electric-commands</C><BR><P>This variable controls if an electric command is active or not. Thisvariable should contain a list of electric commands to be active. Toactivate all electric commands bind this variable to the atom<C>t</C>.</P> <ITEM><C>erlang-electric-newline-inhibit</C><BR><P>When non-<C>nil</C> when <C>erlang-electric-newline</C> should donothing when preceded by a electric command that is member of thelist <C>erlang-electric-newline-inhibit-list</C>.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -