⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emacs.sgml

📁 OTP是开放电信平台的简称
💻 SGML
📖 第 1 页 / 共 5 页
字号:
<EM> Example 3: </EM></P><P>Here we assume that we have defined a new skeleton named<C>erlang-skel-example</C>.  The best time to add this skeleton to thevariable <C>erlang-skel</C> is when Erlang mode has been loaded butbefore it has been activated.  We define a function that adds twoentries to <C>erlang-skel</C>, the first is <C>()</C> that represent adivisor in the menu, the second is the entry for the <C>Example</C>skeleton.  We then add the function to the <C>erlang-load-hook</C>, ahook that is called when Erlang mode is loaded into Emacs.<CODE>(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)</CODE></SECTION></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Manual Pages</TITLE><P>The UNIX version of Erlang tools contain a set of manual pages thatcan be accessed by the standard UNIX command "man".  The Erlang modeplace a list of all available manual pages in the "Erlang" menu.</P><P>Unfortunately this feature is not available in the Windows version ofthe Erlang editing mode since the Erlang tools are not delivered withthe manual pages.</P><SECTION><TITLE> The Menu </TITLE><P>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 alist 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 numberof sub-menus.</P><P>The menu item "Man - Function" is capable of finding the man page of anamed Erlang function.  This commands understands the<C>module:function</C> notation.  This command defaults to the name underthe point.  Should the name not contain a module name the list ofimported modules is searched.</P></SECTION><SECTION><TITLE>Customization</TITLE><P>The following variables control the manual page feature.</P><LIST>  <ITEM><C>erlang-man-dirs</C><BR><P>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 threeelements.  The first is the name of the menu, e.g. "Man - Modules" or"Man - Local Stuff".  The second is the name of a directory.  Thethird is a flag that control the interpretation of the directory.When <C>nil</C> the directory is treated as an absolute path, whennon-<C>nil</C> it is taken as relative to the directory named in thevariable <C>erlang-root-dir</C>.</P>  <ITEM><C>erlang-man-max-menu-size</C><BR><P>The maximum number of menu items in a manual page menu.  If the numberof manual pages would be more than this variable the menu will besplit alphabetically into chunks each not larger than the value ofthis variable.</P></LIST></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Tags</TITLE><P>Tags is a standard Emacs package used to record information aboutsource files in large development projects.  In addition to listingthe files of a project, a tags file normally contains informationabout all functions and variables that are defined.  By far, the mostuseful command of the tags system is its ability to find thedefinition of functions in any file in the project.  However the Tagssystem is not limited to this feature, for example, it is possible todo a text search in all files in a project, or to perform aproject-wide search and replace.</P><SECTION><TITLE>Creating a TAGS file</TITLE><P>In order to use the Tags system a file named <C>TAGS</C> must be created.The file can be seen as a database over all functions, records, andmacros in all files in the project.  The <C>TAGS</C> file can be createdusing to different methods for Erlang.  The first is the standardEmacs utility "etags", the second is by using the Erlang module<C>tags</C>.</P></SECTION><SECTION><TITLE>The etags utility</TITLE><!-- <TITLE>The <C>etags</C> utility</TITLE> --><P>The <C>etags</C> is a program that is part of the Emacs distribution.  Itis normally executed from a command line, like a unix shell or a DOSbox.</P><P>The <C>etags</C> program of fairly modern versions of Emacs and XEmacshas native support for Erlang.  To check if your version does includethis support, issue the command <C>etags --help</C> at a the commandline prompt.  At the end of the help text there is a list of supportedlanguages.  Unless Erlang is a member of this list I suggest that youshould 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!)-- <C>etags</C> associate the file extensions <C>.erl</C> and<C>.hrl</C> with Erlang.</P><P>Basically, the <C>etags</C> utility is runed using the following form:</P><CODE>    etags file1.erl file2.erl</CODE><P>This will create a file named <C>TAGS</C> in the current directory.</P><P>The <C>etags</C> utility can also read a list of files from its standardinput by supplying a single dash in place of the file names.  Thisfeature is useful when a project consists of a large number of files.The standard UNIX command <C>find</C> can be used to generate the list offiles, e.g:</P><CODE>    file . -name "*.[he]rl" -print | etags -</CODE><P>The above line will create a <C>TAGS</C> file covering all the Erlangsource files in the current directory, and in the subdirectoriesbelow.</P><P>Please see the GNU Emacs Manual and the etags man page for more info.</P><P>The code implementing the Erlang support for the <C>etags</C> program hasbeen donated to the Free Software Foundation by the company AndersLindgren Development.</P></SECTION><SECTION><TITLE>The tags Erlang module</TITLE><!-- <TITLE>The <C>tags</C> Erlang module</TITLE> --><P>One of the tools in the Erlang distribution is a module named<C>tags</C>.  This tool can create a <C>TAGS</C> file from Erlangsource files.</P><P>The following are examples of useful functions in this module.  Pleasesee the reference manual on tags for details.</P><LIST>  <ITEM><C>tags:file('foo.erl').</C><BR><P>Create a <C>TAGS</C> file for the file "foo.erl".</P>  <ITEM><C>tags:subdir('src/project/', [{outfile, 'project.TAGS'}]).</C><BR><P>Create a tags file containing all Erlang source files in the directory<C>"src/project/"</C>.  The option <C>outfile</C> specify the name ofthe created <C>TAGS</C> file.</P>  <ITEM><C>tags:root([{outdir, 'bar'}]).</C><BR><P>Create a <C>TAGS</C> file of all the Erlang files in the Erlangdistribution.  The <C>TAGS</C> file will be placed in the the directory<C>bar</C>.</P></LIST></SECTION><SECTION><TITLE>Additional Erlang support</TITLE><P>The standard Tags system has only support for simple names.  Thenaming convention <C>module:function</C> used by Erlang is not supported.</P><P>The Erlang mode supplies an alternative set of Tags functions that isaware of the format <C>module:function</C>.  When selecting a thedefault search string for the commands the name under the point isfirst selected.  Should the name not contain a module name the<C>-import</C> list at the beginning of the buffer is scanned.</P><SECTION><TITLE>Limitations</TITLE><P>Currently, the additional Erlang module name support is not compatiblewith the <C>etags.el</C> package that is part of XEmacs.</P></SECTION></SECTION><SECTION><TITLE>Useful Tags Commands</TITLE><LIST>  <ITEM><C> M-. </C> (<C>erlang-find-tag</C>)<BR><P>Find a function definition.  The default value is the function nameunder the point.  Should the function name lack the module specifierthe <C>-import</C> list is searched for an appropriate candidate.</P>  <ITEM><C> C-u M-. </C> (<C>erlang-find-tag</C> with an argument)<BR><P>The <C>find-tag</C> commands place the point on the first occurrence ofa function that match the tag.  This command move the point to thenext match.</P>  <ITEM><C> C-x 4 . </C> (<C>erlang-find-tag-other-window</C>)<BR><P>As above, but the new file will be shown in another window in the sameframe.</P>  <ITEM><C> C-x 5 . </C> (<C>erlang-find-tag-other-frame</C>)<BR><P>As <C>erlang-find-tag</C> but the new file will be shown in a new frame.</P>  <ITEM><C> M-TAB </C> (<C>erlang-complete-tag</C>)<BR><P>This command is used to fill in the end of a partially writtenfunction name.  For example, assume that the point is at the end ofthe string <C>a_long</C>, and the Tags file contain the function<C>a_long_function_name</C>.  By executing this command the string<C>a_long</C> will be expanded into <C>a_long_function_name</C>.</P>  <ITEM><C> M-x tags-search RET </C><BR><P>This command will search through all the files in a project for astring.  (Actually, it search for a pattern described by a regularexpression.)</P>  <ITEM><C> M-, </C> (<C>tags-loop-continue</C>)<BR><P>Move the point to the next search match.</P></LIST></SECTION></SECTION><SECTION><TITLE>IMenu</TITLE><P>IMenu is a standard package of GNU Emacs.  With IMenu it is possibleto get a menu in the menu bar containing all the functions in thebuffer.  Erlang mode provides support for Erlang source files.</P><!-- TODO<P>Unfortunately the IMenu package is not part of XEmacs.  In the futureErlang mode might get support for the XEmacs package "funcmenu" thatprovides similar support for XEmacs.</P>--><SECTION><TITLE>Starting IMenu</TITLE><LIST>  <ITEM><C> M-x imenu-add-to-menubar RET</C><BR><P>This command will create the IMenu menu containing all the functionsin the current buffer.  The command will ask you for a suitable namefor the menu.</P></LIST></SECTION><SECTION><TITLE>Customization</TITLE><P>See chapter "<SEEALSO MARKER="#customization">Customization</SEEALSO>"below for a general description on how to customize the Erlang mode.</P><P>To automatically create the IMenu menu for all Erlang buffers, placethe lines below into the appropriate init file (e.g. ~/.emacs).  Thefunction <C>my-erlang-imenu-hook</C> will be called each time anErlang source file is read.  It will call the<C>imenu-add-to-menubar</C> function.  The menu will be named"Functions".</P><CODE>(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")))</CODE></SECTION></SECTION><!-- ---------------------------- Inferior Erlang --><!-- - CHAPTER --><SECTION><TITLE>Running Erlang from Emacs</TITLE><P>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 alarge application.  For example, Emacs could be used as the userinterface for Erlang applications.</P><P>The Erlang editing mode provides two simple, yet very useful,applications.  The first is to start an Erlang shell and use an Emacsbuffer for input and output.  The second is a compile commands thatmakes it possible to compile Erlang modules and to locate the linescontaining the compilation errors.</P><P>The actual communication between Emacs and Erlang can be performed bydifferent low-level techniques.  The Erlang editing mode provides atechnique called "inferior" processes.  The add on package Erl'emsupplies a technically much more advanced communication techniqueknown as an Erl'em link.  All the commands that are provided by theediting mode can use either technique.  However, more advancedpackages will probably need features only provided by the Erl'empackage.</P><SECTION><TITLE>Inferior Erlang</TITLE><P>The editing mode is capable of starting a so called "inferior" Erlangprocess.  This is a normal subprocess that use one Emacs buffer forinput and output.  The effect is that a command line shell, or anErlang shell, can be displayed inside Emacs.</P><P>The big drawback with an inferior process is that the communicationbetween Emacs and the process is limited to commands issued at thecommand line.  Since this is the interface that is used by the user itis difficult, to say the least, to write an Emacs application thatcommunicate with the inferior process.  For example, the<C>erlang-compile</C> command described in the section "Compilation"below really stretch the capabilities of the inferior Erlang process.In fact, should the user have issued a command that would take sometime to complete it is impossible for Emacs to perform the<C>erlang-compile</C> command.</P></SECTION><SECTION><TITLE>The Erl'em Link</TITLE><P>The Erl'em package established a low-level communication channelbetween Emacs and an Erlang node.  This communication channel can beused by Emacs to issue several independent Erlang commands, to startErlang processes and to open several Erlang IO streams.  It is alsopossible for Erlang to call Emacs functions.</P><P>In short the Erl'em package is designed to be the base of complexapplication that is partially implemented in Emacs and partially inErlang.</P><P>It is the hope of the author that the Erl'em link in the future willbe used as the base for porting the user interface of the Erlangdebugger to Emacs.  If this could be possible, Emacs could be used asan Integrated Debugger Environment (IDE) for Erlang.</P><P>The structure of the Erl'em link and its programming interface isdescribed in the text "Erl'em Developers Manual".</P></SECTION></SECTION><!-- CHAPTER --><SECTION><TITLE>Erlang Shell</TITLE><P>It is possible to start an Erlang shell inside Emacs.  The shell willuse an Emacs buffer for input and output.  Normal Emacs commands canbe used to edit the command line and to recall lines from the commandline history.</P><P>The output will never be erased from the buffer so you will never riskletting important output fall over the top edge of the display.</P><P>As discussed in the previous chapter there are two low-level

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -