Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / EmacsBgBuildMode
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>EmacsBgBuildMode</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>EmacsBgBuildMode</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p>Do you really want to think about starting a build of you project?
32 What if you had a personal slave that would restart a build of your
33 project whenever you save any file belonging to that project? The
34 bg-build mode does just that. Just save the file, a compile is
35 started (silently!), you can continue working without even thinking
36 about starting a build, and if there are errors, you are notified
37 (with a message), and can then jump to errors.</p></div>
38 <div class="paragraph"><p>This mode is not specific to MLton per se, but is particularly useful
39 for working with MLton due to the longer compile times. By the time
40 you start wondering about possible errors, the build is already on the
41 way.</p></div>
42 </div>
43 </div>
44 <div class="sect1">
45 <h2 id="_functionality_and_features">Functionality and Features</h2>
46 <div class="sectionbody">
47 <div class="ulist"><ul>
48 <li>
49 <p>
50 Each time a file is saved, and after a user configurable delay
51 period has been exhausted, a build is started silently in the
52 background.
53 </p>
54 </li>
55 <li>
56 <p>
57 When the build is finished, a status indicator (message) is
58 displayed non-intrusively.
59 </p>
60 </li>
61 <li>
62 <p>
63 At any time, you can switch to a build process buffer where all the
64 messages from the build are shown.
65 </p>
66 </li>
67 <li>
68 <p>
69 Optionally highlights (error/warning) message locations in (source
70 code) buffers after a finished build.
71 </p>
72 </li>
73 <li>
74 <p>
75 After a build has finished, you can jump to locations of warnings
76 and errors from the build process buffer or by using the <span class="monospaced">first-error</span>
77 and <span class="monospaced">next-error</span> commands.
78 </p>
79 </li>
80 <li>
81 <p>
82 When a build fails, bg-build mode can optionally execute a user
83 specified command. By default, bg-build mode executes <span class="monospaced">first-error</span>.
84 </p>
85 </li>
86 <li>
87 <p>
88 When starting a build of a particular project, a possible previous
89 live build of the same project is interrupted first.
90 </p>
91 </li>
92 <li>
93 <p>
94 A project configuration file specifies the commands required to
95 build a project.
96 </p>
97 </li>
98 <li>
99 <p>
100 Multiple projects can be loaded into bg-build mode and bg-build mode
101 can build a given maximum number of projects concurrently.
102 </p>
103 </li>
104 <li>
105 <p>
106 Supports both <a href="http://www.gnu.org/software/emacs/">Gnu Emacs</a> and
107 <a href="http://www.xemacs.org">XEmacs</a>.
108 </p>
109 </li>
110 </ul></div>
111 </div>
112 </div>
113 <div class="sect1">
114 <h2 id="_download">Download</h2>
115 <div class="sectionbody">
116 <div class="paragraph"><p>There is no package for the mode at the moment. To install the mode you
117 need to fetch the Emacs Lisp, <span class="monospaced">*.el</span>, files from the MLton repository:
118 <a href="https://github.com/MLton/mlton/tree/master/ide/emacs"><span class="monospaced">emacs</span></a>.</p></div>
119 </div>
120 </div>
121 <div class="sect1">
122 <h2 id="_setup">Setup</h2>
123 <div class="sectionbody">
124 <div class="paragraph"><p>The easiest way to load the mode is to first tell Emacs where to find the
125 files. For example, add</p></div>
126 <div class="listingblock">
127 <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>
128 </pre></div></div></div>
129 <div class="paragraph"><p>to your <span class="monospaced">~/.emacs</span> or <span class="monospaced">~/.xemacs/init.el</span>. You&#8217;ll probably also want
130 to start the mode automatically by adding</p></div>
131 <div class="listingblock">
132 <div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nb">require</span> <span class="ss">&#39;bg-build-mode</span><span class="p">)</span>
133 <span class="p">(</span><span class="nv">bg-build-mode</span><span class="p">)</span>
134 </pre></div></div></div>
135 <div class="paragraph"><p>to your Emacs init file. Once the mode is activated, you should see
136 the <span class="monospaced">BGB</span> indicator on the mode line.</p></div>
137 <div class="sect2">
138 <h3 id="_mlton_and_compilation_mode">MLton and Compilation-Mode</h3>
139 <div class="paragraph"><p>At the time of writing, neither Gnu Emacs nor XEmacs contain an error
140 regexp that would match MLton&#8217;s messages.</p></div>
141 <div class="paragraph"><p>If you use Gnu Emacs, insert the following code into your <span class="monospaced">.emacs</span> file:</p></div>
142 <div class="listingblock">
143 <div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nb">require</span> <span class="ss">&#39;compile</span><span class="p">)</span>
144 <span class="p">(</span><span class="nv">add-to-list</span>
145 <span class="ss">&#39;compilation-error-regexp-alist</span>
146 <span class="o">&#39;</span><span class="p">(</span><span class="s">&quot;^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$&quot;</span>
147 <span class="mi">2</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">))</span>
148 </pre></div></div></div>
149 <div class="paragraph"><p>If you use XEmacs, insert the following code into your <span class="monospaced">init.el</span> file:</p></div>
150 <div class="listingblock">
151 <div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nb">require</span> <span class="ss">&#39;compile</span><span class="p">)</span>
152 <span class="p">(</span><span class="nv">add-to-list</span>
153 <span class="ss">&#39;compilation-error-regexp-alist-alist</span>
154 <span class="o">&#39;</span><span class="p">(</span><span class="nv">mlton</span>
155 <span class="p">(</span><span class="s">&quot;^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$&quot;</span>
156 <span class="mi">2</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">)))</span>
157 <span class="p">(</span><span class="nv">compilation-build-compilation-error-regexp-alist</span><span class="p">)</span>
158 </pre></div></div></div>
159 </div>
160 </div>
161 </div>
162 <div class="sect1">
163 <h2 id="_usage">Usage</h2>
164 <div class="sectionbody">
165 <div class="paragraph"><p>Typically projects are built (or compiled) using a tool like <a href="http://www.gnu.org/software/make/"><span class="monospaced">make</span></a>,
166 but the details vary. The bg-build mode needs a project configuration file to
167 know how to build your project. A project configuration file basically contains
168 an Emacs Lisp expression calling a function named <span class="monospaced">bg-build</span> that returns a
169 project object. A simple example of a project configuration file would be the
170 (<a href="https://github.com/MLton/mltonlib/blob/master/com/ssh/async/unstable/example/smlbot/Build.bgb"><span class="monospaced">Build.bgb</span></a>)
171 file used with smlbot:</p></div>
172 <div class="listingblock">
173 <div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nv">bg-build</span>
174 <span class="ss">:name</span> <span class="s">&quot;SML-Bot&quot;</span>
175 <span class="ss">:shell</span> <span class="s">&quot;nice -n5 make all&quot;</span><span class="p">)</span>
176 </pre></div></div></div>
177 <div class="paragraph"><p>The <span class="monospaced">bg-build</span> function takes a number of keyword arguments:</p></div>
178 <div class="ulist"><ul>
179 <li>
180 <p>
181 <span class="monospaced">:name</span> specifies the name of the project. This can be any
182 expression that evaluates to a string or to a nullary function that
183 returns a string.
184 </p>
185 </li>
186 <li>
187 <p>
188 <span class="monospaced">:shell</span> specifies a shell command to execute. This can be any
189 expression that evaluates to a string, a list of strings, or to a
190 nullary function returning a list of strings.
191 </p>
192 </li>
193 <li>
194 <p>
195 <span class="monospaced">:build?</span> specifies a predicate to determine whether the project
196 should be built after some files have been modified. The predicate is
197 given a list of filenames and should return a non-nil value when the
198 project should be built and nil otherwise.
199 </p>
200 </li>
201 </ul></div>
202 <div class="paragraph"><p>All of the keyword arguments, except <span class="monospaced">:shell</span>, are optional and can be left out.</p></div>
203 <div class="paragraph"><p>Note the use of the <span class="monospaced">nice</span> command above. It means that background
204 build process is given a lower priority by the system process
205 scheduler. Assuming your machine has enough memory, using nice
206 ensures that your computer remains responsive. (You probably won&#8217;t
207 even notice when a build is started.)</p></div>
208 <div class="paragraph"><p>Once you have written a project file for bg-build mode. Use the
209 <span class="monospaced">bg-build-add-project</span> command to load the project file for bg-build
210 mode. The bg-build mode can also optionally load recent project files
211 automatically at startup.</p></div>
212 <div class="paragraph"><p>After the project file has been loaded and bg-build mode activated,
213 each time you save a file in Emacs, the bg-build mode tries to build
214 your project.</p></div>
215 <div class="paragraph"><p>The <span class="monospaced">bg-build-status</span> command creates a buffer that displays some
216 status information on builds and allows you to manage projects (start
217 builds explicitly, remove a project from bg-build, &#8230;) as well as
218 visit buffers created by bg-build. Notice the count of started
219 builds. At the end of the day it can be in the hundreds or thousands.
220 Imagine the number of times you&#8217;ve been relieved of starting a build
221 explicitly!</p></div>
222 </div>
223 </div>
224 </div>
225 <div id="footnotes"><hr></div>
226 <div id="footer">
227 <div id="footer-text">
228 </div>
229 <div id="footer-badges">
230 </div>
231 </div>
232 </body>
233 </html>