Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / doc / guide / localhost / EmacsDefUseMode
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>EmacsDefUseMode</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>EmacsDefUseMode</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p>MLton provides an <a href="CompileTimeOptions">option</a>,
32 <span class="monospaced">-show-def-use <em>file</em></span>, to output precise (giving exact source
33 locations) and accurate (including all uses and no false data)
34 whole-program def-use information to a file. Unlike typical tags
35 facilities, the information includes local variables and distinguishes
36 between different definitions even when they have the same name. The
37 def-use Emacs mode uses the information to provide navigation support,
38 which can be particularly useful while reading SML programs compiled
39 with MLton (such as the MLton compiler itself).</p></div>
40 </div>
41 </div>
42 <div class="sect1">
43 <h2 id="_screen_capture">Screen Capture</h2>
44 <div class="sectionbody">
45 <div class="paragraph"><p>Note the highlighting and the type displayed in the minibuffer.</p></div>
46 <div class="imageblock" style="text-align:center;">
47 <div class="content">
48 <img src="EmacsDefUseMode.attachments/def-use-capture.png" alt="EmacsDefUseMode.attachments/def-use-capture.png">
49 </div>
50 </div>
51 </div>
52 </div>
53 <div class="sect1">
54 <h2 id="_features">Features</h2>
55 <div class="sectionbody">
56 <div class="ulist"><ul>
57 <li>
58 <p>
59 Highlights definitions and uses. Different colors for definitions, unused definitions, and uses.
60 </p>
61 </li>
62 <li>
63 <p>
64 Shows types (with highlighting) of variable definitions in the minibuffer.
65 </p>
66 </li>
67 <li>
68 <p>
69 Navigation: <span class="monospaced">jump-to-def</span>, <span class="monospaced">jump-to-next</span>, and <span class="monospaced">jump-to-prev</span>. These work precisely (no searching involved).
70 </p>
71 </li>
72 <li>
73 <p>
74 Can list, visit and mark all references to a definition (within a program).
75 </p>
76 </li>
77 <li>
78 <p>
79 Automatically reloads updated def-use files.
80 </p>
81 </li>
82 <li>
83 <p>
84 Automatically loads previously used def-use files at startup.
85 </p>
86 </li>
87 <li>
88 <p>
89 Supports both <a href="http://www.gnu.org/software/emacs/">Gnu Emacs</a> and <a href="http://www.xemacs.org">XEmacs</a>.
90 </p>
91 </li>
92 </ul></div>
93 </div>
94 </div>
95 <div class="sect1">
96 <h2 id="_download">Download</h2>
97 <div class="sectionbody">
98 <div class="paragraph"><p>There is no separate package for the def-use mode although the mode
99 has been relatively stable for some time already. To install the mode
100 you need to get the Emacs Lisp, <span class="monospaced">*.el</span>, files from MLton&#8217;s repository:
101 <a href="https://github.com/MLton/mlton/tree/master/ide/emacs"><span class="monospaced">emacs</span></a>. The easiest way to get the files
102 is to use <a href="Git">Git</a> to access MLton&#8217;s <a href="Sources">sources</a>.</p></div>
103 </div>
104 </div>
105 <div class="sect1">
106 <h2 id="_setup">Setup</h2>
107 <div class="sectionbody">
108 <div class="paragraph"><p>The easiest way to load def-use mode is to first tell Emacs where to
109 find the files. For example, add</p></div>
110 <div class="listingblock">
111 <div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nv">add-to-list</span> <span class="ss">&#39;load-path</span> <span class="p">(</span><span class="nv">file-truename</span> <span class="s">&quot;path-to-the-el-files&quot;</span><span class="p">))</span>
112 </pre></div></div></div>
113 <div class="paragraph"><p>to your <span class="monospaced">~/.emacs</span> or <span class="monospaced">~/.xemacs/init.el</span>. You&#8217;ll probably
114 also want to start <span class="monospaced">def-use-mode</span> automatically by adding</p></div>
115 <div class="listingblock">
116 <div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nb">require</span> <span class="ss">&#39;esml-du-mlton</span><span class="p">)</span>
117 <span class="p">(</span><span class="nv">def-use-mode</span><span class="p">)</span>
118 </pre></div></div></div>
119 <div class="paragraph"><p>to your Emacs init file. Once the def-use mode is activated, you
120 should see the <span class="monospaced">DU</span> indicator on the mode line.</p></div>
121 </div>
122 </div>
123 <div class="sect1">
124 <h2 id="_usage">Usage</h2>
125 <div class="sectionbody">
126 <div class="paragraph"><p>To use def-use mode one typically first sets up the program&#8217;s makefile
127 or build script so that the def-use information is saved each time the
128 program is compiled. In addition to the <span class="monospaced">-show-def-use <em>file</em></span>
129 option, the <span class="monospaced">-prefer-abs-paths true</span> expert option is required.
130 Note that the time it takes to save the information is small (compared
131 to type-checking), so it is recommended to simply add the options to
132 the MLton invocation that compiles the program. However, it is only
133 necessary to type check the program (or library), so one can specify
134 the <span class="monospaced">-stop tc</span> option. For example, suppose you have a program
135 defined by an MLB file named <span class="monospaced">my-prg.mlb</span>, you can save the def-use
136 information to the file <span class="monospaced">my-prg.du</span> by invoking MLton as:</p></div>
137 <div class="listingblock">
138 <div class="content monospaced">
139 <pre>mlton -prefer-abs-paths true -show-def-use my-prg.du -stop tc my-prg.mlb</pre>
140 </div></div>
141 <div class="paragraph"><p>Finally, one needs to tell the mode where to find the def-use
142 information. This is done with the <span class="monospaced">esml-du-mlton</span> command. For
143 example, to load the <span class="monospaced">my-prg.du</span> file, one would type:</p></div>
144 <div class="listingblock">
145 <div class="content monospaced">
146 <pre>M-x esml-du-mlton my-prg.du</pre>
147 </div></div>
148 <div class="paragraph"><p>After doing all of the above, find an SML file covered by the
149 previously saved and loaded def-use information, and place the cursor
150 at some variable (definition or use, it doesn&#8217;t matter). You should
151 see the variable being highlighted. (Note that specifications in
152 signatures do not define variables.)</p></div>
153 <div class="paragraph"><p>You might also want to setup and use the
154 <a href="EmacsBgBuildMode">Bg-Build mode</a> to start builds automatically.</p></div>
155 </div>
156 </div>
157 <div class="sect1">
158 <h2 id="_types">Types</h2>
159 <div class="sectionbody">
160 <div class="paragraph"><p><span class="monospaced">-show-def-use</span> output was extended to include types of variable
161 definitions in revision <a href="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6333"><span class="monospaced">r6333</span></a>. To get good type names, the
162 types must be in scope at the end of the program. If you are using the
163 <a href="MLBasis">ML Basis</a> system, this means that the root MLB-file for your
164 application should not wrap the libraries used in the application inside
165 <span class="monospaced">local ... in ... end</span>, because that would remove them from the scope before
166 the end of the program.</p></div>
167 </div>
168 </div>
169 </div>
170 <div id="footnotes"><hr></div>
171 <div id="footer">
172 <div id="footer-text">
173 </div>
174 <div id="footer-badges">
175 </div>
176 </div>
177 </body>
178 </html>