<?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>A Curious Programmer</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com</link>
	<description>Exploring programming languages</description>
	<lastBuildDate>Mon, 31 Aug 2009 09:50:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='curiousprogrammer.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/5ffa1e4450160d0ec8fe7eb366602e27?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>A Curious Programmer</title>
		<link>http://curiousprogrammer.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://curiousprogrammer.wordpress.com/osd.xml" title="A Curious Programmer" />
		<item>
		<title>Sorting Records With Emacs</title>
		<link>http://curiousprogrammer.wordpress.com/2009/08/31/sorting-records-with-emacs/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/08/31/sorting-records-with-emacs/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 09:50:53 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs lisp]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=735</guid>
		<description><![CDATA[I use sort-lines fairly frequently to keep my #includes, uses or variable names in order.  Occasionally though, I need to sort something slightly more complicated and I end up writing a little perl script.  I found myself thinking it must be equally easy in emacs.
For example, I say I have the following data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=735&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I use sort-lines fairly frequently to keep my <code style="font-size:130%;background:#eee;padding:3px;">#includes</code>, <code style="font-size:130%;background:#eee;padding:3px;">uses</code> or variable names in order.  Occasionally though, I need to sort something slightly more complicated and I end up writing a little perl script.  I found myself thinking it must be equally easy in emacs.</p>
<p>For example, I say I have the following data which I want to sort by the second field which is in position 12 and 13.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
Edward Wood 9   01/07/2005
Ed Smith    25  06/12/2004
James Brown 18  01/07/2005
Jon James   13  05/15/2007
</pre>
<p>Now, emacs does have a <code style="font-size:130%;background:#eee;padding:3px;">sort-columns</code> function which does all sorts of fancy things including checking if we are using Unix and shelling out to sort if possible, but it doesn&#8217;t seem to be able to do a numerical comparison.  However, in <code style="font-size:130%;background:#eee;padding:3px;">sort.el</code> it does have a general purpose sorting function called <code style="font-size:130%;background:#eee;padding:3px;">sort-subr</code>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">sort-subr</span> (reverse nextrecfun endrecfun
                          <span style="color:#228b22;">&amp;optional</span> startkeyfun endkeyfun predicate)
</pre>
<p><code style="font-size:130%;background:#eee;padding:3px;">sort-lines</code> itself is a good start for my custom function as it has all the code for handling regions, reversal and skipping between records (lines) that we need.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">sort-lines</span> (reverse beg end)
  (interactive <span style="color:#bc8f8f;">"P\nr"</span>)
  (<span style="color:#a020f0;">save-excursion</span>
    (<span style="color:#a020f0;">save-restriction</span>
      (narrow-to-region beg end)
      (goto-char (point-min))
      (<span style="color:#a020f0;">let</span> ((inhibit-field-text-motion t))
        (sort-subr reverse 'forward-line 'end-of-line)))))
</pre>
<p>Getting the startkeyfun and endkeyfun correct was fairly straight forward but I wasn&#8217;t entirely sure what information was passed to the predicate.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">sort-on-field</span> (reverse beg end)
  (interactive <span style="color:#bc8f8f;">"P\nr"</span>)
  (<span style="color:#a020f0;">save-excursion</span>
    (<span style="color:#a020f0;">save-restriction</span>
      (narrow-to-region beg end)
      (goto-char (point-min))
      (<span style="color:#a020f0;">let</span> ((inhibit-field-text-motion t))
        (sort-subr reverse 'forward-line 'end-of-line
                   (<span style="color:#a020f0;">lambda</span> () (forward-char 12))
                   (<span style="color:#a020f0;">lambda</span> () (forward-char 2))
                   (<span style="color:#a020f0;">lambda</span> (a b)
                     (message (format <span style="color:#bc8f8f;">"[%s] [%s]"</span> a b))))))))

[(703 . 705)] [(676 . 678)]
[(757 . 759)] [(730 . 732)]
[(757 . 759)] [(703 . 705)]
[(730 . 732)] [(703 . 705)]
</pre>
<p>The final working version:</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">sort-on-field</span> (reverse beg end)
  (interactive <span style="color:#bc8f8f;">"P\nr"</span>)
  (<span style="color:#a020f0;">save-excursion</span>
    (<span style="color:#a020f0;">save-restriction</span>
      (narrow-to-region beg end)
      (goto-char (point-min))
      (<span style="color:#a020f0;">let</span> ((inhibit-field-text-motion t))
        (sort-subr reverse 'forward-line 'end-of-line
                   (<span style="color:#a020f0;">lambda</span> () (forward-char 12))
                   (<span style="color:#a020f0;">lambda</span> () (forward-char 2))
                   (<span style="color:#a020f0;">lambda</span> (a b)
                     (<span style="color:#a020f0;">let</span> ((s1 (buffer-substring (car a) (cdr a)))
                           (s2 (buffer-substring (car b) (cdr b))))
                       (&lt; (string-to-number s1) (string-to-number s2)))))))))
</pre>
<p>Providing a nice way of asking for the start and end location of the sorting field is left as an exercise for the reader.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/735/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=735&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/08/31/sorting-records-with-emacs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>Emacs Lisp Keyword Parameters</title>
		<link>http://curiousprogrammer.wordpress.com/2009/08/16/elisp-keyword-params/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/08/16/elisp-keyword-params/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 10:25:08 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[directory aliases]]></category>
		<category><![CDATA[emacs lisp]]></category>
		<category><![CDATA[keyword parameters]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=732</guid>
		<description><![CDATA[I don&#8217;t create many lisp macros but it is still a huge advantage having them.  I&#8217;m a big user of macros that other people have created.  For example, by default emacs lisp does not support keyword parameters.  Thanks to the magic of macros they have been added in the cl.el common lisp [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=732&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I don&#8217;t create many lisp macros but it is still a huge advantage having them.  I&#8217;m a big user of macros that other people have created.  For example, by default emacs lisp does not support keyword parameters.  Thanks to the magic of macros they have been added in the <code style="font-size:130%;background:#eee;padding:3px;">cl.el</code> common lisp package.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">cl</span>)

(<span style="color:#a020f0;">defun*</span> <span style="color:#0000ff;">example</span> (<span style="color:#228b22;">&amp;rest</span> args
                 <span style="color:#228b22;">&amp;key</span> (a 1) (b 2))
  (format <span style="color:#bc8f8f;">"%s %s %s"</span> args a b))
</pre>
<p><code style="font-size:130%;background:#eee;padding:3px;">(example)</code> works as expected and returns <code style="font-size:130%;background:#eee;padding:3px;">&quot;nil 1 2&quot;</code></p>
<p><code style="font-size:130%;background:#eee;padding:3px;">(example :a 10)</code> is pretty good too although you may be surprised that keywords are not removed from the &amp;rest args <code style="font-size:130%;background:#eee;padding:3px;">&quot;(:a 10) 10 2&quot;</code></p>
<p>However, <code style="font-size:130%;background:#eee;padding:3px;">(example 1)</code> returns the following surprise <code style="font-size:130%;background:#eee;padding:3px;">(error &quot;Keyword argument 1 not one of (:a :b)&quot;)</code>.</p>
<p>If you are using <code style="font-size:130%;background:#eee;padding:3px;">&amp;rest</code> and <code style="font-size:130%;background:#eee;padding:3px;">&amp;key</code> together, you can fix this with <code style="font-size:130%;background:#eee;padding:3px;">&amp;allow-other-keys</code>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun*</span> <span style="color:#0000ff;">example</span> (<span style="color:#228b22;">&amp;rest</span> args
                 <span style="color:#228b22;">&amp;key</span> (a 1) (b 2)
                 <span style="color:#228b22;">&amp;allow-other-keys</span>)
  (format <span style="color:#bc8f8f;">"%s %s %s"</span> args a b))
</pre>
<p>Okay, so much for pithy examples.  How about something practical?</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun*</span> <span style="color:#0000ff;">remote-path</span> (<span style="color:#228b22;">&amp;rest</span> path
                     <span style="color:#228b22;">&amp;key</span> (user <span style="color:#bc8f8f;">"jared"</span>) (server <span style="color:#bc8f8f;">"someserver"</span>)
                     <span style="color:#228b22;">&amp;allow-other-keys</span>)
  (concat <span style="color:#bc8f8f;">"ftp:"</span> user <span style="color:#bc8f8f;">"@"</span> server <span style="color:#bc8f8f;">":"</span>
          (mapconcat #'identity path <span style="color:#bc8f8f;">"/"</span>)))
</pre>
<p><code style="font-size:130%;background:#eee;padding:3px;">(remote-path :user &quot;uat-user&quot; &quot;/tmp&quot; &quot;test-dir&quot;)</code> throws this error <code style="font-size:130%;background:#eee;padding:3px;">(wrong-type-argument sequencep :user)</code>.  This is because if you use <code style="font-size:130%;background:#eee;padding:3px;">&amp;rest</code> arguments and <code style="font-size:130%;background:#eee;padding:3px;">&amp;key</code> arguments together, the keyword arguments are also passed through into <code style="font-size:130%;background:#eee;padding:3px;">&amp;rest</code>.</p>
<p>I couldn&#8217;t find an obvious function to remove keyword parameters so I&#8217;ve written my own <code style="font-size:130%;background:#eee;padding:3px;">remove-keyword-params</code>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">remove-keyword-params</span> (seq)
  (<span style="color:#a020f0;">if</span> (null seq) nil
    (<span style="color:#a020f0;">let</span> ((head (car seq))
          (tail (cdr seq)))
      (<span style="color:#a020f0;">if</span> (keywordp head) (remove-keyword-params (cdr tail))
        (cons head (remove-keyword-params tail))))))

(<span style="color:#a020f0;">defun*</span> <span style="color:#0000ff;">remote-path</span> (<span style="color:#228b22;">&amp;rest</span> path
                     <span style="color:#228b22;">&amp;key</span> (user <span style="color:#bc8f8f;">"jared"</span>) (server <span style="color:#bc8f8f;">"someserver"</span>)
                     <span style="color:#228b22;">&amp;allow-other-keys</span>)
  (concat <span style="color:#bc8f8f;">"ftp:"</span> user <span style="color:#bc8f8f;">"@"</span> server <span style="color:#bc8f8f;">":"</span>
          (mapconcat #'identity (remove-keyword-params path) <span style="color:#bc8f8f;">"/"</span>)))
</pre>
<p>Now it works correctly.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(remote-path <span style="color:#da70d6;">:user</span> <span style="color:#bc8f8f;">"uat-user"</span> <span style="color:#bc8f8f;">"/tmp"</span> <span style="color:#bc8f8f;">"test-dir"</span>)
<span style="color:#b22222;">;; </span><span style="color:#b22222;">"ftp:uat-user@someserver:/tmp/test-dir"
</span></pre>
<p>So what do I want this for?  For my <a href="http://curiousprogrammer.wordpress.com/2009/02/18/emacs-directory-aliases/">directory aliases</a> of course.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defconst</span> <span style="color:#b8860b;">*dired-dirs*</span>
  (list (cons <span style="color:#bc8f8f;">"dev"</span> (remote-path <span style="color:#bc8f8f;">"~/dev"</span>))
        (cons <span style="color:#bc8f8f;">"dev:system"</span>
              (remote-path <span style="color:#da70d6;">:user</span> <span style="color:#bc8f8f;">"dev-user"</span> <span style="color:#bc8f8f;">"~/system"</span>))
        (cons <span style="color:#bc8f8f;">"uat:system"</span>
              (remote-path <span style="color:#da70d6;">:user</span> <span style="color:#bc8f8f;">"dev-user"</span> <span style="color:#bc8f8f;">"~/system"</span>))))
</pre>
<p>And surprise surprise, because emacs is architected so well, it all works remotely through tramp completely transparently.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/732/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=732&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/08/16/elisp-keyword-params/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>A Strange Tramp Mode Problem</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/28/tramp-mode-problem/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/07/28/tramp-mode-problem/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 21:45:15 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[strange bug]]></category>
		<category><![CDATA[tramp mode]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=728</guid>
		<description><![CDATA[Does anyone else use tramp?  It is a mode that allows emacs to transparently edit remote files.  For example, you have a file called afile.txt on a server called someserver.

/ftp:jared@someserver:~/afile.txt

Then behind the scenes emacs will ftp the the file to and from the server every time you save.
What Is Happening In Ange-ftp?
Recently tramp [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=728&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Does anyone else use <a href="http://www.emacswiki.org/emacs/TrampMode">tramp</a>?  It is a mode that allows emacs to transparently edit remote files.  For example, you have a file called <em>afile.txt</em> on a server called <em>someserver</em>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
/ftp:jared@someserver:~/afile.txt
</pre>
<p>Then behind the scenes emacs will ftp the the file to and from the server every time you save.</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">What Is Happening In Ange-ftp?</h2>
<p class="first">Recently <code style="font-size:130%;background:#eee;padding:3px;">tramp</code> has been letting me down.  When I try and access a remote-file it fails to login to the ftp process.  <em>Sad</em>.</p>
<p>The ftp login as handled by <code style="font-size:130%;background:#eee;padding:3px;">ange-ftp</code>.  I finally tracked the problem down to this section.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">ange-ftp-get-process</span> (host user)
      <span style="color:#b22222;">;; </span><span style="color:#b22222;">...
</span>      (<span style="color:#a020f0;">let</span> ((pass (ange-ftp-quote-string
                   (ange-ftp-get-passwd host user)))
</pre>
<p><code style="font-size:130%;background:#eee;padding:3px;">ange-ftp-get-process</code> calls <code style="font-size:130%;background:#eee;padding:3px;">(ange-ftp-quote-string ...)</code>.  Normally, this isn&#8217;t a problem.  For example, on the Windows PC I am using at this precise moment <code style="font-size:130%;background:#eee;padding:3px;">(ange-ftp-quote-string &quot;!\&quot;£$%^&amp;*()&quot;)</code> expands to <code style="font-size:130%;background:#eee;padding:3px;">&quot;!\&quot;£$%^&amp;*()&quot;</code>.  However, at work, I get:</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
<span style="color:#bc8f8f;">"\\!\"&#163;\\$\\%^\\&amp;\\*()"</span>
</pre>
<p>Could this be due to the customize EmacsW32 option?  I&#8217;m not sure.  Anyway, absent the underlying cause, my work-around is to <code style="font-size:130%;background:#eee;padding:3px;">(require 'ange-ftp)</code> and then redefine the ange-ftp-get-process without the quoting of the password.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">ange-ftp</span>)

(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">ange-ftp-get-process</span> (host user)
      <span style="color:#b22222;">;; </span><span style="color:#b22222;">...
</span>      (<span style="color:#a020f0;">let</span> ((pass (ange-ftp-get-passwd host user))
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/728/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/728/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/728/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/728/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/728/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/728/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/728/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/728/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/728/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/728/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=728&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/07/28/tramp-mode-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>Emacs Utility Functions</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 11:40:44 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs lisp]]></category>
		<category><![CDATA[utility functions]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725</guid>
		<description><![CDATA[I have a number of utility functions in a file called my-utils.el.  The first one I wrote was add-path.
add-path

(defun add-path (&#38;rest path)
  (let ((full-path ""))
    (dolist (var path)
      (setq full-path (concat full-path var)))
    (add-to-list 'load-path (expand-file-name full-path))))

This means that when I add [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=725&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have a number of utility functions in a file called <code style="font-size:130%;background:#eee;padding:3px;">my-utils.el</code>.  The first one I wrote was <code style="font-size:130%;background:#eee;padding:3px;">add-path</code>.</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">add-path</h2>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">add-path</span> (<span style="color:#228b22;">&amp;rest</span> path)
  (<span style="color:#a020f0;">let</span> ((full-path <span style="color:#bc8f8f;">""</span>))
    (<span style="color:#a020f0;">dolist</span> (var path)
      (setq full-path (concat full-path var)))
    (add-to-list 'load-path (expand-file-name full-path))))
</pre>
<p>This means that when I add a new third-party library (in its own directory), I can just write:</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(add-path *elisp-dir* <span style="color:#bc8f8f;">"muse-3.12"</span>)
</pre>
<p>I have a function called <code style="font-size:130%;background:#eee;padding:3px;">identity</code> that returns whatever was passed to it.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">identity</span> (e) e)
</pre>
<p>This is particularly useful in functions like <code style="font-size:130%;background:#eee;padding:3px;">mapconcat</code>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">add-path</span> (<span style="color:#228b22;">&amp;rest</span> path)
  (add-to-list 'load-path (mapconcat #'identity path <span style="color:#bc8f8f;">""</span>)))
</pre>
<p>I like this function that I found on the internet a while ago (can&#8217;t find it again for attribution unfortunately).</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">insert-YYMMDD</h2>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">insert-YYYMMDD</span> ()
  (interactive)
  (insert (format-time-string <span style="color:#bc8f8f;">"%Y%m%d"</span>)))
</pre>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">remove-dupes</h2>
<p><code style="font-size:130%;background:#eee;padding:3px;">remove-dupes</code> removes duplicate items that are next to each other in a list in the same way that <code style="font-size:130%;background:#eee;padding:3px;">uniq</code> does.  (I mentioned this previously in one of the <a href="http://curiousprogrammer.wordpress.com/2009/07/02/enabling-yourusers-2/">enabling your users</a> posts.)</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">remove-dupes</span> (list)
  (<span style="color:#a020f0;">let</span> (tmp-list head)
    (<span style="color:#a020f0;">while</span> list
      (setq head (pop list))
      (<span style="color:#a020f0;">unless</span> (equal head (car list))
        (push head tmp-list)))
    (reverse tmp-list)))
</pre>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">assoc-replace</h2>
<p class="first">Sometimes you will have an assocation list where you just want to replace one of the values.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">assoc-replace</span> (seq values)
  <span style="color:#bc8f8f;">"Replace an element within an association list where the cars match."</span>
  (mapcar (<span style="color:#a020f0;">lambda</span> (elem)
            (<span style="color:#a020f0;">let*</span> ((key (car elem))
                   (val (assoc key values)))
              (<span style="color:#a020f0;">if</span> val (cadr val) elem))) seq))
</pre>
<p>And often, only the cdr needs to change so <code style="font-size:130%;background:#eee;padding:3px;">kv</code> is a shortcut for that case.  <code style="font-size:130%;background:#eee;padding:3px;">(kv 'a 'b)</code> returns <code style="font-size:130%;background:#eee;padding:3px;">(a (a . b))</code>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defsubst</span> <span style="color:#0000ff;">kv</span> (k v)
  `(,k (,k . ,v)))
</pre>
<p>(These functions were mentioned in <a href="http://curiousprogrammer.wordpress.com/2009/03/10/elisp-association-lists/">emacs association lists</a>)</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">ext-mode-map</h2>
<p><code style="font-size:130%;background:#eee;padding:3px;">ext-mode-map</code> allows me to easily setup a major mode for extensions that are inconsistently capitalized.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-extensions</span> (l)
  (concat <span style="color:#bc8f8f;">"\\.</span><span style="color:#bc8f8f;font-weight:bold;">\\</span><span style="color:#bc8f8f;font-weight:bold;">(</span><span style="color:#bc8f8f;">"</span>
          (mapconcat
           (<span style="color:#a020f0;">lambda</span> (s)
             (mapconcat (<span style="color:#a020f0;">lambda</span> (c)
                          (<span style="color:#a020f0;">let</span> ((c (upcase (char-to-string c))))
                            (concat <span style="color:#bc8f8f;">"["</span> c (downcase c) <span style="color:#bc8f8f;">"]"</span>)))
                        (symbol-name s) <span style="color:#bc8f8f;">""</span>))
           l <span style="color:#bc8f8f;">"</span><span style="color:#bc8f8f;font-weight:bold;">\\</span><span style="color:#bc8f8f;font-weight:bold;">|</span><span style="color:#bc8f8f;">"</span>)
          <span style="color:#bc8f8f;">"</span><span style="color:#bc8f8f;font-weight:bold;">\\</span><span style="color:#bc8f8f;font-weight:bold;">)</span><span style="color:#bc8f8f;">\\'"</span>))

(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">ext-mode-map</span> (extensions mode)
  (cons (file-extensions extensions) mode))
</pre>
<p>Then, for example, I can setup my perl extensions like this:</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(add-to-list 'auto-mode-alist (ext-mode-map '(pl perl pm) 'cperl-mode))
</pre>
<p>(These functions were previously mentioned in <a href="http://curiousprogrammer.wordpress.com/2009/02/02/autoload-emacs-major-mode/">autoloading an emacs major mode</a>)</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">duplicate-current-line</h2>
<p class="first">I&#8217;m <em>still</em> using this function to duplicate the current line.  It works unless you are on the final line which is very rare and you can work around that by opening a line below.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">duplicate-current-line</span> ()
  (interactive)
  (beginning-of-line nil)
  (<span style="color:#a020f0;">let</span> ((b (point)))
    (end-of-line nil)
    (copy-region-as-kill b (point)))
  (beginning-of-line 2)
  (open-line 1)
  (yank)
  (back-to-indentation))
</pre>
<p>(This function was mentioned previously in <a href="http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/">A Simple Emacs Shortcut &#8211; Duplicate Line</a>)</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">set-longlines-mode</h2>
<p class="first">I often copy text into buffer and want to read it nicely wrapped around.  I&#8217;ll change this function to use <code style="font-size:130%;background:#eee;padding:3px;">visual-line-mode</code> when all my emacs versions are upgraded to 23.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">set-longlines-mode</span> ()
  (interactive)
  (text-mode)
  (longlines-mode 1))
</pre>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">count-words</h2>
<p class="first">Other people have talked about their own <code style="font-size:130%;background:#eee;padding:3px;">count-words</code> functions in the past.  I have my own ideas about what constitutes a word.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">count-words</span> ()
  (interactive)
  (<span style="color:#a020f0;">let</span> ((words (count-matches <span style="color:#bc8f8f;">"[-A-Za-z0-9][-A-Za-z0-9.]*"</span>
                              (point-min) (point-max))))
    (message (format <span style="color:#bc8f8f;">"There are %d words"</span> words))))
</pre>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">regex-replace and string-repeat</h2>
<p class="first">I sometimes have a text transform that I want to apply globally to a buffer.  Exercise for the reader, fix <code style="font-size:130%;background:#eee;padding:3px;">regex-replace</code> to only apply to a region if one is selected.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">regex-replace</span> (regex string)
  (goto-char (point-min))
  (<span style="color:#a020f0;">while</span> (re-search-forward regex nil t)
    (replace-match string)))

(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">string-repeat</span> (str n)
  (<span style="color:#a020f0;">let</span> ((retval <span style="color:#bc8f8f;">""</span>))
    (<span style="color:#a020f0;">dotimes</span> (i n)
      (setq retval (concat retval str)))
    retval))
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/725/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/725/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/725/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/725/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/725/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=725&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>Strawberry Perl and POE</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/18/strawberry-perl-and-poe/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/07/18/strawberry-perl-and-poe/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 19:45:43 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[poe]]></category>
		<category><![CDATA[strawberry perl]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=720</guid>
		<description><![CDATA[I&#8217;m (unfortunately) doing more work on Windows on these days so I&#8217;ve installed a mini Windows-dev environment at home.  It is impressive what the libre software guys have done &#8211; between Emacs, Cygwin and Perl (and a rusty MinGW C compiler) I feel almost at home.
On Windows, there is an embarrassment of Perl options. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=720&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m (unfortunately) doing more work on Windows on these days so I&#8217;ve installed a mini Windows-dev environment at home.  It is impressive what the libre software guys have done &#8211; between Emacs, Cygwin and Perl (and a rusty MinGW C compiler) I feel almost at home.</p>
<p>On Windows, there is an embarrassment of Perl options.  I could choose from ActiveState Perl, Strawberry Perl, CygPerl or try and build it myself.  I haven&#8217;t tried Strawberry Perl so I thought I&#8217;d give it a whirl.  The install process was pleasant enough but after that I had some problems.  I tried my usual <code style="font-size:130%;background:#eee;padding:3px;">perl -MCPAN -e shell</code> incantation followed by installing (upgrading) the CPAN package but it didn&#8217;t work.  Woe is me!</p>
<p>I reached for old reliable cygperl but <em>that</em> didn&#8217;t work either.  Hmmm&#8230; fishy, I&#8217;m sure I haven&#8217;t had problems previously.  Thankfully googling the exact error lead to a solution which unfortunately I didn&#8217;t make a note of.  I do remember that it involved a rebase from the static shell, <code style="font-size:130%;background:#eee;padding:3px;">ash</code>.  Following that, Strawberry Perl worked too.</p>
<p>The next thing to do was to install POE.  POE allows you to structure your code in an event-driven way.  I&#8217;ve experienced some strange behaviour with POE on various Windows Perl implementations in the past so I want to test a few things.</p>
<p>My basic POE script.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
<span style="color:#a020f0;">use</span> <span style="color:#0000ff;">strict</span>;
<span style="color:#a020f0;">use</span> <span style="color:#0000ff;">warnings</span>;

<span style="color:#a020f0;">use</span> <span style="color:#0000ff;">POE</span>;

POE::Session-&gt;create(
    <span style="color:#bc8f8f;">inline_states</span> =&gt; {
        <span style="color:#bc8f8f;">_start</span> =&gt; <span style="color:#a020f0;">sub</span> { <span style="color:#0000ff;background-color:#eeeed1;font-weight:bold;">$_</span>[KERNEL]-&gt;yield(<span style="color:#bc8f8f;">'loop'</span>); },
        <span style="color:#bc8f8f;">loop</span>   =&gt; <span style="color:#a020f0;">sub</span> {
            <span style="color:#66cd00;">print</span> <span style="color:#bc8f8f;">"Normal loop\n"</span>;
            <span style="color:#0000ff;background-color:#eeeed1;font-weight:bold;">$_</span>[KERNEL]-&gt;delay(<span style="color:#bc8f8f;">loop</span> =&gt; 1);
        },
    }
);

$poe_kernel-&gt;run();
</pre>
<p>That was a cumbersome way to implement a while 1 loop eh?</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
<span style="color:#a020f0;">while</span> (1) {
    <span style="color:#66cd00;">print</span> <span style="color:#bc8f8f;">"Normal Loop\n"</span>;
    <span style="color:#228b22;">sleep</span> 1;
}
</pre>
<p>The first thing I want to test is timeouts.  I actually like the crufty way that timeouts are implemented in perl with eval / sig alarm.  I use sleep here to simulate a long running process despite the warning in the documentation.</p>
<blockquote>
<p class="quoted">
It is usually a mistake to intermix alarm and sleep calls. (sleep may be internally implemented in your system with alarm)</p>
</blockquote>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
<span style="color:#a020f0;">use</span> <span style="color:#0000ff;">strict</span>;
<span style="color:#a020f0;">use</span> <span style="color:#0000ff;">warnings</span>;

<span style="color:#a020f0;">use</span> <span style="color:#0000ff;">POE</span>;

<span style="color:#a020f0;">sub</span> <span style="color:#0000ff;">timeout_test</span>
{
    <span style="color:#a020f0;">eval</span> {
        <span style="color:#a020f0;">local</span> <span style="color:#ff0000;background-color:#eeeed1;font-weight:bold;font-style:italic;">$SIG</span>{<span style="color:#bc8f8f;">ALRM</span>} = <span style="color:#a020f0;">sub</span> { <span style="color:#a020f0;">die</span> <span style="color:#bc8f8f;">"alarm\n"</span> }; <span style="color:#b22222;"># </span><span style="color:#b22222;">NB: \n required
</span>        <span style="color:#228b22;">alarm</span> 3;
        <span style="color:#228b22;">sleep</span> 5; <span style="color:#b22222;"># </span><span style="color:#b22222;">This simulates a long-running process
</span>        <span style="color:#228b22;">alarm</span> 0;
    };
    <span style="color:#a020f0;">if</span> ($@) {
        <span style="color:#a020f0;">die</span> <span style="color:#a020f0;">unless</span> $@ <span style="color:#228b22;">eq</span> <span style="color:#bc8f8f;">"alarm\n"</span>; <span style="color:#b22222;"># </span><span style="color:#b22222;">propagate unexpected errors
</span>        <span style="color:#66cd00;">print</span> <span style="color:#bc8f8f;">"Timeout\n"</span>;
        <span style="color:#b22222;"># </span><span style="color:#b22222;">timed out
</span>    }
    <span style="color:#a020f0;">else</span> {
        <span style="color:#b22222;"># </span><span style="color:#b22222;">didn't
</span>    }
}
</pre>
<p>POE sessions are a bit like co-operative threads.  If the session doesn&#8217;t yield to the kernel, another session can&#8217;t run so if the timeout doesn&#8217;t work, we won&#8217;t see any output after the timeout loop starts.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
POE::Session-&gt;create(
    <span style="color:#bc8f8f;">inline_states</span> =&gt; {
        <span style="color:#bc8f8f;">_start</span> =&gt; <span style="color:#a020f0;">sub</span> { <span style="color:#0000ff;background-color:#eeeed1;font-weight:bold;">$_</span>[KERNEL]-&gt;yield(<span style="color:#bc8f8f;">'loop'</span>); },
        <span style="color:#bc8f8f;">loop</span>   =&gt; <span style="color:#a020f0;">sub</span> {
            <span style="color:#66cd00;">print</span> <span style="color:#bc8f8f;">"Normal Loop\n"</span>;
            <span style="color:#0000ff;background-color:#eeeed1;font-weight:bold;">$_</span>[KERNEL]-&gt;delay(<span style="color:#bc8f8f;">loop</span> =&gt; 1);
        },
    }
);

POE::Session-&gt;create(
    <span style="color:#bc8f8f;">inline_states</span> =&gt; {
        <span style="color:#bc8f8f;">_start</span> =&gt; <span style="color:#a020f0;">sub</span> { <span style="color:#0000ff;background-color:#eeeed1;font-weight:bold;">$_</span>[KERNEL]-&gt;yield(<span style="color:#bc8f8f;">'loop'</span>); },
        <span style="color:#bc8f8f;">loop</span>   =&gt; <span style="color:#a020f0;">sub</span> {
            <span style="color:#66cd00;">print</span> <span style="color:#bc8f8f;">"Timeout loop\n"</span>;
            timeout_test();
            <span style="color:#0000ff;background-color:#eeeed1;font-weight:bold;">$_</span>[KERNEL]-&gt;delay(<span style="color:#bc8f8f;">loop</span> =&gt; 1);
        },
    }
);

$poe_kernel-&gt;run();
</pre>
<p>Fortunately, it works fine.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
$ perl basic-poe.pl
Normal Loop
Timeout loop
Timeout
Normal Loop
Timeout loop
Timeout
Normal Loop
Terminating on signal SIGINT(2)
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/720/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=720&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/07/18/strawberry-perl-and-poe/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>My Emacs Defaults</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/13/my-emacs-defaults/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/07/13/my-emacs-defaults/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 22:00:18 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[basic config]]></category>
		<category><![CDATA[emacs config]]></category>
		<category><![CDATA[essential config]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=713</guid>
		<description><![CDATA[Now that I have customised my emacs extensively, the default configuration is quite uncomfortable for me to use.  I have a file called my-defaults.el which is the bare minimum I need to make using emacs a pleasant experience.  If I have to sit down at your emacs session, I will probably need to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=713&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Now that I have customised my emacs extensively, the default configuration is quite uncomfortable for me to use.  I have a file called <code style="font-size:130%;background:#eee;padding:3px;">my-defaults.el</code> which is the bare minimum I need to make using emacs a pleasant experience.  If I have to sit down at your emacs session, I will probably need to cut and paste these into a temp buffer and call <code style="font-size:130%;background:#eee;padding:3px;">M-x eval-region</code>.</p>
<p>I&#8217;ve mentioned <a href="http://curiousprogrammer.wordpress.com/2009/04/28/emacs-hacks/">some of these</a> modifications before.</p>
<p>I always <em>always</em> use ido and uniquify.  Ido makes it so nice for finding files and switching buffers, I now find the default behaviour surprising and sometimes even catch myself waiting for the options to appear.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">ido</span>)
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">uniquify</span>)
</pre>
<p><em>flex-matching</em> is a given of course, and I don&#8217;t like being prompted unnecessarily for new buffers &#8211; I&#8217;m always creating them.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(ido-mode t)
(setq ido-enable-flex-matching t)

(setq ido-create-new-buffer 'always)
</pre>
<p>The way emacs deals with identically named files by default is poor, but it is great that it is so easy to fix.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator <span style="color:#bc8f8f;">"|"</span>)
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re <span style="color:#bc8f8f;">"^\\*"</span>)
</pre>
<p>Since emacs23, fonts now look great.  This is from my windows config.  Other folks have written about beautifying emacs for other OSes.  I summarised those posts <a href="http://curiousprogrammer.wordpress.com/2009/04/09/beautiful-emacs-roundup/">here</a>.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(set-default-font
 <span style="color:#bc8f8f;">"-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1"</span>)
</pre>
<p>It should be obvious what most of these do.  The most important ones are setting yes-or-no-p to accept y or n rather than forcing me to type yes&lt;RETURN&gt; and removing the toolbar.  Actually no, scratch that, these are all important.  (Emacs23 has some of these set by default).</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(global-font-lock-mode 1)
(setq inhibit-splash-screen t)
(setq font-lock-maximum-decoration 3)
(setq use-file-dialog nil)
(setq use-dialog-box nil)
(fset 'yes-or-no-p 'y-or-n-p)
(tool-bar-mode -1)
(show-paren-mode 1)
(transient-mark-mode t)
(setq case-fold-search t)
(blink-cursor-mode 0)
</pre>
<p>It took me ages to figure out how to prevent emacs <a href="http://curiousprogrammer.wordpress.com/2009/01/24/how-to-disable-ident-tabs-mode/">converting a bunch of spaces into tabs</a>.  And of course, the scrollbar should always be on the right.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(custom-set-variables
 '(scroll-bar-mode 'right)
 '(indent-tabs-mode nil))
</pre>
<p>Where am I?</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(line-number-mode 1)
(column-number-mode 1)
</pre>
<p>Keep emacs backup files in one place.  This is from my windows config again.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(push '(<span style="color:#bc8f8f;">"."</span> . <span style="color:#bc8f8f;">"c:/home/jared/.emacs-backups"</span>) backup-directory-alist)
</pre>
<p>And make it so that when I copy a region, that gets sent to the OS clipboard.</p>
<pre style="font-size:130%;border:1px solid #bbb;background:#eee;overflow:auto;margin:15px 5px;padding:5px;">
(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/713/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=713&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/07/13/my-emacs-defaults/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>Basic Emacs Muse Configuration</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/10/basic-emacsmuse-config/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/07/10/basic-emacsmuse-config/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 13:10:46 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs muse]]></category>
		<category><![CDATA[muse configuration]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=704</guid>
		<description><![CDATA[Looking back over my old posts, I found I didn&#8217;t cover basic muse setup at the time when I did my original muse series.
part 1  part 2 part 3 part 4
As I&#8217;ve mentioned previously, I generate the html (including the funky syntax highlighting) for my posts and squidoo lenses using muse with htmlize.
You can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=704&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Looking back over my old posts, I found I didn&#8217;t cover basic muse setup at the time when I did my original muse series.</p>
<p><a href="http://curiousprogrammer.wordpress.com/2009/03/08/squidoo-lenses-and-emacs-muse/">part 1</a>  <a href="http://curiousprogrammer.wordpress.com/2009/03/10/elisp-association-lists/">part 2</a> <a href="http://curiousprogrammer.wordpress.com/2009/03/12/emacs-muse-aliases/">part 3</a> <a href="http://curiousprogrammer.wordpress.com/2009/03/14/deriving-muse-styles/">part 4</a></p>
<p>As I&#8217;ve mentioned previously, I generate the html (including the funky syntax highlighting) for my posts and squidoo lenses using muse with htmlize.</p>
<p>You can download muse <a href="http://mwolson.org/projects/EmacsMuse.html">here</a> and if you are using emacs23 then you need the patched version of htmlize, available <a href="http://www.emacswiki.org/emacs/download/htmlize.el">here</a>.</p>
<hr />
<p>The first thing I do with most third party modules, is I add the require lines and the paths I need.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(load <span style="color:#bc8f8f;">"my-vars.el"</span>)

(<span style="color:#a020f0;">defconst</span> <span style="color:#b8860b;">*elisp-muse*</span> (concat *elisp-3rd* <span style="color:#bc8f8f;">"/muse-3.12/lisp"</span>))

(add-to-list 'load-path *elisp-muse*)

(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">htmlize</span>)

(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">muse-mode</span>)
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">muse-publish</span>)
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">muse-html</span>)
</pre>
<p><code style="font-size:130%;background:#eee;padding:3px;">my-var.el</code> contains constants pointing to the top-level directories (I still haven&#8217;t got around to putting everything under <code style="font-size:130%;background:#eee;padding:3px;">emacs.d</code>)</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defconst</span> <span style="color:#b8860b;">*elisp-dir*</span> (expand-file-name <span style="color:#bc8f8f;">"~/emacs-files"</span>))
(<span style="color:#a020f0;">defconst</span> <span style="color:#b8860b;">*elisp-3rd*</span> (concat *elisp-dir* <span style="color:#bc8f8f;">"/third-party"</span>))

(<span style="color:#a020f0;">provide</span> '<span style="color:#5f9ea0;">my-vars</span>)
</pre>
<p>I use a couple of minor modes together with muse which are added to <code style="font-size:130%;background:#eee;padding:3px;">muse-mode-hook</code>.  (Note, I&#8217;m still using <a href="http://curiousprogrammer.wordpress.com/2009/06/17/longlines-mode/">longlines-mode</a> as at work I&#8217;m unable to use emacs23 where <code style="font-size:130%;background:#eee;padding:3px;">visual-line-mode</code> was introduced)</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">muse-minor-modes</span> ()
  (longlines-mode 1)
  (flyspell-mode 1)
  (font-lock-mode 0))

(add-hook 'muse-mode-hook 'muse-minor-modes)
</pre>
<p>And I like publishing to be activated by a single key.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">my-muse-publish</span> ()
  (interactive)
  (muse-publish-file (buffer-file-name) <span style="color:#bc8f8f;">"html"</span>))

(define-key muse-mode-map [f7] 'my-muse-publish)
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/704/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/704/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/704/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/704/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/704/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/704/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/704/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/704/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/704/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/704/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=704&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/07/10/basic-emacsmuse-config/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>Enabling Your Users Part 2</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/02/enabling-yourusers-2/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/07/02/enabling-yourusers-2/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 21:45:55 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs app]]></category>
		<category><![CDATA[file selector]]></category>
		<category><![CDATA[session history]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=695</guid>
		<description><![CDATA[Storing Session History
A little while ago we were talking about writing a little emacs-based application to enable the users to help themselves.  The beginning of this tool needs a light-weight dired using emacs buttons to use for navigating around the filesystem.  Today we will look at adding functionality to remember which files and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=695&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">Storing Session History</h2>
<p>A little while ago we were talking about writing a little emacs-based application to enable the users to help themselves.  The beginning of this tool needs a <a href="http://curiousprogrammer.wordpress.com/2009/06/21/enabling-your-users/">light-weight dired</a> using emacs buttons to use for navigating around the filesystem.  Today we will look at adding functionality to remember which files and directories have been accessed previously.</p>
<p>First of all we need some variables to store the directories and files in.
</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defvar</span> <span style="color:#b8860b;">file-editor-current-dir</span> nil)

(<span style="color:#a020f0;">defvar</span> <span style="color:#b8860b;">file-editor-save-dirs</span> nil)
(<span style="color:#a020f0;">defvar</span> <span style="color:#b8860b;">file-editor-save-dirs</span> '(a b c))
(<span style="color:#a020f0;">defvar</span> <span style="color:#b8860b;">file-editor-save-files</span> nil)
</pre>
<p>Then we provide a customizable variable where the history will be saved between emacs sessions.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defcustom</span> <span style="color:#b8860b;">file-editor-history-file</span> <span style="color:#bc8f8f;">"~/.file-editor-history"</span>
  <span style="color:#bc8f8f;">"File in which the file-editor history is saved between invocations.
Variables stored are: `</span><span style="color:#5f9ea0;">file-editor-save-dirs</span><span style="color:#bc8f8f;">', `</span><span style="color:#5f9ea0;">file-editor-save-files</span><span style="color:#bc8f8f;">'."</span>
  <span style="color:#da70d6;">:type</span> 'string
  <span style="color:#da70d6;">:group</span> 'file-editor)
</pre>
<p>We will frequently be adding the same file and directory into the lists and we don&#8217;t want to get dupes.  I could use a data structure that helps avoid dupes or I could just sort the lists and remove adjacent dupes.  Guess which option I chose.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">remove-dupes</span> (list)
  (<span style="color:#a020f0;">let</span> (tmp-list head)
    (<span style="color:#a020f0;">while</span> list
      (setq head (pop list))
      (<span style="color:#a020f0;">unless</span> (equal head (car list))
        (push head tmp-list)))
    (reverse tmp-list)))

(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-sort-history</span> ()
  (setq file-editor-save-dirs
        (remove-dupes (sort file-editor-save-dirs #'string&lt;)))
  (setq file-editor-save-files
        (remove-dupes (sort file-editor-save-files #'string&lt;))))
</pre>
<p><strong>ido</strong> has code that stores history between sessions.  I&#8217;ve stolen most of it to save the file editor history.  <code style="font-size:130%;background:#eee;padding:3px;">(ido-pp ...)</code> pretty prints the variable contents into the buffer, e.g. something like this.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
;; ----- file-editor-save-dirs -----

( <span style="color:#bc8f8f;">"dir1"</span> <span style="color:#bc8f8f;">"dir2"</span> <span style="color:#bc8f8f;">"dir3"</span> )
</pre>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">require</span> '<span style="color:#5f9ea0;">ido</span>)

(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-save-history</span> ()
  <span style="color:#bc8f8f;">"Save file-editor history between sessions."</span>
  (<span style="color:#a020f0;">let</span> ((buf (get-buffer-create <span style="color:#bc8f8f;">" *file-editor data*"</span>))
        (version-control 'never))
    (<span style="color:#a020f0;">unwind-protect</span>
        (<span style="color:#a020f0;">with-current-buffer</span> buf
          (erase-buffer)
          (file-editor-sort-history)
          (ido-pp 'file-editor-save-dirs)
          (ido-pp 'file-editor-save-files)
          (write-file file-editor-history-file nil))
      (kill-buffer buf))))
</pre>
<p>When it comes time to load the history back, <code style="font-size:130%;background:#eee;padding:3px;">(read (current-buffer))</code> loads it back into the variables.  You can see the use of <code style="font-size:130%;background:#eee;padding:3px;">unwind-protect</code> and <code style="font-size:130%;background:#eee;padding:3px;">condtion-case</code> in the code below as I talked about in my <a href="http://curiousprogrammer.wordpress.com/2009/06/08/error-handling-in-emacs-lisp/">emacs lisp error handling</a> post.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-load-history</span> ()
  (<span style="color:#a020f0;">let</span> ((file (expand-file-name file-editor-history-file)) buf)
    (<span style="color:#a020f0;">when</span> (file-readable-p file)
      (<span style="color:#a020f0;">let</span> ((buf (get-buffer-create <span style="color:#bc8f8f;">" *file-editor data*"</span>)))
        (<span style="color:#a020f0;">unwind-protect</span>
            (<span style="color:#a020f0;">with-current-buffer</span> buf
              (erase-buffer)
              (insert-file-contents file)
              (<span style="color:#a020f0;">condition-case</span> nil
                  (setq file-editor-save-dirs (read (current-buffer))
                        file-editor-save-files (read (current-buffer)))
                (<span style="color:#ff0000;font-weight:bold;">error</span> nil)))
          (kill-buffer buf))))))
</pre>
<p>The obvious time to save the history is when we exit emacs.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-kill-emacs-hook</span> ()
  (file-editor-save-history))

(add-hook 'kill-emacs-hook 'file-editor-kill-emacs-hook)
</pre>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">Modifications To The Original Code</h2>
<p class="first">
The way we choose which files and directories will be remembered is each time a file is opened, the parent directory and the file including full path are added to the appropriate variable.
</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-open-file-editor-file</span> (button)
  (<span style="color:#a020f0;">let</span> ((parent (button-get button 'parent))
        (file (button-get button 'file))
        (file-complete (concat parent <span style="color:#bc8f8f;">"/"</span> file)))
    <span style="background:#dd9999;">(push parent file-editor-save-dirs)        </span>
    <span style="background:#dd9999;">(push file-complete file-editor-save-files)</span>
    (find-file file-complete)
    (file-editor-mode)
    (longlines-mode 1)))
</pre>
<p>We need to extend the <code style="font-size:130%;background:#eee;padding:3px;">file-editor-default-dirs</code> function to display the previously stored directories and files.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-default-dirs</span> ()
  (<span style="color:#a020f0;">let</span> ((buffer (get-buffer-create <span style="color:#bc8f8f;">"*file-editor-dir-list*"</span>)))
    (<span style="color:#a020f0;">with-current-buffer</span> buffer
      (<span style="color:#a020f0;">let</span> ((inhibit-read-only t))
        (erase-buffer)
        (file-editor-sort-history)

        (insert <span style="color:#bc8f8f;">"*** Default File List ***\n\n"</span>)

        (<span style="color:#a020f0;">dolist</span> (dir file-editor-default-dirs)
          (file-editor-insert-opendir-button <span style="color:#bc8f8f;">""</span> dir))

        (<span style="color:#a020f0;">when</span> file-editor-save-dirs
          (insert <span style="color:#bc8f8f;">"\n"</span>)
          (<span style="color:#a020f0;">dolist</span> (dir file-editor-save-dirs)
            (file-editor-insert-opendir-button <span style="color:#bc8f8f;">""</span> dir)))

        (<span style="color:#a020f0;">when</span> file-editor-save-files
          (insert <span style="color:#bc8f8f;">"\n"</span>)
          (<span style="color:#a020f0;">dolist</span> (file file-editor-save-files)
            (insert-text-button file 'parent <span style="color:#bc8f8f;">""</span> 'file file
                                <span style="color:#da70d6;">:type</span> 'open-file-editor)))))))
</pre>
<p>And for some future functionality I am thinking about we also store the current directory that is being visited.</p>
<pre style="font-size:130%;border:1px solid #bbb;overflow:auto;background:#eee;margin:15px 5px;padding:5px;">
(<span style="color:#a020f0;">defun</span> <span style="color:#0000ff;">file-editor-dir-list</span> (parent)
  (<span style="color:#a020f0;">let</span> ((buffer (get-buffer-create <span style="color:#bc8f8f;">"*file-editor-dir-list*"</span>)))
    (<span style="color:#a020f0;">with-current-buffer</span> buffer
      (<span style="color:#a020f0;">let</span> ((inhibit-read-only t) files dirs)
        (setq parent (expand-file-name parent))
        <span style="background:#dd9999;">(setq file-editor-current-dir parent)</span>
        (erase-buffer)
        <span style="color:#b22222;">;; </span><span style="color:#b22222;">...
</span>))))
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/695/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/695/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/695/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/695/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/695/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/695/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/695/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/695/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/695/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/695/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=695&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/07/02/enabling-yourusers-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>Interesting Emacs Links &#8211; 2009 Week 25</title>
		<link>http://curiousprogrammer.wordpress.com/2009/06/28/emacs-links-2009-25/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/06/28/emacs-links-2009-25/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 15:30:44 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs links]]></category>
		<category><![CDATA[emacs news]]></category>
		<category><![CDATA[emacs tips]]></category>
		<category><![CDATA[org mode]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=692</guid>
		<description><![CDATA[Org Mode
The wonderful Org mode has deservedly been getting a lot of [word] press recently.  This is a really great tutorial.  There is a nice customization guide at orgmode.org.  endperform talks about using it for time tracking and remembering useful tricks.  Emacs-fu has an article on generating html with org-mode.  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=692&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">Org Mode</h2>
<p>The wonderful Org mode has deservedly been getting a lot of <em>[word]</em> press recently.  <a href="http://doc.norang.ca/org-mode.html">This</a> is a really great tutorial.  There is a nice <a href="http://orgmode.org/worg/org-customization-guide.php">customization guide</a> at orgmode.org.  <a href="http://www.endperform.org/2009/06/16/life-with-emacs-org-mode/">endperform</a> talks about using it for time tracking and remembering useful tricks.  Emacs-fu has <a href="http://emacs-fu.blogspot.com/2009/05/writing-and-blogging-with-org-mode.html">an article</a> on generating html with org-mode.  ByteBaker talks about <a href="http://bytebaker.com/2009/06/26/software-to-keep-your-pdfs-and-papers-organized/">using it</a> to organise papers he downloaded and to <a href="http://bytebaker.com/2009/06/23/too-many-formats/">make a wiki</a>.</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">My Emacs Posts</h2>
<p>I&#8217;ve started a series about a <a href="http://curiousprogrammer.wordpress.com/2009/06/21/enabling-your-users/">light-weight alternative to dired mode</a>.  Part two, which will remember locations you have visited previously is on the way.</p>
<p>A quick mention of <a href="http://curiousprogrammer.wordpress.com/2009/06/17/longlines-mode/">longlines-mode</a> got <a href="http://curiousprogrammer.wordpress.com/2009/06/17/longlines-mode/#comment-7683">a comment</a> about <code style="font-size:130%;background:#eee;padding:3px;">visual-line-mode</code> which is the replacement in Emacs 23 onwards.  I&#8217;ve switched over and it does seem better.  longlines-mode was fairly reliable, but occasionally it would forget that it was supposed to be wrapping words and I would need to disable it and enable it.</p>
<h2 style="color:#080;background-color:#eee;margin:0;padding:5px 5px 5px 15px;">Other Emacs Posts</h2>
<p>alieniloquent talks about <a href="http://blog.alieniloquent.com/2009/06/25/an-example-of-defadvice-in-emacs/">using advice</a> to disable other window is you use the universal prefix (<code style="font-size:130%;background:#eee;padding:3px;">C-u</code>).  Nice trick.</p>
<p>Aneesh Kumar has post on switching from <a href="http://aneesh-kumar.blogspot.com/2009/06/switching-from-vim-to-emacs.html">vim to emacs</a>, or actually viper.  As I use vim a lot, I&#8217;ve tried viper in the past but I always found that it made accessing various emacs commands harder (or maybe just different) than it is in vanilla emacs so I always switched back.</p>
<p><a href="http://www.arminsadeghi.com/slickedit_and_emacs">Armin Sadeghi</a> says that his two favourite editors are SlickEdit and Emacs.</p>
<blockquote><p>
The big difference between SlickEdit and Emacs is that SlickEdit is commercial software and Emacs is open source.
</p></blockquote>
<p>If that is the big difference, why not just use Emacs?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/692/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/692/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/692/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/692/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/692/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=692&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/06/28/emacs-links-2009-25/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
		<item>
		<title>The Real World versus BlogWorld</title>
		<link>http://curiousprogrammer.wordpress.com/2009/06/23/real-world/</link>
		<comments>http://curiousprogrammer.wordpress.com/2009/06/23/real-world/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 20:35:57 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[real world constraints]]></category>

		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=689</guid>
		<description><![CDATA[In the real world

we don&#8217;t get to choose Ruby just because we want to
we don&#8217;t have time to implement perfect solutions
we don&#8217;t go back and fix ugly but working code
the second law of thermodynamics always holds
copy/paste and singleton are not the root of all evil
Java/C++/Perl are not dying
we still need to write code that works [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=689&subd=curiousprogrammer&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In the real world</p>
<ul>
<li>we don&#8217;t get to choose Ruby just because we want to</li>
<li>we don&#8217;t have time to implement perfect solutions</li>
<li>we don&#8217;t go back and fix ugly but working code</li>
<li>the second law of thermodynamics always holds</li>
<li>copy/paste and singleton are not the root of all evil</li>
<li>Java/C++/Perl are not dying</li>
<li>we still need to write code that works in IE</li>
<li>for most programmers IDEs are better than emacs or vim</li>
<li>two journeyman programmers are better than one rockstar</li>
</ul>
<p>And in blogworld bloggers often forget that the plural of anecdote is not data.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/curiousprogrammer.wordpress.com/689/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/curiousprogrammer.wordpress.com/689/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/curiousprogrammer.wordpress.com/689/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/curiousprogrammer.wordpress.com/689/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/curiousprogrammer.wordpress.com/689/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/curiousprogrammer.wordpress.com/689/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/curiousprogrammer.wordpress.com/689/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/curiousprogrammer.wordpress.com/689/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/curiousprogrammer.wordpress.com/689/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/curiousprogrammer.wordpress.com/689/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=curiousprogrammer.wordpress.com&blog=367204&post=689&subd=curiousprogrammer&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://curiousprogrammer.wordpress.com/2009/06/23/real-world/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5f74091ba22c3b3205a72d70b42abfa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Jared</media:title>
		</media:content>
	</item>
	</channel>
</rss>