| 1 |
= EmacsBgBuildMode |
| 2 |
|
| 3 |
Do you really want to think about starting a build of you project? |
| 4 |
What if you had a personal slave that would restart a build of your |
| 5 |
project whenever you save any file belonging to that project? The |
| 6 |
bg-build mode does just that. Just save the file, a compile is |
| 7 |
started (silently!), you can continue working without even thinking |
| 8 |
about starting a build, and if there are errors, you are notified |
| 9 |
(with a message), and can then jump to errors. |
| 10 |
|
| 11 |
This mode is not specific to MLton per se, but is particularly useful |
| 12 |
for working with MLton due to the longer compile times. By the time |
| 13 |
you start wondering about possible errors, the build is already on the |
| 14 |
way. |
| 15 |
|
| 16 |
== Functionality and Features |
| 17 |
|
| 18 |
* Each time a file is saved, and after a user configurable delay |
| 19 |
period has been exhausted, a build is started silently in the |
| 20 |
background. |
| 21 |
* When the build is finished, a status indicator (message) is |
| 22 |
displayed non-intrusively. |
| 23 |
* At any time, you can switch to a build process buffer where all the |
| 24 |
messages from the build are shown. |
| 25 |
* Optionally highlights (error/warning) message locations in (source |
| 26 |
code) buffers after a finished build. |
| 27 |
* After a build has finished, you can jump to locations of warnings |
| 28 |
and errors from the build process buffer or by using the `first-error` |
| 29 |
and `next-error` commands. |
| 30 |
* When a build fails, bg-build mode can optionally execute a user |
| 31 |
specified command. By default, bg-build mode executes `first-error`. |
| 32 |
* When starting a build of a particular project, a possible previous |
| 33 |
live build of the same project is interrupted first. |
| 34 |
* A project configuration file specifies the commands required to |
| 35 |
build a project. |
| 36 |
* Multiple projects can be loaded into bg-build mode and bg-build mode |
| 37 |
can build a given maximum number of projects concurrently. |
| 38 |
* Supports both http://www.gnu.org/software/emacs/[Gnu Emacs] and |
| 39 |
http://www.xemacs.org[XEmacs]. |
| 40 |
|
| 41 |
|
| 42 |
== Download |
| 43 |
|
| 44 |
There is no package for the mode at the moment. To install the mode you |
| 45 |
need to fetch the Emacs Lisp, `*.el`, files from the MLton repository: |
| 46 |
https://github.com/MLton/mlton/tree/master/ide/emacs[`emacs`]. |
| 47 |
|
| 48 |
|
| 49 |
== Setup |
| 50 |
|
| 51 |
The easiest way to load the mode is to first tell Emacs where to find the |
| 52 |
files. For example, add |
| 53 |
|
| 54 |
[source,cl] |
| 55 |
---- |
| 56 |
(add-to-list 'load-path (file-truename "path-to-the-el-files")) |
| 57 |
---- |
| 58 |
|
| 59 |
to your `~/.emacs` or `~/.xemacs/init.el`. You'll probably also want |
| 60 |
to start the mode automatically by adding |
| 61 |
|
| 62 |
[source,cl] |
| 63 |
---- |
| 64 |
(require 'bg-build-mode) |
| 65 |
(bg-build-mode) |
| 66 |
---- |
| 67 |
|
| 68 |
to your Emacs init file. Once the mode is activated, you should see |
| 69 |
the `BGB` indicator on the mode line. |
| 70 |
|
| 71 |
|
| 72 |
=== MLton and Compilation-Mode |
| 73 |
|
| 74 |
At the time of writing, neither Gnu Emacs nor XEmacs contain an error |
| 75 |
regexp that would match MLton's messages. |
| 76 |
|
| 77 |
If you use Gnu Emacs, insert the following code into your `.emacs` file: |
| 78 |
|
| 79 |
[source,cl] |
| 80 |
---- |
| 81 |
(require 'compile) |
| 82 |
(add-to-list |
| 83 |
'compilation-error-regexp-alist |
| 84 |
'("^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$" |
| 85 |
2 3 4)) |
| 86 |
---- |
| 87 |
|
| 88 |
If you use XEmacs, insert the following code into your `init.el` file: |
| 89 |
|
| 90 |
[source,cl] |
| 91 |
---- |
| 92 |
(require 'compile) |
| 93 |
(add-to-list |
| 94 |
'compilation-error-regexp-alist-alist |
| 95 |
'(mlton |
| 96 |
("^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$" |
| 97 |
2 3 4))) |
| 98 |
(compilation-build-compilation-error-regexp-alist) |
| 99 |
---- |
| 100 |
|
| 101 |
== Usage |
| 102 |
|
| 103 |
Typically projects are built (or compiled) using a tool like http://www.gnu.org/software/make/[`make`], |
| 104 |
but the details vary. The bg-build mode needs a project configuration file to |
| 105 |
know how to build your project. A project configuration file basically contains |
| 106 |
an Emacs Lisp expression calling a function named `bg-build` that returns a |
| 107 |
project object. A simple example of a project configuration file would be the |
| 108 |
(https://github.com/MLton/mltonlib/blob/master/com/ssh/async/unstable/example/smlbot/Build.bgb[`Build.bgb`]) |
| 109 |
file used with smlbot: |
| 110 |
|
| 111 |
[source,cl] |
| 112 |
---- |
| 113 |
include::https://raw.github.com/MLton/mltonlib/master/com/ssh/async/unstable/example/smlbot/Build.bgb[indent=0,lines=5..-1] |
| 114 |
---- |
| 115 |
|
| 116 |
The `bg-build` function takes a number of keyword arguments: |
| 117 |
|
| 118 |
* `:name` specifies the name of the project. This can be any |
| 119 |
expression that evaluates to a string or to a nullary function that |
| 120 |
returns a string. |
| 121 |
|
| 122 |
* `:shell` specifies a shell command to execute. This can be any |
| 123 |
expression that evaluates to a string, a list of strings, or to a |
| 124 |
nullary function returning a list of strings. |
| 125 |
|
| 126 |
* `:build?` specifies a predicate to determine whether the project |
| 127 |
should be built after some files have been modified. The predicate is |
| 128 |
given a list of filenames and should return a non-nil value when the |
| 129 |
project should be built and nil otherwise. |
| 130 |
|
| 131 |
All of the keyword arguments, except `:shell`, are optional and can be left out. |
| 132 |
|
| 133 |
Note the use of the `nice` command above. It means that background |
| 134 |
build process is given a lower priority by the system process |
| 135 |
scheduler. Assuming your machine has enough memory, using nice |
| 136 |
ensures that your computer remains responsive. (You probably won't |
| 137 |
even notice when a build is started.) |
| 138 |
|
| 139 |
Once you have written a project file for bg-build mode. Use the |
| 140 |
`bg-build-add-project` command to load the project file for bg-build |
| 141 |
mode. The bg-build mode can also optionally load recent project files |
| 142 |
automatically at startup. |
| 143 |
|
| 144 |
After the project file has been loaded and bg-build mode activated, |
| 145 |
each time you save a file in Emacs, the bg-build mode tries to build |
| 146 |
your project. |
| 147 |
|
| 148 |
The `bg-build-status` command creates a buffer that displays some |
| 149 |
status information on builds and allows you to manage projects (start |
| 150 |
builds explicitly, remove a project from bg-build, ...) as well as |
| 151 |
visit buffers created by bg-build. Notice the count of started |
| 152 |
builds. At the end of the day it can be in the hundreds or thousands. |
| 153 |
Imagine the number of times you've been relieved of starting a build |
| 154 |
explicitly! |