<?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/"
	>

<channel>
	<title>Atomized &#187; lisp</title>
	<atom:link href="http://atomized.org/tag/lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://atomized.org</link>
	<description>Fragmenting reality.</description>
	<lastBuildDate>Mon, 23 May 2011 23:46:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Brief updates on Elisp projects</title>
		<link>http://atomized.org/2009/06/brief-updates-on-elisp-projects/</link>
		<comments>http://atomized.org/2009/06/brief-updates-on-elisp-projects/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 23:25:05 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=569</guid>
		<description><![CDATA[I’m behind on my twit.el fork. Some of my changes got rolled in to mainline, but many didn’t, and this led to a merge nightmare. I’m wiping out what I did and starting over. I also need to figure out if there’s a way to line wrap variable-width fonts, since auto-fill doesn’t seem to work [...]]]></description>
			<content:encoded><![CDATA[<p>I’m behind on <a href="https://github.com/ieure/twit-el/tree">my twit.el fork</a>. Some of my changes got rolled in to mainline, but many didn’t, and this led to a merge nightmare. I’m wiping out what I did and starting over. I also need to figure out if there’s a way to line wrap variable-width fonts, since auto-fill doesn’t seem to work quite right.</p>
<p>I <a href="https://github.com/ieure/php-mode-el/tree">forked</a> <a href="http://php-mode.sourceforge.net/">php-mode</a>. I don’t have anything major planned, but I fixed the fontification of docblock comments.</p>
<p>I <a href="http://github.com/ieure/test-case-mode/blob/cacba6a3d524c75baa6315fce5df87a8496d12dd/test-case-phpunit.el">added</a> <a href="http://phpunit.de/">PHPUnit</a> support to <a href="http://github.com/ieure/test-case-mode/tree/master">test-case-mode</a>. Consider <a href="https://github.com/ieure/phpunit-el/tree">phpunit-el</a> deprecated.</p>
<p>There are a couple things missing vs. phpunit-el, some of which may need some changes to test-case-mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/06/brief-updates-on-elisp-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Emacs 23: Easier directory-local variables</title>
		<link>http://atomized.org/2009/05/emacs-23-easier-directory-local-variables/</link>
		<comments>http://atomized.org/2009/05/emacs-23-easier-directory-local-variables/#comments</comments>
		<pubDate>Wed, 06 May 2009 00:12:48 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[directory-local-variables]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=554</guid>
		<description><![CDATA[I’ve been using directory-local-variables for a while now, and written about them before I currently have two problems with DLV: It takes a lot of code to set anything. Here’s a very simple example that makes all files opened under a subdirectory read-only: (dir-locals-set-class-variables 'read-only '((nil . ((buffer-read-only t))))) (dir-locals-set-directory-class "~/Library/Preferences" 'read-only nil) Many of [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been using directory-local-variables for a while now, and <a href="http://atomized.org/2009/01/emacs-23-directory-local-variables/">written about them before</a></p>
<p>I currently have two problems with DLV:</p>
<ol>
<li>It takes a lot of code to set anything. Here’s a very simple example that makes all files opened under a subdirectory read-only:
<pre language="emacs-lisp">
(dir-locals-set-class-variables 'read-only
                                '((nil . ((buffer-read-only t)))))
(dir-locals-set-directory-class "~/Library/Preferences" 'read-only nil)
    </pre>
</li>
<li>Many of my variables need to be set to paths of files within the base directory. As an example, <code>phpunit-program</code> needs to be <code>$ROOT/bin/phpunit</code>. This doesn’t map well onto the class/directory split of DLV; I have to define a class for every directory, since the values are dependent on the path. You also end up duplicating a lot of long paths inside the directory-class.</li>
</ol>
<p>Here’s my current solution, <code>dir-locals</code>.</p>
<pre language="emacs-lisp">
(defmacro absolute-dirname (path)
  "Return the directory name portion of a path.

If PATH is local, return it unaltered.
If PATH is remote, return the remote diretory portion of the path."
  `(cond ((tramp-tramp-file-p ,path)
          (elt (tramp-dissect-file-name ,path) 3))
         (t ,path)))

(defmacro dir-locals (dir vars)
       "Set local variables for a directory.

DIR is the base diretory to set variables on.

VARS is an alist of variables to set on files opened under DIR,
in the same format as `dir-locals-set-class-variables' expects."
       `(let ((name (intern (concat "dir-locals-"
                                    ,(md5 (expand-file-name dir)))))
              (base-dir ,dir)
              (base-abs-dir ,(absolute-dirname dir)))
          (dir-locals-set-class-variables name ,vars)
          (dir-locals-set-directory-class ,dir name nil)))
</pre>
<p>It takes two arguments, a directory and a list of variables. The directory-class is autogenerated, so you don’t need to worry about it. Here’s how you’d use it:</p>
<pre language="emacs-lisp">
(dir-locals "~/Projects/hello-world"
            '((nil . ((user-mail-address . "ian@foo.com")))))
</pre>
<p><em>Much</em> better.</p>
<p>Within your varible list, you have two special variables you can use: <code>base-dir</code> and <code>base-abs-dir</code>. These contain the root of the directory the variables apply to, and the local directory part of that, respectively.</p>
<p>We need this because of the way Emacs invokes processes. If you’re visiting a remote file, Emacs will spawn external processes on the remote system. To set a DLV for a remote file, the root needs to be in the form <code>/ssh:user@host:/path/to/root</code>. If you try to invoke a program like that, it won’t work; you need just the directory part of the path, and this is what’s available in <code>base-abs-dir</code>.</p>
<p>On the other hand, if you want per-project TAGS files, you’ll need the full path to the remote system.</p>
<p> Here’s how you’d use it:</p>
<pre langauge="emacs-lisp">
(dir-locals "~/Projects/hello-world"
            `((nil . ((user-mail-address . "ian@foo.com")
                      (tags-table-list . '(,(concat base-dir "/TAGS.gz")))))
              (php-mode . ((phpunit-program . ,(concat base-abs-dir
                                                       "/bin/phpunit"))))))
</pre>
<p>The important thing to note here is the different syntax used for the variables. Rather than using a regular quote, we use a backquote, and a comma where the special variables are used.</p>
<p>And that’s that. Now I have one-(or two-)line setting of variables, with access to the base directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/05/emacs-23-easier-directory-local-variables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Disabling Python-mode’s skeletons</title>
		<link>http://atomized.org/2009/01/disabling-python-mode%e2%80%99s-skeletons/</link>
		<comments>http://atomized.org/2009/01/disabling-python-mode%e2%80%99s-skeletons/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 20:59:43 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[abbrev]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[skeleton]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=498</guid>
		<description><![CDATA[One of the few things I dislike about Emacs 23 is the new behavior of python-mode. When you type things like def, it expands these into snippets using abbrev-mode. I don’t like this because I have similar functionality by way of yasnippet. I prefer the yasnippet way because it uses fields in the snippet. The [...]]]></description>
			<content:encoded><![CDATA[<p>One of the few things I dislike about <a href="/wp-content/cocoa-emacs-nightly">Emacs 23</a> is the new behavior of <code>python-mode</code>. When you type things like <code>def</code>, it expands these into snippets using <code>abbrev-mode</code>. I don’t like this because I have similar functionality by way of <a href="http://code.google.com/p/yasnippet/">yasnippet</a>.</p>
<p>I prefer the yasnippet way because it uses fields in the snippet. The default way prompts you for values in the minibuffer with <code>read-string</code>, which I dislike. It also overrides my preferred behavior, and there’s no option to disable it.</p>
<p>Of course, there’s always a way in Emacs, and it can be removed with this code:</p>
<pre language="lisp">
(let (python-mode-abbrev-table)
  (require 'python))
</pre>
<p>Which is simple and works, though I dislike it. I prefer to tweak behaviors with <code>eval-after-load</code>, since <code>require</code>s can be slow. Unfortunately, by the time that code executes, the damage is done.</p>
<p>I’ll update if I find a better way to fix it.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/01/disabling-python-mode%e2%80%99s-skeletons/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why Lisp is Awesome</title>
		<link>http://atomized.org/2009/01/why-lisp-is-awesome/</link>
		<comments>http://atomized.org/2009/01/why-lisp-is-awesome/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 00:52:43 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=475</guid>
		<description><![CDATA[A few weeks ago, I was talking to some people about the nerdy things I work on, and the nerdy things I like. The conversation inevitably turned to Emacs and Lisp, and someone asked why I liked them so much. There are a lot of reasons, but I think the main one is that it’s [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I was talking to some people about the nerdy things I work on, and the nerdy things I like. The conversation inevitably turned to Emacs and Lisp, and someone asked why I liked them so much.</p>
<p>There are a lot of reasons, but I think the main one is that it’s such a pioneering and influential language, and most people aren’t aware of it. An astonishing number of language features we take for granted owe their existence to Lisp.</p>
<ul>
<li><b>The switch statement</b>. In lisp, this works like so:
<pre language="lisp">
(cond
    ((= var "foo")
     (message "This is the foo block."))
    ((= var "bar")
     (message "This is the bar block."))
    (t
     (message "Default case")))
</pre>
<p>This is equivalent to the following code in C:</p>
<pre language="c">
switch (var) {
    case "foo":
        printf("foo block.");
        break;

    case "bar":
        printf("bar block.");
        break;

    default:
        printf("Default case")
}
</pre>
<p>As you can see, they both have advantages and disadvantages:</p>
<ul>
<li>The lisp version is more succinct.</li>
<li>In lisp, you can test for any condition, whereas <del datetime="2010-01-07T00:56:33+00:00">C only lets you test one expression. This is a wash, since if you want multiple tests on the same expression, you have to repeat it throughout the <code>(cond)</code>.</del></li>
<li>There’s no way to fall through in lisp like there is in C.</li>
<li><del datetime="2010-01-07T00:56:33+00:00">…But, your condition can be an expression in Lisp, rather than a simple test for equality, so your condition could be <code>(cond (or "foo" "bar"))</code></del></li>
<li><ins datetime="2010-01-07T00:56:33+00:00">As a commenter points out, you can use <code>switch(true)</code> to test more complex expressions in your <code>case</cond>s. While this works, it feels pretty hacky.</ins></li>
</ul>
</li>
<li><b>Lambda functions.</b> One of the fundamental building blocks of Lisp, lambdas have gained widespread adoption in modern languages like JavaScript, PHP, Python, Perl, Visual Basic, Ruby, and C#.</li>
<li>Hand in hand with lambdas, <b>functions are data.</b> That is, you can pass a function to another function. A function can return a function. Using lambdas, a function can create an entirely new function, return it, and it may be passed to yet another function.</li>
<li><b>Closures.</b> In a nutshell, closures give you a private, inherited namespace. So if your parent closure defines a variable <code>x = 5</code>, and you create a closure inside it, you also can see that <code>x = 5</code>. If your closure changes that to <code>x = 50</code>, that is invisible to your parent closure, but visible (in the same way) to any closures that closure creates. Essentially, it’s a private copy-on-write namespace. Closures were first implemented in Scheme, a Lisp-descended language. Before that, the <code>let</code> expressions gave some of the flexibility of closures.
<pre language="lisp">
(defun print-foo ()
    (message foo))

(setq foo "Foo")
;; Calling (print-foo) will print "Foo".

;; Inside the let block, 'foo is changed to "bar".
;; Evaluating this prints "Bar".
(let ((foo "Bar"))
    (print-foo))

;; This prints "Foo" again
(print-foo)
</pre>
</li>
<li><b>Dynamic programming.</b> With <code>fset</code>, you can change any function. Common Lisp adds <code>flet</code>, which works the same as <code>let</code>, but on functions. So you can change how library code works at an extremely deep level, but keep those changes out of the way of other code which expects the stock behavior.</li>
<li><b>Data is code.</b> This is an extremely powerful concept, and it’s been seen more recently in JSON. The basic idea is that you leverage the language parser to parse complex data structures, rather than writing your own parser.
<pre language="lisp">
'((item-one . (foo bar ))
  (item-two . (baz quux)))
</pre>
<p>This is equavalent to</p>
<pre language="javascript">
{
    "item-one": ["foo" "bar"],
    "item-two": ["baz" "quux"]
}
</pre>
<p>In other words, your data is expressed in the same literal notation as if it was in your code.</li>
<li><b>And-or trick.</b> At least Python and Ruby have copied this feature. In Lisp, boolean expressions don’t evaluate to true or false; rather, they evaluate to the portion of the expression causing the test to pass or fail. This sounds much more complicated than it really is. Here’s are some sample expressions:
<pre language="c">
0 || 99;
</pre>
<p>In C, this will return <code>TRUE</code>; The zero is considered false, and non-zero is true. Since the condition is true, true is returned.</p>
<pre language="lisp">
(or nil 99)
</pre>
<p>The same test in lisp. Rather than return <code>t</code> (Lisp’s equivalent to C’s <code>TRUE</code>), this expression returns <code>99</code>. The value 99 is what caused the expression to terminate, so it’s value is returned.</p>
<p>It’s hard to understand the power of this at first, but consider the case where you want to assign the variable <code>x</code> the value of variable <code>a</code> if it is not false, or <code>b</code> otherwise. In C, you have:</p>
<pre language="c">
if (a) {
    x = a;
} else {
    x = b;
}
</pre>
<p>Not very elegant. You can use the ternary syntax, where it becomes:</p>
<pre language="c">
x = a ? a : b;
</pre>
<p>This is better, but note how you have to repeat the <code>a</code> variable twice. Contrast this with the lisp version:</p>
<pre language="lisp">
(setq x (or a b))
</pre>
<p>No repetition. While it’s actually longer than the C version in this simple example, you gain much benefit when you use more complex expressions, such as ones where you want to assign the return value of a function if it’s true. In C, you’re stuck with calling the method twice, or assigning it’s output to a variable before the test.</p>
<p>In Python, you’d use:</p>
<pre language="python">
x = a or b
</pre>
</li>
<li><b>References.</b> Lisp’s basic data structure is the linked list. What’s interesting is how they’re managed. Lisp lists are constructed from <i>cons cells</i>, where the first half (the <i>car</i>)points to the data for that cell, and the last half (the <i>cdr</i>, pronounced "coulder") points to the next cell; the last cell in the list has a null pointer. The really neat part of this is that <i>everything is a pointer</i>. So every member of a list exists on it’s own, and other lists are free to point to it. Consider this:
<pre language="lisp">
;; This sets 'ex to a two-element list: (foo bar)
(setq ex '(bar baz))

;; This creates a new list 'ey; the first cell is 'foo, and the rest of the
;; list is the contents of 'ex.
;; Evaluating 'ey will show: (foo bar baz)
(setq ey (cons 'foo ex))

;; This sets the first element of 'ex to quux
(setcar ex 'quux)

;; Evaluating ex now produces: (quux bar)
;; Evaluating ey produces: (foo quux bar)
    </pre>
<p>This works because ey’s cdr points to ex; it hasn’t copied ex, it’s incorporated it by reference.
    </li>
</ul>
<p>So there you have a short tour of what’s cool about Lisp, and the features you’re using that you owe to it. Not all of these features were in the earliest version of Lisp, but it’s quite a feat that so many advanced high-level language features first appeared there. <a href="http://www-formal.stanford.edu/jmc/recursive.html">The original paper on Lisp</a> is still quite relevant, and shows some of the algorithms you can implement with the earliest parts of the language.</p>
<p>I don’t mean to bash on C here; I actually really like C for what it is. And it’s not unlike Lisp in that it’s a highly influential language with an extremely simple core.</p>
<p>What’s fascinating to me about Lisp is that a language which is fifty years old is was so advanced, and is <i>still</i> so influential. In the fast-moving world of computing, that’s truly an amazing accomplishment.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/01/why-lisp-is-awesome/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Emacs Archaeology</title>
		<link>http://atomized.org/2008/12/emacs-archaeology/</link>
		<comments>http://atomized.org/2008/12/emacs-archaeology/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 07:47:44 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[its]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[teco]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=469</guid>
		<description><![CDATA[I’ve been digging through the history of Emacs and Lisp lately. Getting back to my roots, as it were. I read the original paper on Lisp, from all the way back in 1960. It continues to amaze me how much life is left in those old ideas of Lisp. I also turned up this Emacs [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been digging through the history of Emacs and Lisp lately. Getting back to my roots, as it were. I read <a href="http://www-formal.stanford.edu/jmc/recursive.html">the original paper on Lisp</a>, from all the way back in 1960. It continues to amaze me how much life is left in those old ideas of Lisp.</p>
<p>I also turned up this <a href="http://agave.garden.org/~aaronh/gnu/emacs/doc/emacs-1978.html">Emacs manual</a>, circa 1978, from when Emacs was written in TECO and running under ITS on the PDP-10. The two major differences seem to be use of <code>M-M-</code> to execute commands (<code>M-x</code> in modern Emacs) and command names being more verbose, such as <code>Query Replace</code> instead of <code>query-replace</code>. Other than that, most of the commands are the same and still work. Lots of the stuff you’d expect in a modern Emacs were there: Dired, major modes, interactive help, regexp search.</p>
<p>I even found a useful command I didn’t know.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/12/emacs-archaeology/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Run MacPorts inside Emacs</title>
		<link>http://atomized.org/2008/12/run-macports-inside-emacs/</link>
		<comments>http://atomized.org/2008/12/run-macports-inside-emacs/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 20:19:10 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[macports]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=458</guid>
		<description><![CDATA[While I find certain aspects of MacPorts objectionable, many of it’s ports are indispensible. Having switched to the Mac from Debian, I really miss the GNU tools. In particular, find and the color available in GNU ls. MacPorts makes it easy and clean to install GNU coreutils &#38; findutils, overriding the system commands. MacPorts has [...]]]></description>
			<content:encoded><![CDATA[<p>While I find certain aspects of <a href="http://macports.org">MacPorts</a> <a href="http://atomized.org/2008/09/the-thing-i-hate-about-macports/">objectionable</a>, many of it’s ports are indispensible. Having switched to the Mac from <a href="http://debian.org">Debian</a>, I really miss the GNU tools. In particular, <a href="http://www.gnu.org/software/findutils/">find</a> and the color available in <a href="http://www.gnu.org/software/coreutils/manual/html_node/ls-invocation.html#ls-invocation">GNU ls</a>. MacPorts makes it easy and clean to install GNU coreutils &amp; findutils, overriding the system commands.</p>
<p>MacPorts has a convenient interactive mode for when you want to work with ports. As with all things, I find it even more convenient to use inside of Emacs. So I whipped up this function which does just that.</p>
<pre language="lisp">
(defun run-port (arg)
  "Run the `port' (MacPorts) command.
If PREFIX is specified, run the command as root."
  (interactive "P")
  (let ((default-directory (cond (arg "/sudo::/") ("~"))))
    (comint-run "/opt/local/bin/port")))
</pre>
<p>While the interactive mode is nice, there’s no way (that I know of) to install stuff unless you run it as root. This isn’t such a good thing to do if you just want to poke around. So you can run it either way; a plain invocation runs it as the current user, but if you supply a prefix argument, it will run as root. This requires <a href="http://atomized.org/2008/12/cocoa-emacs-23-nightly-cvs-builds/">Emacs 23</a>, which is smart enough to execute stuff through Tramp when <code>default-directory</code> is non-local.</p>
<p>As always, feedback to <code>ian (dot) eure {at} gmail -dot- com</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/12/run-macports-inside-emacs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpunit.el: A PHPUnit interface for Emacs</title>
		<link>http://atomized.org/2008/12/phpunitel-a-phpunit-interface-for-emacs/</link>
		<comments>http://atomized.org/2008/12/phpunitel-a-phpunit-interface-for-emacs/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 22:33:04 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[phpunit-el]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=445</guid>
		<description><![CDATA[Here at Digg, we’re getting unit testing religion. We had some older code which had PHPT coverage, but we’ve moved to PHPUnit as our test platform. I’ve been writing a lot of unit tests lately. In fact, I’ve written more test code than non-test code. So I’ve natually been running phpunit fifty times a day, [...]]]></description>
			<content:encoded><![CDATA[<p>Here at <a href="http://digg.com/">Digg</a>, we’re getting unit testing religion. We had some older code which had PHPT coverage, but we’ve moved to <a href="http://phpunit.de">PHPUnit</a> as our test platform.</p>
<p>I’ve been writing <i>a lot</i> of unit tests lately. In fact, I’ve written more test code than non-test code. So I’ve natually been running <code>phpunit</code> fifty times a day, to the point where I started wishing I had a better way to test. There wasn’t, so I <i>had no choice</i> but to write one.</p>
<p>Enter <a href="http://github.com/ieure/phpunit-el/tree/master"><code>phpunit.el</code></a>.</p>
<h2>Usage</h2>
<p>Simple use is, well, simple: <code>M-x phpunit-run-test RET</code>. This brings up a command line in the miniuffer for you to enter the command. You can re-run the test with <code>phpunit-run-test-or-retest</code>, or by pressing <code>R</code> in the <code>*phpunit*</code> buffer.</p>
<p>It’s derived from <code>compilation-mode</code>, so <code>C-x `</code> will jump you to the first error listed in the output.</p>
<h2>Customizing</h2>
<p>There are a few options to customize, like the path to the PHPUnit binary, the default arguments, and such. Poke around with <code>M-x customize-group RET phpunit RET</code>.</p>
<p>More advanced features are enabled by customizing <code>phpunit-testable-list</code>, which tells phpunit.el how to map a source file to a test file. It’s format is:</p>
<pre>(
  (SOURCE-REGEX TEST-CLASS TEST-FILE)
  (SOURCE-REGEX TEST-CLASS TEST-FILE)
  …
)</pre>
<p>Which is to say, if a source file matches <code>SOURCE-REGEX</code>, the name of the unit test class is <code>TEST-CLASS</code> and the path to the file it exists in is <code>TEST-FILE</code>.</p>
<p>Some features and functions depend on this, notably <code>phpunit-test-this</code> and <code>phpunit-find-test-file</code>.</p>
<p>If you open a PHP file and a corresponding test file is found, the <code>phpunit-minor-mode</code> is enabled, as indicated by &#8220;Test&#8221; in the modeline. This turns on a few bindings to help you run your tests.</p>
<h2>Minor Mode Bindings</h2>
<ul>
<li><code>C-c C-l r</code> <code>(phpunit-run-test-or-retest)</code> – Run a test, or re-run the last test.</li>
<li><code>C-c C-l f</code> <code>(phpunit-find-test-file)</code> – Open the unit test corresponding to the currently viewed source.</li>
<li><code>C-c C-l t</code> <code>(phpunit-test-this)</code> – Run the test associated with this source.</li>
</ul>
<h2>Code</h2>
<p>The code is under the GPL3, and <a href="http://github.com/ieure/phpunit-el/">it’s available at GitHub</a>. It’s still a work in progress. Feel free to drop me a line if you have problems or patches.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/12/phpunitel-a-phpunit-interface-for-emacs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Emacs: Create directory before saving</title>
		<link>http://atomized.org/2008/12/emacs-create-directory-before-saving/</link>
		<comments>http://atomized.org/2008/12/emacs-create-directory-before-saving/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 18:36:21 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[find-file]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[make-directory]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=435</guid>
		<description><![CDATA[Creating a new file in Emacs is as easy as opening it. If you ask Emacs to open a file which doesn’t exist, it won’t complain; It will open up a blank buffer pointing at it. It will even let you open a file in a directory that doesn’t exist (yet). If you do this, [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a new file in Emacs is as easy as opening it. If you ask Emacs to open a file which doesn’t exist, it won’t complain; It will open up a blank buffer pointing at it. It will even let you open a file in a directory that doesn’t exist (yet).</p>
<p>If you do this, Emacs will let you know, by displaying this message:</p>
<pre>
Use M-x make-directory RET RET to create the directory and its parents
</pre>
<p>Which is handy… but wouldn’t it be nice if we didn’t even have to do that? This being Emacs, we don’t.</p>
<pre language="lisp">
(add-hook 'before-save-hook
          '(lambda ()
             (or (file-exists-p (file-name-directory buffer-file-name))
                 (make-directory (file-name-directory buffer-file-name) t))))
</pre>
<p>If you add that to your <code>.emacs</code>, you won’t have to. When you save your buffer, Emacs will check to see if the path exists. If it doesn’t, it will create it for you, including any parent directories.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/12/emacs-create-directory-before-saving/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Enhancing Emacs’ SQL Mode</title>
		<link>http://atomized.org/2008/10/enhancing-emacs%e2%80%99-sql-mode/</link>
		<comments>http://atomized.org/2008/10/enhancing-emacs%e2%80%99-sql-mode/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 20:04:22 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql-mode]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=370</guid>
		<description><![CDATA[I use sql-mode a lot. It’s incredibly handy to have my abbrevs and Emacs bindings available when I’m interacting with SQL servers. But there’s always room for improvement, so I’ve identified a few areas where sql-mode could work a bit better, and fixed them. Better Buffer Naming I found this code somwhere a while back, [...]]]></description>
			<content:encoded><![CDATA[<p>I use <code>sql-mode</code> a lot. It’s incredibly handy to have my abbrevs and Emacs bindings available when I’m interacting with SQL servers. But there’s always room for improvement, so I’ve identified a few areas where <code>sql-mode</code> could work a bit better, and fixed them.</p>
<h2>Better Buffer Naming</h2>
<p>I found this code somwhere a while back, and threw in some enhancements:</p>
<ol>
<li>If <code>sql-name</code> is set, that is used in the buffer name, e.g. “*SQL sql-name*”</li>
<li>Otherwise, the name will include the hostname of <code>sql-server</code> and <code>sql-database</code>. If <code>sql-server</code> is an IP address, it’s used; if it’s a DNS name, the hostname part is used. e.g. “*SQL: dbhost/dbname*” or “*SQL 192.168.0.1/dbname”</li>
</ol>
<pre>
(defun sql-make-smart-buffer-name ()
  "Return a string that can be used to rename a SQLi buffer.

This is used to set `sql-alternate-buffer-name' within
`sql-interactive-mode'."
  (or (and (boundp 'sql-name) sql-name)
      (concat (if (not(string= "" sql-server))
                  (concat
                   (or (and (string-match "[0-9.]+" sql-server) sql-server)
                       (car (split-string sql-server "\\.")))
                   "/"))
              sql-database)))

(add-hook 'sql-interactive-mode-hook
          (lambda ()
            (setq sql-alternate-buffer-name (sql-make-smart-buffer-name))
            (sql-rename-buffer)))
</pre>
<h2>Support for TCP Ports</h2>
<p>At Digg, we have a lot of databases. As <a href="http://blog.digg.com/?p=213">you may have read</a>, we have four main pools of databases. Each of these has one write master and several slaves. We have this setup duplicated in many places for production, development, QA, and so on. While the less-stable environments don’t require the full setup, we try to balance consistency with resource usage. What we’ve settled on is one physical host running four different MySQL instance, one for each pool, each listening on a different port. Unfortunately, <code>sql-mode</code> has no support for this. You can set the <code>sql-*-options</code> variables, but this is cumbersome when you need to quickly connect to servers on different ports.</p>
<p>This simple advice will add <code>sql-port</code> into <code>sql-mysql-options</code>, if it’s set.</p>
<pre>
(defadvice sql-connect-mysql (around sql-mysql-port activate)
  "Add support for connecting to MySQL on other ports"
  (let ((sql-mysql-options (or (and (boundp 'sql-port) sql-port (cons (concat "-P " (or (and (numberp sql-port) (number-to-string sql-port)) sql-port)) sql-mysql-options)) sql-mysql-options)))
    ad-do-it))
</pre>
<p>Currently, this ony works for MySQL. It should be trivial to extend the support for other databases.</p>
<p>This doesn’t get read interactively like the other options, so you’ll have to create a new function with a let binding to connect. This isn’t such a bad thing when you throw in the next enhancement.</p>
<h2>Support for Preset Connections</h2>
<p>It’s not much fun to enter your connection information every time you want to connect. I had some functions which used let expressions to set the correct defaults for connections, but this was suboptimal, since you had to hit RET a bunch of times before the connection would start. This is fixed with preset connections. You define <code>sql-connection-alist</code> with a connection name and a list of sql variables to bind. Then you may call <code>sql-connect-preset</code> with the connection name, and you get your connection immediately.</p>
<p>Note that you can specify <code>sql-port</code> in the connection definition. Also, <code>sql-name</code> is defined to the name of the connection, so you can set the buffer name there, as well.</p>
<p>At some point in the future, it would be a good idea to make an interactive version of <code>sql-connect-preset</code>, which prompts you for one of the defined connections. For now, though, you need to define a function.</p>
<p>Example code:</p>
<pre>
(setq sql-connection-alist
      '((pool-a
         (sql-product 'mysql)
         (sql-server "1.2.3.4")
         (sql-user "me")
         (sql-password "mypassword")
         (sql-database "thedb")
         (sql-port 3306))
        (pool-b
         (sql-product 'mysql)
         (sql-server "1.2.3.4")
         (sql-user "me")
         (sql-password "mypassword")
         (sql-database "thedb")
         (sql-port 3307))))

(defun sql-connect-preset (name)
  "Connect to a predefined SQL connection listed in `sql-connection-alist'"
  (eval `(let ,(cdr (assoc name sql-connection-alist))
    (flet ((sql-get-login (&#038;rest what)))
      (sql-product-interactive sql-product)))))

(defun sql-pool-a ()
  (interactive)
  (sql-connect-preset 'pool-a))
</pre>
<p>Now, you can just run <code>sql-pool-a</code> and get connected right away. Because the buffers have good names, you can easily fire up many connections.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/10/enhancing-emacs%e2%80%99-sql-mode/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Emacs: Open a shell in the current directory</title>
		<link>http://atomized.org/2008/07/emacs-open-a-shell-in-the-current-directory/</link>
		<comments>http://atomized.org/2008/07/emacs-open-a-shell-in-the-current-directory/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 17:11:24 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[comint]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=289</guid>
		<description><![CDATA[One of the thing I often need is a shell in the same directory as a file I’m editing. Emacs doesn’t have a quick way to do this, so I hacked one together. (defun shell-here () "Open a shell in `default-directory'." (interactive) (let ((dir (expand-file-name default-directory)) (buf (or (get-buffer "*shell*") (shell)))) (goto-char (point-max)) (if (not [...]]]></description>
			<content:encoded><![CDATA[<p>One of the thing I often need is a shell in the same directory as a file I’m editing. Emacs doesn’t have a quick way to do this, so I hacked one together.</p>
<pre>
(defun shell-here ()
  "Open a shell in `default-directory'."
  (interactive)
  (let ((dir (expand-file-name default-directory))
        (buf (or (get-buffer "*shell*") (shell))))
    (goto-char (point-max))
    (if (not (string= (buffer-name) "*shell*"))
        (switch-to-buffer-other-window buf))
    (message list-buffers-directory)
    (if (not (string= (expand-file-name list-buffers-directory) dir))
        (progn (comint-send-string (get-buffer-process buf)
                                   (concat "cd \"" dir "\"\r"))
               (setq list-buffers-directory dir)))))
</pre>
<p>I have this bound to <code>C-c !</code>, which is an open global binding. It’s working well for me, though there are some things I’d like to see improved, like the buffer-name comparison used to switch to the shell buffer. It would also be nice if you could specify the directory if you call it with a prefix.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/07/emacs-open-a-shell-in-the-current-directory/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

