File: EmacsBgBuildMode

package info (click to toggle)
mlton 20130715-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 60,900 kB
  • ctags: 69,386
  • sloc: xml: 34,418; ansic: 17,399; lisp: 2,879; makefile: 1,605; sh: 1,254; pascal: 256; python: 143; asm: 97
file content (233 lines) | stat: -rw-r--r-- 10,607 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>EmacsBgBuildMode</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>EmacsBgBuildMode</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>Do you really want to think about starting a build of you project?
What if you had a personal slave that would restart a build of your
project whenever you save any file belonging to that project?  The
bg-build mode does just that.  Just save the file, a compile is
started (silently!), you can continue working without even thinking
about starting a build, and if there are errors, you are notified
(with a message), and can then jump to errors.</p></div>
<div class="paragraph"><p>This mode is not specific to MLton per se, but is particularly useful
for working with MLton due to the longer compile times.  By the time
you start wondering about possible errors, the build is already on the
way.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_functionality_and_features">Functionality and Features</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
Each time a file is saved, and after a user configurable delay
period has been exhausted, a build is started silently in the
background.
</p>
</li>
<li>
<p>
When the build is finished, a status indicator (message) is
displayed non-intrusively.
</p>
</li>
<li>
<p>
At any time, you can switch to a build process buffer where all the
messages from the build are shown.
</p>
</li>
<li>
<p>
Optionally highlights (error/warning) message locations in (source
code) buffers after a finished build.
</p>
</li>
<li>
<p>
After a build has finished, you can jump to locations of warnings
and errors from the build process buffer or by using the <span class="monospaced">first-error</span>
and <span class="monospaced">next-error</span> commands.
</p>
</li>
<li>
<p>
When a build fails, bg-build mode can optionally execute a user
specified command.  By default, bg-build mode executes <span class="monospaced">first-error</span>.
</p>
</li>
<li>
<p>
When starting a build of a particular project, a possible previous
live build of the same project is interrupted first.
</p>
</li>
<li>
<p>
A project configuration file specifies the commands required to
build a project.
</p>
</li>
<li>
<p>
Multiple projects can be loaded into bg-build mode and bg-build mode
can build a given maximum number of projects concurrently.
</p>
</li>
<li>
<p>
Supports both <a href="http://www.gnu.org/software/emacs/">Gnu Emacs</a> and
<a href="http://www.xemacs.org">XEmacs</a>.
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_download">Download</h2>
<div class="sectionbody">
<div class="paragraph"><p>There is no package for the mode at the moment.  To install the mode you
need to fetch the Emacs Lisp, <span class="monospaced">*.el</span>, files from the MLton repository:
<a href="https://github.com/MLton/mlton/tree/master/ide/emacs"><span class="monospaced">emacs</span></a>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_setup">Setup</h2>
<div class="sectionbody">
<div class="paragraph"><p>The easiest way to load the mode is to first tell Emacs where to find the
files.  For example, add</p></div>
<div class="listingblock">
<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>
</pre></div></div></div>
<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
to start the mode automatically by adding</p></div>
<div class="listingblock">
<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>
<span class="p">(</span><span class="nv">bg-build-mode</span><span class="p">)</span>
</pre></div></div></div>
<div class="paragraph"><p>to your Emacs init file.  Once the mode is activated, you should see
the <span class="monospaced">BGB</span> indicator on the mode line.</p></div>
<div class="sect2">
<h3 id="_mlton_and_compilation_mode">MLton and Compilation-Mode</h3>
<div class="paragraph"><p>At the time of writing, neither Gnu Emacs nor XEmacs contain an error
regexp that would match MLton&#8217;s messages.</p></div>
<div class="paragraph"><p>If you use Gnu Emacs, insert the following code into your <span class="monospaced">.emacs</span> file:</p></div>
<div class="listingblock">
<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>
<span class="p">(</span><span class="nv">add-to-list</span>
 <span class="ss">&#39;compilation-error-regexp-alist</span>
 <span class="o">&#39;</span><span class="p">(</span><span class="s">&quot;^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$&quot;</span>
   <span class="mi">2</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">))</span>
</pre></div></div></div>
<div class="paragraph"><p>If you use XEmacs, insert the following code into your <span class="monospaced">init.el</span> file:</p></div>
<div class="listingblock">
<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>
<span class="p">(</span><span class="nv">add-to-list</span>
 <span class="ss">&#39;compilation-error-regexp-alist-alist</span>
 <span class="o">&#39;</span><span class="p">(</span><span class="nv">mlton</span>
   <span class="p">(</span><span class="s">&quot;^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$&quot;</span>
    <span class="mi">2</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">)))</span>
<span class="p">(</span><span class="nv">compilation-build-compilation-error-regexp-alist</span><span class="p">)</span>
</pre></div></div></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_usage">Usage</h2>
<div class="sectionbody">
<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>,
but the details vary.  The bg-build mode needs a project configuration file to
know how to build your project.  A project configuration file basically contains
an Emacs Lisp expression calling a function named <span class="monospaced">bg-build</span> that returns a
project object.  A simple example of a project configuration file would be the
(<a href="https://github.com/MLton/mltonlib/blob/master/com/ssh/async/unstable/example/smlbot/Build.bgb"><span class="monospaced">Build.bgb</span></a>)
file used with smlbot:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="nv">bg-build</span>
 <span class="ss">:name</span>  <span class="s">&quot;SML-Bot&quot;</span>
 <span class="ss">:shell</span> <span class="s">&quot;nice -n5 make all&quot;</span><span class="p">)</span>
</pre></div></div></div>
<div class="paragraph"><p>The <span class="monospaced">bg-build</span> function takes a number of keyword arguments:</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">:name</span> specifies the name of the project.  This can be any
expression that evaluates to a string or to a nullary function that
returns a string.
</p>
</li>
<li>
<p>
<span class="monospaced">:shell</span> specifies a shell command to execute.  This can be any
expression that evaluates to a string, a list of strings, or to a
nullary function returning a list of strings.
</p>
</li>
<li>
<p>
<span class="monospaced">:build?</span> specifies a predicate to determine whether the project
should be built after some files have been modified.  The predicate is
given a list of filenames and should return a non-nil value when the
project should be built and nil otherwise.
</p>
</li>
</ul></div>
<div class="paragraph"><p>All of the keyword arguments, except <span class="monospaced">:shell</span>, are optional and can be left out.</p></div>
<div class="paragraph"><p>Note the use of the <span class="monospaced">nice</span> command above.  It means that background
build process is given a lower priority by the system process
scheduler.  Assuming your machine has enough memory, using nice
ensures that your computer remains responsive.  (You probably won&#8217;t
even notice when a build is started.)</p></div>
<div class="paragraph"><p>Once you have written a project file for bg-build mode.  Use the
<span class="monospaced">bg-build-add-project</span> command to load the project file for bg-build
mode.  The bg-build mode can also optionally load recent project files
automatically at startup.</p></div>
<div class="paragraph"><p>After the project file has been loaded and bg-build mode activated,
each time you save a file in Emacs, the bg-build mode tries to build
your project.</p></div>
<div class="paragraph"><p>The <span class="monospaced">bg-build-status</span> command creates a buffer that displays some
status information on builds and allows you to manage projects (start
builds explicitly, remove a project from bg-build, &#8230;) as well as
visit buffers created by bg-build.  Notice the count of started
builds.  At the end of the day it can be in the hundreds or thousands.
Imagine the number of times you&#8217;ve been relieved of starting a build
explicitly!</p></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>