<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>So I decided to take my work back underground &#187; Emacs</title>
	<atom:link href="http://gaiustech.wordpress.com/category/emacs/feed/" rel="self" type="application/rss+xml" />
	<link>http://gaiustech.wordpress.com</link>
	<description>To stop it falling into the wrong hands</description>
	<lastBuildDate>Sat, 13 Apr 2013 19:41:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gaiustech.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/0a1f076fa7fc2f9e2944ef7437e6a709?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>So I decided to take my work back underground &#187; Emacs</title>
		<link>http://gaiustech.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gaiustech.wordpress.com/osd.xml" title="So I decided to take my work back underground" />
	<atom:link rel='hub' href='http://gaiustech.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Segmentation Faults, TAP and Eclipse</title>
		<link>http://gaiustech.wordpress.com/2011/09/09/segmentation-faults-tap-and-eclipse/</link>
		<comments>http://gaiustech.wordpress.com/2011/09/09/segmentation-faults-tap-and-eclipse/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 11:14:41 +0000</pubDate>
		<dc:creator>Gaius</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ocaml]]></category>
		<category><![CDATA[Operation Foothold]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[seg fault]]></category>
		<category><![CDATA[sigsegv]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://gaiustech.wordpress.com/?p=1717</guid>
		<description><![CDATA[This is quite a neat trick. Consider: Referencing that NULL pointer obviously crashes straight away with a terse segmentation fault: By simply linking it with libSegFault, which seems to be documented only very informally, but comes with glibc: Of course &#8230; <a href="http://gaiustech.wordpress.com/2011/09/09/segmentation-faults-tap-and-eclipse/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=1717&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is quite a neat trick. Consider:</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;cstdlib&gt;

int main(int argc, char** argv) {
  int* ptr = NULL;
  *ptr = 1;

  exit(EXIT_SUCCESS);
}
</pre>
<p>Referencing that <code>NULL</code> pointer obviously crashes straight away with a terse <a href="http://en.wikipedia.org/wiki/Segmentation_fault">segmentation fault</a>:</p>
<p><a href="http://gaiustech.files.wordpress.com/2011/09/segfault1.png"><img src="http://gaiustech.files.wordpress.com/2011/09/segfault1.png?w=640" alt="" title="segfault1"   class="aligncenter size-full wp-image-1719" /></a><br />
By simply linking it with <code>libSegFault</code>, which seems to be documented only <a href="http://www.cygwin.com/ml/gdb/2007-06/msg00345.html">very informally</a>, but comes with <a href="http://www.gnu.org/s/libc/">glibc</a>:</p>
<p><a href="http://gaiustech.files.wordpress.com/2011/09/segfault2.png"><img src="http://gaiustech.files.wordpress.com/2011/09/segfault2.png?w=640" alt="" title="segfault2"   class="aligncenter size-full wp-image-1720" /></a><br />
Of course you could get all this by starting the program with <a href="http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_42.html">gdb</a> but this looks like a great technique for diagnosing crashes &#8220;in the wild&#8221;. Not that my code segfaults all the time, mind! After writing this, I found some more details on <a href="http://stackoverflow.com/q/77005/447514">Stack Overflow</a>, including a good tip about <code>c++filt</code>. Another useful utility is <code><a href="http://linux.die.net/man/1/addr2line">addr2line</a></code>.</p>
<p>Also I am starting to incorporate <code><a href="http://testanything.org/wiki/index.php/Testing_with_C%2B%2B#Testing_using_libtap.2B.2B">libtap++</a></code>, an implementation of the <a href="http://testanything.org/wiki/index.php/TAP_at_IETF:_Draft_Standard#Introduction">Test Anything Protocol</a>, into my projects. C++ has <a href="http://c2.com/cgi/wiki?StronglyTyped">strong typing</a>, at least stronger than plain C, which helps <a href="http://gaiustech.wordpress.com/2011/04/25/and-while-im-on-the-subject/">trap errors at compile time</a> like in OCaml. But since I always write a test harness anyway, it makes sense to fall into line with the way everyone else does it, especially as I have ambitions for wider adoption of my bindings&dagger;. <s>Presently there is <a href="http://testanything.org/wiki/index.php/TAP_Producers">no TAP producer for OCaml</a></s>&Dagger;, so at some point I will work on that too (or just bind to <a href="https://github.com/zorgnax/libtap">the C libtap</a>).</p>
<p>On the recommendation of a friend of mine who is a very experienced C++ programmer, I have been playing with <a href="http://www.eclipse.org/cdt/">Eclipse CDT</a>, which is pretty nice for C/C++ but doesn&#8217;t deal well at all with mixed C++/OCaml projects, and <a href="http://eclipsefp.github.com">EclipseFP</a> seems to have dropped support for OCaml at some point. I think I&#8217;ll try using it for just the <code>.so</code> portion of my projects and stick with Emacs/<code>make</code> for final integration with OCaml bindings, at least until I see if it really is more productive to do C++ in a full-blown <a href="http://en.wikipedia.org/wiki/Integrated_development_environment">IDE</a> versus good old <a href="http://www.gnu.org/software/emacs/tour/">Emacs</a>. Also I&#8217;ve bought a copy of <i><a href="http://www.amazon.co.uk/Boost-C-Libraries-Boris-Schaling/dp/0982219199/ref=sr_1_5?s=books&amp;ie=UTF8&amp;qid=1315564879&amp;sr=1-5">The Boost C++ Libraries</a></i>, again on the recommendation of my friend, that whatever I want, it&#8217;s probably already in <a href="http://www.boost.org/">Boost</a>. </p>
<p><font size="1">&dagger; OPERATION FOOTHOLD<br />
&Dagger; See comments</font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gaiustech.wordpress.com/1717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gaiustech.wordpress.com/1717/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=1717&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gaiustech.wordpress.com/2011/09/09/segmentation-faults-tap-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ced82e97b7a13f79da0aaaca2302cd45?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gaiush</media:title>
		</media:content>

		<media:content url="http://gaiustech.files.wordpress.com/2011/09/segfault1.png" medium="image">
			<media:title type="html">segfault1</media:title>
		</media:content>

		<media:content url="http://gaiustech.files.wordpress.com/2011/09/segfault2.png" medium="image">
			<media:title type="html">segfault2</media:title>
		</media:content>
	</item>
		<item>
		<title>Komodo 6</title>
		<link>http://gaiustech.wordpress.com/2010/10/07/komodo-6/</link>
		<comments>http://gaiustech.wordpress.com/2010/10/07/komodo-6/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 13:38:21 +0000</pubDate>
		<dc:creator>Gaius</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Ocaml]]></category>

		<guid isPermaLink="false">http://gaiustech.wordpress.com/?p=481</guid>
		<description><![CDATA[As of version 6, ActiveState Komodo includes OCaml syntax highlighting. It appears to be only minimal (e.g. no completion, no hovering over something to get its type, no code folding, no integration with the toolchain) but it&#8217;s a start&#8230; Or &#8230; <a href="http://gaiustech.wordpress.com/2010/10/07/komodo-6/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=481&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As of version 6, <a href="http://www.activestate.com/komodo-edit">ActiveState Komodo</a> includes OCaml syntax highlighting. It appears to be only minimal  (e.g. no completion, no hovering over something to get its type, no <a href="http://gaiustech.wordpress.com/2010/09/20/code-folding-in-emacs/">code folding</a>, no integration with the toolchain) but it&#8217;s a start&#8230;</p>
<p>Or too little too late, I&#8217;ve already switched to Emacs :-)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gaiustech.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gaiustech.wordpress.com/481/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=481&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gaiustech.wordpress.com/2010/10/07/komodo-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ced82e97b7a13f79da0aaaca2302cd45?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gaiush</media:title>
		</media:content>
	</item>
		<item>
		<title>Compiler tip</title>
		<link>http://gaiustech.wordpress.com/2010/09/20/ocaml-compiler-errors/</link>
		<comments>http://gaiustech.wordpress.com/2010/09/20/ocaml-compiler-errors/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 14:51:38 +0000</pubDate>
		<dc:creator>Gaius</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Ocaml]]></category>

		<guid isPermaLink="false">http://gaiustech.wordpress.com/?p=339</guid>
		<description><![CDATA[Consider the following trivial bit of OCaml: To me as a beginner this looks quite plausible, since I wrote something much like it, of course it should actually be: But the error from the compiler is strange: That is actually &#8230; <a href="http://gaiustech.wordpress.com/2010/09/20/ocaml-compiler-errors/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=339&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Consider the following trivial bit of OCaml:</p>
<pre class="brush: fsharp; highlight: [5]; title: ; wrap-lines: false; notranslate">
open Printf
  
let _ =
  let array_max arr =
    let arr' = Array.copy arr; 
    Array.sort (fun a b -&gt; b - a) arr';
    arr'.(0) in
  printf &quot;max=%d\n&quot; (array_max [|1;2;3;4;5|])
</pre>
<p>To me as a beginner this looks quite plausible, since I wrote something much like it, of course it should actually be:</p>
<pre class="brush: fsharp; first-line: 5; title: ; wrap-lines: false; notranslate">
   let arr' = Array.copy arr in
</pre>
<p>But the error from the compiler is strange:</p>
<pre class="brush: plain; highlight: [3]; light: true; title: ; wrap-lines: false; notranslate">
make -k 
ocamlc -g -c testcase.ml
File &quot;testcase.ml&quot;, line 9, characters 0-0:
Error: Syntax error
make: *** [testcase.cmo] Error 2
make: Target `testcase' not remade because of errors
</pre>
<p>That is actually one character beyond the end of my file!</p>
<p>So my top tip for today is, mysteriously vague error messages like this are probably a <code>;</code> instead of an <code>in</code> <i>somewhere</i>.  Emacs to the rescue:</p>
<pre class="brush: plain; light: true; title: ; wrap-lines: false; notranslate">
M-x replace-regexp RET \(let.*\); RET \1 in RET
</pre>
<p>Hah! Now if only I could think of a way to invoke that automagically when I get <code>0-0</code> after <code>C-c C-c</code>&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gaiustech.wordpress.com/339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gaiustech.wordpress.com/339/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=339&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gaiustech.wordpress.com/2010/09/20/ocaml-compiler-errors/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ced82e97b7a13f79da0aaaca2302cd45?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gaiush</media:title>
		</media:content>
	</item>
		<item>
		<title>Code folding in Emacs</title>
		<link>http://gaiustech.wordpress.com/2010/09/20/code-folding-in-emacs/</link>
		<comments>http://gaiustech.wordpress.com/2010/09/20/code-folding-in-emacs/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 07:13:13 +0000</pubDate>
		<dc:creator>Gaius</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ocaml]]></category>

		<guid isPermaLink="false">http://gaiustech.wordpress.com/?p=319</guid>
		<description><![CDATA[Code folding is a feature I&#8217;ve taken for granted in Windows IDEs, but now I am using Emacs more and more, I wanted it there too, and it turns out getting it is straightforward enough. Download Folding Mode and save &#8230; <a href="http://gaiustech.wordpress.com/2010/09/20/code-folding-in-emacs/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=319&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Code_folding">Code folding</a> is a feature I&#8217;ve taken for granted in Windows IDEs, but now I am using <a href="http://www.gnu.org/software/emacs/">Emacs</a> more and more, I wanted it there too, and it turns out getting it is straightforward enough.</p>
<ol>
<li>Download <a href="http://www.emacswiki.org/emacs/FoldingMode">Folding Mode</a> and save <a href="http://git.savannah.gnu.org/cgit/emacs-tiny-tools.git/plain/lisp/other/folding.el?h=devel">folding.el</a> in the Emacs site lisp directory (on my Debian machine that is <code>/usr/share/emacs23/site-lisp/</code>, probably the same on any Linux). <s>Surprisingly there&#8217;s no <code>.deb</code> package for it</s> or <code>apt-get install emacs-goodies-el</code>.</li>
<li>Add the following to your <code>~/.emacs</code>:
<pre class="brush: plain; highlight: [4,7]; title: ; notranslate">
(load &quot;folding&quot; 'nomessage 'noerror)
(folding-add-to-marks-list 'haskell-mode &quot;--{{{&quot;  &quot;--}}}&quot;  nil t)
(folding-mode-add-find-file-hook)
(add-hook 'haskell-mode-hook 'folding-mode)

(folding-add-to-marks-list 'tuareg-mode &quot;(*{{{&quot;  &quot;(*}}}*)&quot;  nil t)
(add-hook 'tuareg-mode-hook 'folding-mode)
</pre>
<p>Lines 4 and 7 cause <code>folding-mode</code> to be automatically entered <em>after</em> <code>haskell-mode</code> or <code>tuareg-mode</code> respectively, which seems to be necessary, rather than just loading it on Emacs startup with <code>auto-load</code>. This is slightly different from the instructions on the page, perhaps it was written for an older Emacs. </li>
<li>Delimit the code with the appropriate markers. These can be anything you put in <code>.emacs</code>, <code>{{{</code> and <code>}}}</code> in conjunction with the language&#8217;s own comment characters seems to be a convention. Unfortunately Emacs doesn&#8217;t seem to be able to do this automagically the way other language-sensitive editors would (then again, those editors don&#8217;t allow you to define folding positions yourself, they always do it on functions or other obvious blocks)
</li>
</ol>
<p>As an example you can then toggle between:<br />
<a href="http://gaiustech.files.wordpress.com/2010/09/emacs-unfolded.png"><img src="http://gaiustech.files.wordpress.com/2010/09/emacs-unfolded.png?w=640&#038;h=323" alt="" title="emacs-unfolded" width="640" height="323" class="alignnone size-full wp-image-320" /></a><br />
And:<br />
<a href="http://gaiustech.files.wordpress.com/2010/09/emacs-folded.png"><img src="http://gaiustech.files.wordpress.com/2010/09/emacs-folded.png?w=640&#038;h=323" alt="" title="emacs-folded" width="640" height="323" class="alignnone size-full wp-image-321" /></a><br />
With right-click. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gaiustech.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gaiustech.wordpress.com/319/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gaiustech.wordpress.com&#038;blog=15595609&#038;post=319&#038;subd=gaiustech&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gaiustech.wordpress.com/2010/09/20/code-folding-in-emacs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ced82e97b7a13f79da0aaaca2302cd45?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gaiush</media:title>
		</media:content>

		<media:content url="http://gaiustech.files.wordpress.com/2010/09/emacs-unfolded.png" medium="image">
			<media:title type="html">emacs-unfolded</media:title>
		</media:content>

		<media:content url="http://gaiustech.files.wordpress.com/2010/09/emacs-folded.png" medium="image">
			<media:title type="html">emacs-folded</media:title>
		</media:content>
	</item>
	</channel>
</rss>