📄 emacs.sgml
字号:
methods for Emacs to communicate with Erlang. The first is bystarting an inferior process, the second is by using an Erl'em link.When using inferior processes each new shell will start a new Erlangnode. Should the Erl'em link be used it is possible to start severalshells on the same node, a feature not normally available.</P><SECTION><TITLE>The shell</TITLE><P>In this section we describe how to start a shell. In the next we coverhow to use it once it has been started.</P><LIST> <ITEM><C> M-x erlang-shell RET </C><BR><P>Start a new Erlang shell. When an inferior process is used a newErlang node is started for each shell. Should the Erl'em link packagebe installed several shells can be started on the same Erlang node.</P><P>A word of warning. The Erlang function <C>halt().</C> will kill thecurrent Erlang node, including all shells running on it.</P> <ITEM><C> M-x erlang-shell-display RET </C><BR><P>Display one Erlang shell. If there are no Erlang shells active a newwill be started.</P></LIST></SECTION><SECTION><TITLE>Command line history</TITLE><P>The look and feel on an Erlang shell inside Emacs should be the sameas in a normal Erlang shell. There is just one major difference, thecursor keys will actually move the cursor around just like in anynormal Emacs buffer. The command line history can be accessed by thefollowing commands:</P><LIST> <ITEM><C> C-up </C> or <C> M-p </C> (<C>comint-previous-input</C>)<BR><P>Move to the previous line in the input history.</P> <ITEM><C> C-down </C> or <C> M-n </C> (<C>comint-next-input</C>)<BR><P>Move to the next line in the input history.</P></LIST><P>If the Erlang shell buffer would be killed the command line history issaved to a file. The command line history is automatically retrievedwhen a new Erlang shell is started.</P></SECTION><SECTION><TITLE>The Erlang Shell Mode</TITLE><P>The buffers that are used to run Erlang shells use the major mode<C>erlang-shell-mode</C>. This major mode is based on the standardmode <C>comint-mode</C>.</P><LIST> <ITEM><C> erlang-shell-mode </C><BR><P>Enter Erlang shell mode. To operate correctly the buffer should be inComint mode when this command is called. </P></LIST></SECTION><SECTION><TITLE>Variables</TITLE><P>In this section we present the variables that control the behavior ofthe Erlang shell. See also the next section "Inferior ErlangVariables".</P><LIST><ITEM> <EM>Variable: </EM> <C>erlang-shell-mode-hook</C>(default <C>()</C>)<BR><P>Function to run when this mode is activated. See chapter "<SEEALSOMARKER="#customization">Customization</SEEALSO>" below for examples.</P><ITEM> <EM>Variable: </EM> <C>erlang-input-ring-file-name</C>(default "~/.erlang_history")<BR><P>The file name used to save the command line history.</P><ITEM> <EM>Variable: </EM> <C>erlang-shell-function</C>(default <C>inferior-erlang</C>)<BR><P>This variable contain the low-level function to call to start anErlang shell. This variable will be changed by the Erl'eminstallation.</P><ITEM> <EM>Variable: </EM> <C>erlang-shell-display-function</C>(default <C>inferior-erlang-run-or-select</C>)<BR><P>This variable contain the low-level function to call when the<C>erlang-shell-display</C> is issued. This variable will be changed bythe Erl'em installation.</P></LIST></SECTION><SECTION><TITLE>Inferior Erlang Variables</TITLE><P>The variables described in this chapter are only used when inferiorErlang processes are used. They do not affect the behavior of theshell when using an Erl'em link.</P><LIST> <ITEM> <EM>Variable: </EM> <C>inferior-erlang-display-buffer-any-frame</C> (default<C>nil</C>)<BR><P>When this variable is <C>nil</C> the command<C>erlang-shell-display</C> will display the inferior process in thecurrent frame. When <C>t</C>, it will do nothing when it already isvisible in another frame. When it is bound to the atom <C>raise</C>the frame displaying the buffer will be raised.</P> <ITEM> <EM>Variable: </EM> <C>inferior-erlang-shell-type</C>(default <C>newshell</C>)<BR><P>There are two different variants of the Erlang shell, named the oldand the new shell. The old is a simple variant that does not providecommand line editing facilities. The new, on the other hand, providefull edition features. Apart from this major difference, they differon some subtle points. Since Emacs itself takes care of the commandline edition features you can switch between the two shell types ifyour shell behaves strange.</P><P>To use the new or the old shell bind this variable to <C>newshell</C> or<C>oldshell</C>, respectively.</P> <ITEM> <EM>Variable: </EM> <C>inferior-erlang-machine</C>(default <C>"erl"</C>)<BR><P>The command name of the Erlang runtime system.</P> <ITEM> <EM>Variable: </EM> <C>inferior-erlang-machine-options</C>(default <C>()</C>)<BR><P>A list of strings containing command line options that is used whenstarting an inferior Erlang.</P> <ITEM> <EM>Variable: </EM> <C>inferior-erlang-buffer-name</C>(default <C>"*erlang*"</C>)<BR><P>The base name of the Erlang shell buffer. Should several Erlang shellbuffers be used they will be named <C>*erlang*<2></C>,<C>*erlang*<3></C> etc.</P></LIST></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Compilation</TITLE><P>The classic edit-compile-bugfix cycle for Erlang is to edit the sourcefile in an editor, save it to a file and switch to an Erlang shell.In the shell the compilation command is given. Should the compilationfail 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 canbe performed without leaving Emacs. Emacs can order Erlang to compilea file and it can parse the error messages to automatically place thepoint on the erroneous lines.</P><SECTION><TITLE>Commands</TITLE><LIST> <ITEM><C>C-c C-k</C> (<C>erlang-compile</C>)<BR><P>This command compiles the file in the current buffer.</P><P>The action performed by this command depend on the low-levelcommunication method used. Should an inferior Erlang process be usedEmacs 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 theErlang shell prompt.</P><P>Should an Erl'em link be used the compile command sent to Erlang willbe independent of any active shell. The output will be sent to adedicated buffer.</P> <ITEM><C>C-x ` </C> (<C>erlang-next-error</C>)<BR><P>This command will place the point on the line where the first errorwas found. Each successive use of this command will move the point tothe next error. The buffer displaying the compilation errors will beupdated so that the current error will be visible.</P><P>You can reparse the compiler output from the beginning by precedingthis command by <C> C-u </C>.</P> <ITEM><C>erlang-compile-display</C><BR><P>Show the output generated by the compile command.</P></LIST></SECTION><SECTION><TITLE>Variables</TITLE><LIST> <ITEM> <EM>Variable: </EM> <C>erlang-compile-use-outdir</C>(default <C>t</C>)<BR><P>In some versions of Erlang the <C>outdir</C> options contains a bug.Should the directory not be present in the current Erlang load paththe object file will not be loaded.</P><P>Should this variable be set to <C>nil</C> the <C>erlang-compile</C>command will use a workaround by change current directory, compile thefile, and change back.</P> <ITEM> <EM>Variable: </EM> <C>erlang-compile-function</C>(default <C>inferior-erlang-compile</C>)<BR><P>The low-level function to use to compile an Erlang module.</P> <ITEM> <EM>Variable: </EM> <C>erlang-compile-display-function</C>(default <C>inferior-erlang-run-or-select</C>)<BR><P>The low-level function to call when the result of a compilation shouldbe shown.</P> <ITEM> <EM>Variable: </EM> <C>erlang-next-error-function</C>(default <C>inferior-erlang-next-error</C>)<BR><P>The low-level function to use when <C>erlang-next-error</C> is used.</P></LIST></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Customization</TITLE><P>One of the strengths of Emacs is that users can fairly easy customizethe behavior of almost every detail. The Erlang editing mode is notan exception to this rule.</P><P>Normally, Emacs is customized through the user and system init files,<C>~/.emacs</C> and <C>site-start.el</C>, respectively. The contentof the files are expressions written in the Emacs extension languageEmacs Lisp. The semantics of Lisp is fairly similar Erlang's.However, the syntax is very different. Fortunately, mostcustomizations require only very minor knowledge of the language.</P><SECTION><TITLE>Emacs Lisp</TITLE><P>In this section we show the basic constructions of Emacs Lisp needed toperform customizations.</P><P>In addition to placing the expressions in the init file, they can beevaluated while Emacs is started. One method is to use the <C> M-:</C> (On older versions of Emacs this is bound to <C> ESC ESC</C>)function that evaluates Emacs Lisp expressions in the minibuffer.Another method is to write the expressions in the <C> *scratch* </C> buffer,place the point at the end of the line and press <C>C-j</C>.</P><P>Below is a series of example that we use to demonstrate simple EmacsLisp constructions.</P><LIST> <ITEM> <EM>Example 1:</EM> <BR><P>In this example we set the variable <C>foo</C> to the value 10 addedto the value of the variable <C>a</C>. As we can see by this example,Emacs Lisp use prefix form for all function calls, including simplefunctions like <C>+</C>.</P><CODE>(setq foo (+ 10 a))</CODE> <ITEM> <EM>Example 2:</EM> <BR><P>In this example we first define a function <C>bar</C> that sums the valueof its four parameters. Then we evaluated an expression that firstcalls <C>bar</C> then calls the standard Emacs function <C>message</C>.</P><CODE>(defun bar (a b c d) (+ a b c d))(message "The sum becomes %d" (bar 1 2 3 4))</CODE> <ITEM> <EM>Example 3:</EM><BR><P>Among the Emacs Lisp data types we have atoms. However, inthe following expressions we assign the variable <C>foo</C> the value ofthe variable <C>bar</C>.</P><CODE>(setq foo bar)</CODE><P>To assign the variable <C>foo</C> the atom <C>bar</C> we must quotethe atom with a <C>'</C>-character. Note the syntax, we should precede theexpression (in this case <C>bar</C>) with the quote, not surround it.</P><CODE>(setq foo 'bar)</CODE></LIST></SECTION><SECTION><TITLE>Hooks</TITLE><P>A hook variable is a variable that contain a list of functions torun. In Emacs there is a large number of hook variables, each isruned at a special situation. By adding functions to hooks the usermake Emacs automatically perform anything (well, almost).</P><P>To add a function to a hook you must use the function <C>add-hook</C>.To remove it use <C>remove-hook</C>.</P><P>See chapter "The Editing Mode" above for a list of hooks defined bythe Erlang editing mode.</P><LIST> <ITEM> <EM> Example: </EM> <BR><P>In this example we add <C>tempo-template-erlang-large-header</C> tothe hook <C>erlang-new-file-hook</C>. The effect is that whenever anew Erlang file is created a file header is immediately inserted.</P><CODE> (add-hook 'erlang-new-file-hook 'tempo-template-erlang-large-header)</CODE><ITEM> <EM> Example: </EM> <BR><P>Here we define a new function that sets a few variables when it iscalled. We then add the function to the hook <C>erlang-mode-hook</C> thatgets called every time Erlang mode is activated.</P><CODE>(defun my-erlang-mode-hook () (setq erlang-electric-commands t))(add-hook 'erlang-mode-hook 'my-erlang-mode-hook)</CODE></LIST></SECTION><SECTION><MARKER ID="key_bindings"><TITLE>Custom Key Bindings</TITLE><P>It is possible to bind keys to your favorite commands. Emacs use anumber of key-maps: the global key-map defines the default value ofkeys, local maps are used by the individual major modes, minor modescan have their own key map etc.</P><P>The commands <C>global-set-key</C> and <C>local-set-key</C> defineskeys in the glo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -