<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">



<title>EmacsBgBuildMode - MLton Standard ML Compiler (SML Compiler)</title>
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="all" href="common.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="print" href="print.css">


<link rel="Start" href="Home">


</head>

<body lang="en" dir="ltr">

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-833377-1";
urchinTracker();
</script>
<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
  <tr>
    <td style = "
		border: 0px;
		color: darkblue; 
		font-size: 150%;
		text-align: left;">
      <a class = mltona href="Home">MLton MLTONWIKIVERSION</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      EmacsBgBuildMode
    <td style = "
		border: 0px;
		text-align: right;">
      <table cellspacing = 0 style = "border: 0px">
        <tr style = "vertical-align: middle;">
      </table>
  <tr style = "background-color: white;">
    <td colspan = 3
	style = "
		border: 0px;
		font-size:70%;
		text-align: right;">
      <a href = "Home">Home</a>
      &nbsp;<a href = "Index">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">
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>
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>
<h3 id="head-f43ab5658e2e88669c0e231c0c31ef466c4c6dc2">Functionality and Features</h3>

    <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>
 After a build has finished, you can jump to locations of warnings and  errors from the build process buffer or by using the <tt>first-error</tt> and  <tt>next-error</tt> 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 <tt>first-error</tt>. 
</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 class="external" href="http://www.gnu.org/software/emacs/"><img src="moin-www.png" alt="[WWW]" height="11" width="11">Gnu Emacs</a> and  <a class="external" href="http://www.xemacs.org"><img src="moin-www.png" alt="[WWW]" height="11" width="11">XEmacs</a>. 
</p>
</li>

    </ul>


<h3 id="head-a479c9c34e878d07b4d67a73a48f432ad7dc53c8">Download</h3>
<p>
There is no package for the mode at the moment.  To install the mode you need to fetch the Emacs lisp, <tt>*.el</tt>, files from the MLton repository: <a class="external" href="http://mlton.org/cgi-bin/viewsvn.cgi/mlton/trunk/ide/emacs/"><img src="moin-www.png" alt="[WWW]" height="11" width="11">emacs</a>. 
</p>
<h3 id="head-cdd7bb2816b7a8f88bce0e47be39943bc369516b">Setup</h3>
<p>
The easiest way to load the mode is to first tell Emacs where to find the files.  For example, add 
</p>

            <ul>

   
<pre class=code>
(add-to-list 'load-path (file-truename <B><FONT COLOR="#BC8F8F">&quot;path-to-the-el-files&quot;</FONT></B>))
</PRE>
<p>
 
</p>

            </ul>


<p>
to your <tt>~/.emacs</tt> or <tt>~/.xemacs/init.el</tt>.  You'll probably also want to start the mode automatically by adding 
</p>

            <ul>

   
<pre class=code>
(require 'bg-build-mode)
(bg-build-mode)
</PRE>
<p>
 
</p>

            </ul>


<p>
to your Emacs init file.  Once the mode is activated, you should see the <tt>BGB</tt> indicator on the mode line. 
</p>
<h4 id="head-d2e4cb08e10e25decb4889c2548e69aa63efaf40">MLton and Compilation-Mode</h4>
<p>
At the time of writing, neither Gnu Emacs nor XEmacs contain an error regexp that would match MLton's messages. 
</p>
<p>
If you use Gnu Emacs, insert the following code into your <tt>.emacs</tt> file: 
</p>

            <ul>

   
<pre class=code>
(require 'compile)
(add-to-list
 'compilation-error-regexp-alist
 '(<B><FONT COLOR="#BC8F8F">&quot;^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$&quot;</FONT></B>
   2 3 4))
</PRE>
<p>
 
</p>

            </ul>


<p>
If you use XEmacs, insert the following code into your <tt>init.el</tt> file: 
</p>

            <ul>

   
<pre class=code>
(require 'compile)
(add-to-list
 'compilation-error-regexp-alist-alist
 '(mlton
   (<B><FONT COLOR="#BC8F8F">&quot;^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$&quot;</FONT></B>
    2 3 4)))
(compilation-build-compilation-error-regexp-alist)
</PRE>
<p>
 
</p>

            </ul>


<h3 id="head-0bb18642b70b9f8a9c12ccf39487328f306b8e19">Usage</h3>
<p>
Typically projects are built (or compiled) using a tool like <a class="external" href="http://www.gnu.org/software/make/"><img src="moin-www.png" alt="[WWW]" height="11" width="11">make</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 <tt>bg-build</tt> that returns a project object.  A simple example of a project configuration file would be the (<a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mltonlib/trunk/com/ssh/async/unstable/example/smlbot/Build.bgb?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">Build.bgb</a>) file used with smlbot: 
</p>

        <ul>

  <pre class=code>(bg-build
 <B><FONT COLOR="#5F9EA0">:name</FONT></B>  <B><FONT COLOR="#BC8F8F">&quot;SML-Bot&quot;</FONT></B>
 <B><FONT COLOR="#5F9EA0">:shell</FONT></B> <B><FONT COLOR="#BC8F8F">&quot;nice -n5 make all&quot;</FONT></B>)
</PRE>
 
        </ul>


<p>
The <tt>bg-build</tt> function takes a number of keyword arguments: 
</p>

    <ul>

    <li>
<p>
 <tt>:name</tt> 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>
 <tt>:shell</tt> 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>
 <tt>:build?</tt> 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>


<p>
All of the keyword arguments, except <tt>:shell</tt>, are optional and can be left out. 
</p>
<p>
Note the use of the <tt>nice</tt> 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't even notice when a build is started.) 
</p>
<p>
Once you have written a project file for bg-build mode.  Use the <tt>bg-build-add-project</tt> 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>
<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>
<p>
The <tt>bg-build-status</tt> 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, ...) 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've been relieved of starting a build explicitly! 
</p>
</div>



<p>
<hr>
Last edited on 2007-07-07 04:01:31 by <span title="cs27019070.pp.htv.fi"><a href="VesaKarvonen">VesaKarvonen</a></span>.
</body></html>
