<?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>tadhg.com &#187; tech</title>
	<atom:link href="http://tadhg.com/wp/tag/tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://tadhg.com/wp</link>
	<description>Wherein some things Tadhg are discussed</description>
	<lastBuildDate>Thu, 18 Mar 2010 19:19:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Future of Tabletop Games? D&amp;D on the Microsoft Surface</title>
		<link>http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/</link>
		<comments>http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 02:15:35 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[entertainment]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[roleplaying]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2717</guid>
		<description><![CDATA[Microsoft Surface is an advanced touchscreen display built into a table, backed by a fairly advanced suite of software for gesture recognition. I hadn’t seen many compelling uses for this technology&#8230; until SurfaceScapes, a group at the Carnegie-Mellon Entertainment Technology Center, released demos of Surfaces customized to hangle playing miniature-based D&#38;D on them.

I strongly recommend [...]]]></description>
			<content:encoded><![CDATA[<p><a class="reference external" href="http://en.wikipedia.org/wiki/Microsoft_Surface">Microsoft Surface</a> is an advanced touchscreen display built into a table, backed by a fairly advanced suite of software for gesture recognition. I hadn’t seen many compelling uses for this technology&#8230; until <a class="reference external" href="http://www.etc.cmu.edu/projects/surfacescapes/">SurfaceScapes</a>, a group at the <a class="reference external" href="http://en.wikipedia.org/wiki/Entertainment_Technology_Center">Carnegie-Mellon Entertainment Technology Center</a>, released demos of Surfaces customized to hangle playing miniature-based <cite>D&amp;D</cite> on them.<br />
<span id="more-2717"></span><br />
I strongly recommend watching the video of the demos, and reading the commentary and an interview with the project lead:</p>
<ul>
<li><a class="reference external" href="http://blogs.msdn.com/surface/archive/2009/10/19/dungeons-dragons-done-right-on-microsoft-surface.aspx">“Dungeons &amp; Dragons done right on Microsoft Surface”</a>.
</li>
<li><a class="reference external" href="http://blogs.msdn.com/surface/archive/2009/12/08/bringing-d-d-to-microsoft-surface.aspx">“SurfaceScapes Follow-up: Bringing D&amp;D to Microsoft Surface”</a>.
</li>
<li><a class="reference external" href="http://blogs.msdn.com/surface/archive/2009/12/16/new-gameplay-video-with-d-d-on-surface.aspx">“New gameplay video with D&amp;D on Surface”</a>.
</li>
</ul>
<p>Some of it is quite clumsy, but the potential is clearly there. And looks amazing. While this could definitely aid the playing of <cite>D&amp;D</cite>, there are many games that could benefit from this kind of treatment. Specifically, any games that benefit both from having people physically present and that would also benefit from computation and helpful interfaces (yes, I’m looking at you, <cite>Twilight Imperium</cite>) could get a huge boost from this technology.</p>
<p>It’s a long way away from being available or affordable, and probably a long way from being easily modifiable, too. But we don’t seem to be that far from having commonplace enhanced tabletop games. In the meantime, for roleplaying games there’s the <a class="reference external" href="http://www.rptools.net/">RPTools</a> suite—a suite which may well eventually be a big part of an open source tabletop gaming toolset.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/entertainment/" rel="tag">entertainment</a>, <a href="http://tadhg.com/wp/tag/games/" rel="tag">games</a>, <a href="http://tadhg.com/wp/tag/roleplaying/" rel="tag">roleplaying</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/03/08/inkscape/">Inkscape</a> <span class="related-post-date timestamp">Mon 08 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/26/ai-and-games/">AI and Games</a> <span class="related-post-date timestamp">Thu 26 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/03/comments-on-gming-after-a-15-year-hiatus/">Comments on GMing After a 15-Year Hiatus</a> <span class="related-post-date timestamp">Sun 03 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/01/2010-goals/">2010 Goals</a> <span class="related-post-date timestamp">Fri 01 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/22/the-perfect-is-the-enemy-of-the-good-duke-nukem-forever/">The Perfect is the Enemy of the Good: <cite>Duke Nukem Forever</cite></a> <span class="related-post-date timestamp">Tue 22 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/15/rpgs-ive-played/">RPGs I’ve Played</a> <span class="related-post-date timestamp">Tue 15 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some Vim Script Implementation, Testing, and Hackery</title>
		<link>http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/</link>
		<comments>http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 07:50:47 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Jython]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[text editing]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2690</guid>
		<description><![CDATA[As a result of my porting over jEdit (Jython) macros to Vim, I now have a fair amount of (Python) Vim scripts, and have learned some things about how to set up those scripts. I&#8217;ll go through some of that below, and hopefully other people writing Python scripts for Vim will find it useful.

In jEdit, [...]]]></description>
			<content:encoded><![CDATA[<p>As a result of my porting over <a class="reference external" href="http://jedit.org/">jEdit</a> (Jython) macros to <a class="reference external" href="http://www.vim.org/">Vim</a>, I now have a fair amount of (Python) Vim scripts, and have learned some things about how to set up those scripts. I&#8217;ll go through some of that below, and hopefully other people writing Python scripts for Vim will find it useful.<br />
<span id="more-2690"></span><br />
In jEdit, you invoke macros either by selecting them from a menu (clearly unacceptable) or by opening the <a class="reference external" href="http://www.jedit.org/users-guide/action-bar.html">Action Bar</a> (Ctrl-Enter, for me) and then typing the name of the macro, where “name” means the non-extension part of the filename. I put my macro files went in a subdirectory of the macros directory, and there were namespace issues—all macro names had to be unique, and also couldn&#8217;t match any internal jEdit actions. Furthermore, you couldn&#8217;t pass arguments to them. Despite those issues, it was a powerful and quick piece of functionality, and I wanted to make Vim at least match it.</p>
<p>You can put Python directly into Vim script files, but I wanted to do that as minimally as possible. I added a Vim script that would (essentially) include a Python file, and then I had that Python file import from other Python files as necessary. The Python file includes a class, <tt class="docutils literal"><span class="pre">TBase</span></tt>, that contains the functions I want to run; as much code as possible is kept out of those functions and is in other files—files which ideally are individually testable.</p>
<p>To get to those functions from within Vim, I did this:</p>
<pre class="literal-block">
if filereadable($HOME.&quot;/.vim/plugin/tadhg/tadhg.py&quot;)
    pyfile $HOME/.vim/plugin/tadhg/tadhg.py
endif

&quot; Create the commands pointing the Python in tadhg.py:
if !exists(&quot;:T&quot;)
  command! -range -nargs=+ T python tadhgbase = TBase('rs=&lt;line1&gt; rf=&lt;line2&gt;'); tadhgbase('&lt;args&gt;')
endif

nmap &lt;D-CR&gt; :T
</pre>
<p>That code goes in a Vim script that goes in <tt class="docutils literal"><span class="pre">~/.vim/plugins/tadhg/</span></tt>; it&#8217;s loaded when Vim is. This means that the code in <tt class="docutils literal"><span class="pre">tadhg.py</span></tt> is evaluated at Vim start, so the <tt class="docutils literal"><span class="pre">TBase</span></tt> class is available. Furthermore the user Ex mode command “T” creates a new instance of <tt class="docutils literal"><span class="pre">TBase</span></tt> and then calls it with whatever the user enters after “T”. Finally, Command-Enter is mapped to enter Ex mode and type “T ”, which is quite close indeed to the jEdit functionality I had, but without the disadvantages. I have much more control over the namespace, and I can pass arguments.</p>
<p>When the T command is invoked, a new <tt class="docutils literal"><span class="pre">TBase</span></tt> instance is created and it gets passed the range start and range end line numbers from Vim, which is pretty important for some of the functions. Then the new instance is called, with the argument of whatever was typed after “T ”.</p>
<p>This is the code for handling that latter aspect:</p>
<pre class="python literal-block">
def __call__(self, argstring):
    &quot;&quot;&quot;
    The first arg is the command; the rest are arguments to that command.
    &quot;&quot;&quot;
    args = argstring.split(u&quot; &quot;)

    #Need to extract the keyword args out of args
    kwargs = dict([(arg.split(&quot;=&quot;)[0], arg.split(&quot;=&quot;)[1]) for arg in s.split(&quot; &quot;) if &quot;=&quot; in arg])
    args = [arg for arg in s.split(&quot; &quot;) if &quot;=&quot; not in arg]

    if args and args[0] in self.__class__.__dict__.keys():
        import types
        f = self.__class__.__dict__[args[0]]
        if type(f) == types.FunctionType:
            if args[1:]:
                f(self, *args[1:])
            else:
                f(self)
    else:
        print &quot;no command by that name&quot;
</pre>
<p>In other words, if the first (non-keyword) argument matches the name of a function in the class, run it and pass the rest of the (non-keyword) arguments to it. If I ever need keyword arguments as well, I&#8217;ll add the ability to pass them along too.</p>
<p>In order to actually manipulate Vim from these scripts, you have to use <tt class="docutils literal"><span class="pre">import</span> <span class="pre">vim</span></tt>. When I started writing this, I wasn&#8217;t sure how I&#8217;d test that, and I tried to keep the meat of the code in other files, e.g.:</p>
<pre class="python literal-block">
def mpc(self):
    &quot;&quot;&quot;
    Count the words, then insert them into the document's word count line.
    &quot;&quot;&quot;
    from write_wordcount import WriteWordcount
    wwc = WriteWordcount(tadhgbase)
    wwc.vim_main(vim)
</pre>
<p>(Note that I use <tt class="docutils literal"><span class="pre">import</span> <span class="pre">sys;</span> <span class="pre">sys.path.append(myscriptdir)</span></tt> at the top of the file to make these imports work.)</p>
<p>One of the advantages of this construction is that <tt class="docutils literal"><span class="pre">WriteWordCount</span></tt> can theoretically be used as a standalone script, on any file, and also that its <tt class="docutils literal"><span class="pre">vim_main</span></tt> method takes <tt class="docutils literal"><span class="pre">vim</span></tt> as an argument. For testing purposes, I had to created a <tt class="docutils literal"><span class="pre">MockVim</span></tt> class, which currently looks like this:</p>
<pre class="python literal-block">
class MockVimBuffer(object):

    def __init__(self):
        self.lines = []

    def __contains__(self, item):
        return item in self.lines

    def __iter__(self):
        return self.lines.__iter__()

    def __getitem__(self, index):
        return self.lines.__getitem__(index)

    def __setitem__(self, index, value):
        return self.lines.__setitem__(index, value)

class MockVimCurrent(object):

    def __init__(self):
        self.__dict__[&quot;buffer&quot;] = MockVimBuffer()

    def __setattr__(self, attr, value):
        if attr == &quot;buffer&quot;:
            self.__dict__[&quot;buffer&quot;].lines = value
        else:
            self.__dict__[attr] = value

class MockVim(object):

    def __init__(self):
        self.current = MockVimCurrent()
        self.commands = []

    def eval(self, command):
        command_list = {
            &quot;&amp;ft&quot;: lambda: self.rawmodes,
            &quot;exists('b:TotalWordCount')&quot;: lambda: False,
            &quot;tvar&quot;: lambda: self.tvar,

        }
        return command_list.get(command, lambda: &quot;&quot;)()

    def command(self, command):
        self.commands.append(command)
</pre>
<p>The <tt class="docutils literal"><span class="pre">eval</span></tt> method in <tt class="docutils literal"><span class="pre">MockVim</span></tt> simply returns whatever was appropriate for various tests I was running; I should change it to return <tt class="docutils literal"><span class="pre">self.command_list.get(command,</span> <span class="pre">lambda:</span> <span class="pre">&quot;&quot;)()</span></tt> instead, and make <tt class="docutils literal"><span class="pre">command_list</span></tt> an instance variable so that the various tests can manipulate it as needed instead of having to put specific commands in the base code.</p>
<p>Because the methods in <tt class="docutils literal"><span class="pre">TBase</span></tt> pass <tt class="docutils literal"><span class="pre">vim</span></tt> along to the instances or methods of the modules they import, testing those modules is relatively simple: in the test, you create a new <tt class="docutils literal"><span class="pre">MockVim</span></tt> object, call it <tt class="docutils literal"><span class="pre">vim</span></tt>, and then pass it along instead.</p>
<p>So everything is great (and testable). Unless, that is, you (meaning me) lapse from full test-driven development discipline and bits and pieces of functionality creep into <tt class="docutils literal"><span class="pre">TBase</span></tt>. Because <tt class="docutils literal"><span class="pre">TBase</span></tt> has that <tt class="docutils literal"><span class="pre">import</span> <span class="pre">vim</span></tt> line at the top of it and running it when you&#8217;re not actually in Vim produces an <tt class="docutils literal"><span class="pre">ImportError</span></tt>.</p>
<p>The right way to deal with this is to refactor <tt class="docutils literal"><span class="pre">TBase</span></tt> to take <tt class="docutils literal"><span class="pre">vim</span></tt> as one of its initialization arguments, and then have it set that as an instance variable, and then pass that in its methods, while also altering the line in the parent Vim script to:</p>
<pre class="literal-block">
command! -range -nargs=+ T python import vim; tadhgbase = TBase(vim, 'rs=&lt;line1&gt; rf=&lt;line2&gt;'); tadhgbase('&lt;args&gt;')
</pre>
<p>That way <tt class="docutils literal"><span class="pre">TBase</span></tt> is much easier to test, since the fake <tt class="docutils literal"><span class="pre">vim</span></tt> can be passed in at test time. However, for a bunch of reasons I didn&#8217;t want to do that just yet, partly because it means some reasonably heavy refactoring of pieces of code that I use every day—without tests, because the whole issue here is that <tt class="docutils literal"><span class="pre">TBase</span></tt> isn&#8217;t testable. So I wanted a way to make it testable while altering as little of its existing code (which I know currently works, after all) as possible. This took me a while to figure out, and is rather hacky—but it works.</p>
<p>First, in the test file, do this:</p>
<pre class="python literal-block">
from mockvim import MockVim
#Hack a mock Vim into the global namespace so that we can actually test:
import __builtin__
mv = MockVim()
__builtin__.mv = mv
from tadhg import TBase
</pre>
<p>Then alter the <tt class="docutils literal"><span class="pre">import</span> <span class="pre">vim</span></tt> line above the <tt class="docutils literal"><span class="pre">TBase</span></tt> class to instead read:</p>
<pre class="python literal-block">
try:
    import vim
except ImportError:
    import __builtin__
    vim = __builtin__.mv
</pre>
<p>What this really does is hack a giant global variable, <tt class="docutils literal"><span class="pre">vim</span></tt>, into all of the Python that&#8217;s run after those lines in the test file. Normally doing this seems like a rather bad idea, but it&#8217;s also rather necessary to handle the less-than-ideal situation I&#8217;m dealing with. Once I have the test harness using this hackery running properly, I&#8217;ll feel a lot better about switching over to a better architecture.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/jython/" rel="tag">Jython</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/text-editing/" rel="tag">text editing</a>, <a href="http://tadhg.com/wp/tag/vim/" rel="tag">Vim</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/">jEdit Macros in Python</a> <span class="related-post-date timestamp">Fri 17 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/18/thunderbird-muttator-and-filters/">Thunderbird, Muttator, and Filters</a> <span class="related-post-date timestamp">Thu 18 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/12/using-vim-with-thunderbird/">Using Vim with Thunderbird</a> <span class="related-post-date timestamp">Fri 12 Mar 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Post With Vim</title>
		<link>http://tadhg.com/wp/2010/02/14/first-post-with-vim/</link>
		<comments>http://tadhg.com/wp/2010/02/14/first-post-with-vim/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 04:05:48 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Jython]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[text editing]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2682</guid>
		<description><![CDATA[Over the last couple of weeks I’ve been hacking away on scripts to customize Vim, replicating the scripts I made for jEdit. I’m more or less done, and this blog post is being written in MacVim. This hopefully means that when I’m done with it I’ll be able to publish it from within Vim, the [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last couple of weeks I’ve been hacking away on scripts to customize Vim, replicating the scripts I made for jEdit. I’m more or less done, and this blog post is being written in <a class="reference external" href="http://code.google.com/p/macvim/">MacVim</a>. This hopefully means that when I’m done with it I’ll be able to publish it from within Vim, the same as with <a class="reference external" href="http://jedit.org/">jEdit</a>.<br />
<span id="more-2682"></span><br />
Writing scripts for Vim has been rather different from writing them for jEdit. jEdit is an editor with a robust API; Vim is an editor that kind of gives the user access to the API all the time, via keyboard commands, and scripting for it often consists of simply passing keystrokes. As an example, this is the Jython code for getting the current selection in a jEdit macro:</p>
<pre class="python literal-block">
text = init.textArea.getSelectedText()
</pre>
<p>This is the Python for getting the current visual selection in Vim:</p>
<pre class="python literal-block">self.vim.command('normal gv&quot;wygv')
self.vim.command(&quot;let tvar = getreg(’t’)&quot;)
text = unicode(self.vim.eval(&quot;tvar&quot;), &quot;utf-8&quot;)
</pre>
<p>From a programming perspective, jEdit is clearly a lot nicer to deal with.</p>
<p>I have two primary reasons for making the switch:</p>
<ul>
<li>Future proofing: I couldn’t switch to the various pre-release versions of jEdit 4.3 because I couldn’t get my Jython scripts to work with them, and that made me worry that there simply weren’t enough people scripting jEdit in Python to make it likely that the plugin allowing Jython macros would be supported. Given how useful my scripts are, that would have trapped me with jEdit 4.2, or some future version, if support for JythonInterpreter flagged. Vim, on the other hand, seems to have a lot of people scripting for it in Python, and I don’t see Python support simply disappearing anytime soon with a new release.
</li>
<li>Power/speed: I’m someone who’s quite inclined towards keyboard shortcuts in all applications, and this means Vim should be a highly efficient environment.
</li>
<li>Mentality: Related to the previous point, I think that being able to manipulate text more powerfully will reinforce the approach of scripting as many steps as possible, rather than doing them (no matter how efficiently) manually. Even over the last couple of weeks, I’ve noticed that I’m more inclined to write scripts than to put up with various manual steps in my daily workflow.
</li>
</ul>
<p>So far I’ve mainly worked to replicate my jEdit setup in Vim, with a few small improvements here and there; the largest one is probably the live word count, which means that I can glance at the status line to see the current word count instead of having to select the text to be counted and then invoke the word counter. I’ve also tweaked it so it only counts the relevant parts of the document—for example, in this blog post, it doesn’t count the title or the datestamp.</p>
<p>I don’t intend to abandon jEdit, and have a feeling that I’ll use it for various things here and there, but I’ve switched over the Vim for the majority of my writing and programming.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/jython/" rel="tag">Jython</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/text-editing/" rel="tag">text editing</a>, <a href="http://tadhg.com/wp/tag/vim/" rel="tag">Vim</a>, <a href="http://tadhg.com/wp/tag/writing/" rel="tag">writing</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/">jEdit Macros in Python</a> <span class="related-post-date timestamp">Fri 17 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/18/thunderbird-muttator-and-filters/">Thunderbird, Muttator, and Filters</a> <span class="related-post-date timestamp">Thu 18 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/12/using-vim-with-thunderbird/">Using Vim with Thunderbird</a> <span class="related-post-date timestamp">Fri 12 Mar 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2010/02/14/first-post-with-vim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Better Word Count in Vim</title>
		<link>http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/</link>
		<comments>http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 07:40:14 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Jython]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[text editing]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2596</guid>
		<description><![CDATA[I’m currently trying out Vim (again), and have made more progress this time, mainly due to Seth’s help. The key things that have made it better:

:set hidden. Absolutely critical, this. Stops Vim from complaining when you try to switch buffers and your current buffer has unsaved changes.

bufexplorer. Makes switching buffers a lot easier.

A better Python [...]]]></description>
			<content:encoded><![CDATA[<p>I’m currently trying out Vim (<a href="http://tadhg.com/wp/2009/08/09/time-to-try-vim/" title="Time to Try Vim" >again</a>), and have made more progress this time, mainly due to <a class="reference external" href="http://araxia.net/blog/seth">Seth</a>’s help. The key things that have made it better:</p>
<ul>
<li><tt class="docutils literal"><span class="pre">:set</span> <span class="pre">hidden</span></tt>. Absolutely critical, this. Stops Vim from complaining when you try to switch buffers and your current buffer has unsaved changes.
</li>
<li><a class="reference external" href="http://www.vim.org/scripts/script.php?script_id=42">bufexplorer</a>. Makes switching buffers a lot easier.
</li>
<li><a href="http://hlabs.spb.ru/vim/python3.0.vim" title="Python 3.0" >A better Python syntax file</a>. I didn’t like the defaults.
</li>
<li>My own indentation and syntax files for reStructuredText.
</li>
</ul>
<p>Really, though, the key first one was <tt class="docutils literal"><span class="pre">:set</span> <span class="pre">hidden</span></tt>. Before that I felt that I had completely misunderstood Vim’s file management model.<br />
<span id="more-2596"></span><br />
Once I got the syntax highlighting to a reasonable state, I ported my <a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/" title="Better Word Count in jEdit" >word count macro</a> over to Vim. This wasn’t too hard after the inevitable character encoding problems. For working within Vim scripts, I strongly suggest using the following:</p>
<pre class="python literal-block">
ulines = [unicode(line, &quot;utf-8&quot;) for line in vim.current.buffer]
</pre>
<p>(Assuming your Vim encoding is set to UTF-8, of course.)</p>
<p>The Vim version of my script isn’t as versatile yet as the jEdit version, because I don’t know how to make it work with only selected lines (something that’s easy in jEdit). Apart from that, though, it seems to work quite well; the next version of it might do “live” word count in the status bar.</p>
<p>I’m currently writing this in Vim, or kind of: the actual writing is in Vim, but the creation of the file and the template, the automated expansion of various reStructuredText entities, output to reStructuredText, and the publication, are in jEdit as I haven’t ported those over yet.</p>
<p>The script:</p>
<pre class="python literal-block">
function! WordCount()
python &lt;&lt; EOF
import re
import vim

class WordCounter(object):
    &quot;&quot;&quot;
    Vim script for better word count.
    &quot;&quot;&quot;

    LINE_SEPARATORS = (
        &quot;\r&quot;,
        &quot;\n&quot;
    )

    WORD_SEPARATORS = (
        &quot; &quot;,        # space
        &quot;\t&quot;,       # tab
        &quot;/&quot;,        # slash
        &quot;&amp;&quot;,        # ampersand
        ’&quot;’,        # double quotation mark, straight
        u&quot;\u201C&quot;,  # double quotation mark, left
        u&quot;\u201D&quot;,  # double quotation mark, right
        u&quot;\u2018&quot;,  # single quotation mark, left
        u&quot;\u2013&quot;,  # en dash
        u&quot;\u2014&quot;,  # em dash
        &quot;&gt;&quot;,        # greater than symbol
        &quot;&lt;&quot;,        # less than symbol
        &quot;+&quot;,        # plus
        &quot;=&quot;,        # equals
    )

    REPEATER_SEPARATORS = (
    #These are only separators if they’re present consecutively, e.g. -- or ..
        &quot;-&quot;,
        &quot;.&quot;
    )

    IGNORE = (
    #Not separators per se, but should not be treated as word content
        &quot;’&quot;,        # single quotation mark, straight
        u&quot;\u2019&quot;,  # single quotation mark, right
        &quot;(&quot;,        # left parenthesis
        &quot;)&quot;,        # right parenthesis
        &quot;[&quot;,        # left bracket
        &quot;]&quot;,        # right bracket
        &quot;{&quot;,        # left curly bracket
        &quot;}&quot;,        # right curly bracket
        &quot;|&quot;,        # bar
        &quot;-&quot;,        # hyphen
        &quot;#&quot;,        # hash mark
        &quot;.&quot;,        # period
        &quot;_&quot;,        # underscore
        &quot;`&quot;,        # backtick
        &quot;\\&quot;,        # backslash
    )

    def word_count(self):

        ulines = [unicode(line, &quot;utf-8&quot;) for line in vim.current.buffer]
        text = u&quot;\n&quot;.join(ulines)

        chars = len(text) #Pretty sure I want the actual char count, not the adjusted char count.

        text = self.remove_directives(text)
        text = self.adjust_for_rest(text)
        words, lines = self.count_words(text)

        print &quot;chars: %s, words: %s, lines: %s&quot; % (chars, words, lines)

    def remove_directives(self, text):
        textlines = text.split(&quot;\n&quot;)
        newlines = []
        comment = re.compile(r&quot;[ ]*\.\. [a-zA-Z0-9_\|]&quot;)
        argument = re.compile(r&quot;    :[^\:]*:&quot;)
        for line in textlines:
            if not comment.match(line) and not argument.match(line):
                newlines.append(line)
        return &quot;\n&quot;.join(newlines)

    def adjust_for_rest(self, text):
        &quot;&quot;&quot;
            Go through each of the special cases for reST.
        &quot;&quot;&quot;
        text = self.rest_adjust_pipe_space(text)

        return text

    def rest_adjust_pipe_space(self, text):
        &quot;&quot;&quot;
            Special-case &quot;|\ &quot; to make sure e.g. &quot;|Hypnotic Specter|\ s&quot;
            doesn’t get counted as three words.

            |Incinerate|\ s |Hypnotic Specter|\ —|Hypnotic Specter|\ s
            The above line should be counted as five words.
        &quot;&quot;&quot;
        spacere = re.compile(r&quot;\|\\ ([^ ]{1})&quot;)
        finds = spacere.findall(text)
        text = spacere.sub(&quot;|\g&lt;1&gt;&quot;, text)
        return text

    def count_words(self, text):
        words, lines = 0, 1
        #go through the text character by character:
        word, previous_character = 0, None
        for character in text:
            if character in (self.LINE_SEPARATORS + self.WORD_SEPARATORS) or (character in self.REPEATER_SEPARATORS and previous_character in self.REPEATER_SEPARATORS):
                #it’s a separator
                word = 0
                if character in (self.LINE_SEPARATORS):
                    lines = lines + 1
            elif character in (self.IGNORE):
                pass
            else:
                #it’s part of a word.
                if not word:
                    words = words + 1
                    word = 1
            previous_character = character

        return (words, lines)

WordCounter().word_count()
EOF
endfunction

if !exists(&quot;:WW&quot;)
  command! WW  :call WordCount()
endif
</pre>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/jython/" rel="tag">Jython</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/text-editing/" rel="tag">text editing</a>, <a href="http://tadhg.com/wp/tag/vim/" rel="tag">Vim</a>, <a href="http://tadhg.com/wp/tag/writing/" rel="tag">writing</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/">jEdit Macros in Python</a> <span class="related-post-date timestamp">Fri 17 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/18/thunderbird-muttator-and-filters/">Thunderbird, Muttator, and Filters</a> <span class="related-post-date timestamp">Thu 18 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/12/using-vim-with-thunderbird/">Using Vim with Thunderbird</a> <span class="related-post-date timestamp">Fri 12 Mar 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress 2.9 Upgrade</title>
		<link>http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/</link>
		<comments>http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 23:56:30 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[web-development]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2579</guid>
		<description><![CDATA[I upgraded this blog to WordPress 2.9 today, and it appeared to go entirely smoothly. Please let me know if you notice any breakage.
Tags: Blog, coding, PHP, tech, web-development, WordPressRelated PostsWordPress 2.8 Upgrade Sun 14 Jun 2009WP Plugins: Recent Commentary and Show Tags in RSS Mon 23 Mar 2009Some RSS Changes Thu 19 Mar 2009New [...]]]></description>
			<content:encoded><![CDATA[<p>I upgraded this blog to <a class="reference external" href="http://codex.wordpress.org/Version_2.9">WordPress 2.9</a> today, and it appeared to go entirely smoothly. Please let me know if you notice any breakage.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/blog/" rel="tag">Blog</a>, <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/php/" rel="tag">PHP</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/web-development/" rel="tag">web-development</a>, <a href="http://tadhg.com/wp/tag/wordpress/" rel="tag">WordPress</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2009/06/14/wordpress-2-8-upgrade/">WordPress 2.8 Upgrade</a> <span class="related-post-date timestamp">Sun 14 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/03/23/wp-plugins-recent-commentary-and-show-tags-in-rss/">WP Plugins: Recent Commentary and Show Tags in RSS</a> <span class="related-post-date timestamp">Mon 23 Mar 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/03/19/some-rss-changes/">Some RSS Changes</a> <span class="related-post-date timestamp">Thu 19 Mar 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/23/new-blog-functionality-recent-commentary/">New Blog Functionality: Recent Commentary</a> <span class="related-post-date timestamp">Mon 23 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/13/my-wordpress-development-setup/">My WordPress Development Setup</a> <span class="related-post-date timestamp">Fri 13 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/10/related-posts-plugin-and-sql-trickery/">Related Posts Plugin and SQL Trickery</a> <span class="related-post-date timestamp">Tue 10 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/11/10/html-past-and-future/">HTML Past and Future</a> <span class="related-post-date timestamp">Tue 10 Nov 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/10/404-pages/">404 Pages</a> <span class="related-post-date timestamp">Thu 10 Sep 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Perfect is the Enemy of the Good: Duke Nukem Forever</title>
		<link>http://tadhg.com/wp/2009/12/22/the-perfect-is-the-enemy-of-the-good-duke-nukem-forever/</link>
		<comments>http://tadhg.com/wp/2009/12/22/the-perfect-is-the-enemy-of-the-good-duke-nukem-forever/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 12:08:04 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[creativity]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2518</guid>
		<description><![CDATA[Duke Nukem Forever is the vaporware king of games, a game that was promised for so long that its release was a punchline even in the late 1990s. At one point it and Daikatana were frequently compared to each other; Daikatana was also extremely late and ultimately a failure—but it came out in 2000.
Wired has [...]]]></description>
			<content:encoded><![CDATA[<p><cite>Duke Nukem Forever</cite> is the vaporware king of games, a game that was promised for so long that its release was a punchline even in the late 1990s. At one point it and <a class="reference external" href="http://en.wikipedia.org/wiki/Daikatana"><cite>Daikatana</cite></a> were frequently compared to each other; <cite>Daikatana</cite> was also extremely late and ultimately a failure—but it came out in 2000.</p>
<p><a class="reference external" href="http://www.wired.com/"><cite>Wired</cite></a> has <a href="http://www.wired.com/magazine/2009/12/fail_duke_nukem/all/1" title="Learn to Let Go: How Success Killed Duke Nukem" >a long look at what happened</a>, and it seems fair to conclude that one of the problems was a lack of limits.<br />
<span id="more-2518"></span></p>
<div class="captionimagels300 container">
<img alt="http://tadhg.com/images/photos/2009_12_22__the_perfect_is_the_enemy_of_the_good_duke_nukem_forever/2009_12_22__the_perfect_is_the_enemy_of_the_good_duke_nukem_forever.jpg" src="http://tadhg.com/images/photos/2009_12_22__the_perfect_is_the_enemy_of_the_good_duke_nukem_forever/2009_12_22__the_perfect_is_the_enemy_of_the_good_duke_nukem_forever.jpg" style="width: 300px; height: 231px;" /></p>
<div class="captiontext container">
<a class="reference external" href="http://www.flickr.com/photos/arboltsef/8251874/">“pig cop”</a> by <a class="reference external" href="http://www.flickr.com/photos/arboltsef/">arboltsef</a></p>
</div>
</div>
<p><cite>Duke Nukem Forever</cite> was a project that had almost unlimited money, and a significantly longer development period than any other game I can think of. Its project lead, George Broussard, was more concerned with quality than money or deadlines, but this appears to have led to an inability to ever call it done. More than other creative projects, computer games are yoked to technical advances. There will always be a better graphics engine than the one you built your game on.</p>
<p>I enjoyed <cite>Duke Nukem 3D</cite> when it came out, and looked forward to the sequel for a couple of years. My interests moved more towards multiplayer, to competitive <cite>Quake 3 Arena</cite> and <a class="reference external" href="http://en.wikipedia.org/wiki/Challenge_ProMode_Arena"><cite>CPMA</cite></a>, but <cite>Half-Life</cite> made clear that extremely compelling single-player first-person shooter games were still relevant, and I thought that perhaps <cite>Duke Nukem Forever</cite> would be in the same class.</p>
<p>Extremely long development cycles aren’t necessarily indicators of failure; <cite>Half-Life 2</cite> took five years, and <cite>Team Fortress 2</cite> was released almost ten years after it was first announced. But in that regard at least, Duke (or his reputation?) turned out to indeed be bigger and badder, an ultimately invincible final boss.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/creativity/" rel="tag">creativity</a>, <a href="http://tadhg.com/wp/tag/games/" rel="tag">games</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/">The Future of Tabletop Games? <cite>D&amp;D</cite> on the Microsoft Surface</a> <span class="related-post-date timestamp">Fri 26 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/17/pool-playing-robot-deep-green/">Pool-Playing Robot: Deep Green</a> <span class="related-post-date timestamp">Thu 17 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/26/ai-and-games/">AI and Games</a> <span class="related-post-date timestamp">Thu 26 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/05/11/sfmagicorg-database-structure/">sfmagic.org Database Structure</a> <span class="related-post-date timestamp">Fri 11 May 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/05/06/loopstation-and-cheap-computing-power/">Loop!Station and Cheap Computing Power</a> <span class="related-post-date timestamp">Sun 06 May 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/01/02/distractivities/">Distractivities</a> <span class="related-post-date timestamp">Tue 02 Jan 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2006/08/09/some-plans-for-sfmagicorg/">Some Plans for sfmagic.org</a> <span class="related-post-date timestamp">Wed 09 Aug 2006</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/08/inkscape/">Inkscape</a> <span class="related-post-date timestamp">Mon 08 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/05/doom-and-modern-first-person-shooters/"><cite>Doom</cite> and Modern First-Person Shooters</a> <span class="related-post-date timestamp">Fri 05 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/04/vim-the-killer-instinct-of-text-editors/">Vim: the <cite>Killer Instinct</cite> of Text Editors</a> <span class="related-post-date timestamp">Thu 04 Mar 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/12/22/the-perfect-is-the-enemy-of-the-good-duke-nukem-forever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gizmodo on Space Battle Physics</title>
		<link>http://tadhg.com/wp/2009/12/20/gizmodo-on-space-battle-physics/</link>
		<comments>http://tadhg.com/wp/2009/12/20/gizmodo-on-space-battle-physics/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 16:06:48 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[science-fiction]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[war]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2511</guid>
		<description><![CDATA[This article is an excellent overview of how near-future space combat might actually work, and also points out plenty of things that depictions of far-future space combat have gotten very wrong.

I was sad to see no mention of Babylon 5 in it, since that show made an effort to depict realistic ships and combat.
It is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://gizmodo.com/5426453/the-physics-of-space-battles" title="The Physics of Space Battles" >This article</a> is an excellent overview of how near-future space combat might actually work, and also points out plenty of things that depictions of far-future space combat have gotten very wrong.<br />
<span id="more-2511"></span><br />
I was sad to see no mention of <cite>Babylon 5</cite> in it, since that show made an effort to depict realistic ships and combat.</p>
<p>It is still questionable as to whether small, highly maneuverable fighter craft make any sense; I think it depends on how maneuverable the larger craft are. If they’re not particularly agile, then simply sending lots of firepower in a straight line will be much more cost-effective.</p>
<p>The comments for the article are worth reading through as well&#8230; how space combat would really be is still unclear, but the discussion there has some great food for thought.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/science-fiction/" rel="tag">science-fiction</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/war/" rel="tag">war</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2008/01/24/future-shock/">Future Shock</a> <span class="related-post-date timestamp">Thu 24 Jan 2008</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/07/lets-enhance/">“Let’s Enhance”</a> <span class="related-post-date timestamp">Sun 07 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/">The Future of Tabletop Games? <cite>D&amp;D</cite> on the Microsoft Surface</a> <span class="related-post-date timestamp">Fri 26 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/">WordPress 2.9 Upgrade</a> <span class="related-post-date timestamp">Sun 10 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/22/the-perfect-is-the-enemy-of-the-good-duke-nukem-forever/">The Perfect is the Enemy of the Good: <cite>Duke Nukem Forever</cite></a> <span class="related-post-date timestamp">Tue 22 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/11/13/doomsday-book-review/"><cite>Doomsday Book</cite> Review</a> <span class="related-post-date timestamp">Fri 13 Nov 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/11/10/html-past-and-future/">HTML Past and Future</a> <span class="related-post-date timestamp">Tue 10 Nov 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/12/20/gizmodo-on-space-battle-physics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Past and Future</title>
		<link>http://tadhg.com/wp/2009/11/10/html-past-and-future/</link>
		<comments>http://tadhg.com/wp/2009/11/10/html-past-and-future/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 00:04:45 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2375</guid>
		<description><![CDATA[Mark Pilgrim, author of the excellent Dive Into Python, is working on Dive Into HTML5, and his draft chapter on HTML5 semantics is an excellent introduction to the advantages of the new HTML standard. It’s unfortunately quite far from becoming a real standard, but as a web developer, I’d like to see it happen as [...]]]></description>
			<content:encoded><![CDATA[<p><a class="reference external" href="http://diveintomark.org/">Mark Pilgrim</a>, author of the excellent <a class="reference external" href="http://diveintopython.org/"><cite>Dive Into Python</cite></a>, is working on <a class="reference external" href="http://diveintohtml5.org/"><cite>Dive Into HTML5</cite></a>, and his <a href="http://diveintohtml5.org/semantics.html" title="What Does It All Mean?" >draft chapter on HTML5 semantics</a> is an excellent introduction to the advantages of the new HTML standard. It’s unfortunately quite far from becoming a real standard, but as a web developer, I’d like to see it happen as soon as possible.</p>
<p>I came across a contrasting Mark Pilgrim article that’s also worth reading: <a class="reference external" href="http://diveintomark.org/archives/2009/11/02/why-do-we-have-an-img-element">“Why do we have an IMG element?”</a>, which goes over the history of that element in HTML, the objections raised at the time, and how it won out over alternatives.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/web-development/" rel="tag">web-development</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/">WordPress 2.9 Upgrade</a> <span class="related-post-date timestamp">Sun 10 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/">Some Character Encoding Gotchas</a> <span class="related-post-date timestamp">Thu 16 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/14/wordpress-2-8-upgrade/">WordPress 2.8 Upgrade</a> <span class="related-post-date timestamp">Sun 14 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/12/pylons-via-apache-port-issues/">Pylons Via Apache Port Issues</a> <span class="related-post-date timestamp">Fri 12 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/09/pywebsf-meetup-for-sf-area-python-web-developers/">PyWebSF: Meetup for SF-Area Python Web Developers</a> <span class="related-post-date timestamp">Tue 09 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/03/12/yahoos-website-performance-rules/">Yahoo!'s Website Performance Rules</a> <span class="related-post-date timestamp">Thu 12 Mar 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/13/my-wordpress-development-setup/">My WordPress Development Setup</a> <span class="related-post-date timestamp">Fri 13 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2008/03/18/editable-google-maps/">Editable Google Maps</a> <span class="related-post-date timestamp">Tue 18 Mar 2008</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/11/10/html-past-and-future/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plug Fun</title>
		<link>http://tadhg.com/wp/2009/10/30/plug-fun/</link>
		<comments>http://tadhg.com/wp/2009/10/30/plug-fun/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 07:28:20 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[economics]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[politics]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2342</guid>
		<description><![CDATA[Figuring out what plug (or adapter) to use in a given country is almost like a game; in any case, I found this Gizmodo article well worth the read: “Giz Explains: Why Every Country Has a Different F#$%ing Plug”.
Tags: economics, hardware, politics, techRelated Postsdanah boyd on Online Class Divisions Sun 24 Jun 2007Escape Velocity Sun [...]]]></description>
			<content:encoded><![CDATA[<p>Figuring out what plug (or adapter) to use in a given country is almost like a game; in any case, I found this Gizmodo article well worth the read: <a class="reference external" href="http://gizmodo.com/5391271/giz-explains-why-every-country-has-a-different-fing-plug">“Giz Explains: Why Every Country Has a Different F#$%ing Plug”</a>.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/economics/" rel="tag">economics</a>, <a href="http://tadhg.com/wp/tag/hardware/" rel="tag">hardware</a>, <a href="http://tadhg.com/wp/tag/politics/" rel="tag">politics</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2007/06/24/danah-boyd-on-online-class-divisions/">danah boyd on Online Class Divisions</a> <span class="related-post-date timestamp">Sun 24 Jun 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2006/12/24/escape-velocity/">Escape Velocity</a> <span class="related-post-date timestamp">Sun 24 Dec 2006</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/19/cards-versus-cash/">Cards Versus Cash</a> <span class="related-post-date timestamp">Tue 19 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/14/tiger-woods-and-his-sponsors/">Tiger Woods and His Sponsors</a> <span class="related-post-date timestamp">Mon 14 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/10/facebook-astroturfing/">Facebook Astroturfing</a> <span class="related-post-date timestamp">Thu 10 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/03/bullying-just-a-hunch/">Bullying: Just a Hunch</a> <span class="related-post-date timestamp">Thu 03 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/11/03/state-bandits/">State Bandits</a> <span class="related-post-date timestamp">Tue 03 Nov 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/10/19/economics-fairness-and-football/">Economics, Fairness, and Football</a> <span class="related-post-date timestamp">Mon 19 Oct 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/10/18/wall-street-even-worse-than-you-thought/">Wall Street: Even Worse Than You Thought</a> <span class="related-post-date timestamp">Sun 18 Oct 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/10/15/energy-consumption-data-centers-and-heat/">Energy Consumption, Data Centers, and Heat</a> <span class="related-post-date timestamp">Thu 15 Oct 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/10/30/plug-fun/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Energy Consumption, Data Centers, and Heat</title>
		<link>http://tadhg.com/wp/2009/10/15/energy-consumption-data-centers-and-heat/</link>
		<comments>http://tadhg.com/wp/2009/10/15/energy-consumption-data-centers-and-heat/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 23:03:59 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[economics]]></category>
		<category><![CDATA[energy]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2302</guid>
		<description><![CDATA[The Kardashev Scale is used to measure a civilization’s technology level, using the measure of its energy consumption—or, more accurately, the amount of energy the civilization can harness. In light of the ongoing computing/networking revolution, I’m curious about what percentage of our energy use is by data centers.

The data center explosion is, obviously, driven by [...]]]></description>
			<content:encoded><![CDATA[<p>The <a class="reference external" href="http://en.wikipedia.org/wiki/Kardashev_scale">Kardashev Scale</a> is used to measure a civilization’s technology level, using the measure of its energy consumption—or, more accurately, the amount of energy the civilization can harness. In light of the ongoing computing/networking revolution, I’m curious about what percentage of our energy use is by <a class="reference external" href="http://www.redorbit.com/news/technology/1374175/server_farms_becoming_a_cash_crop_in_the_midwest/">data centers</a>.<br />
<span id="more-2302"></span><br />
The data center explosion is, obviously, driven by increasing adoption of internet technologies. In certain respects it seems like a step back, towards mainframe computing—you have a central location, physical security concerns, energy issues, cooling issues, and so on. I wonder if at any point it will once again make sense to build large single machines rather than tying together many pieces of commodity hardware..</p>
<p>In the meantime, as processors get faster and demand increases, data centers are going to become more energy-hungry, and hotter—which essentially translates to being even more energy-hungry as they need cooling. Hence <a class="reference external" href="http://news.bbc.co.uk/2/hi/programmes/click_online/8297237.stm">Iceland’s bid to become a data center haven</a> makes sense, because they have a conveniently cold climate and a conveniently cheap electricity supply.</p>
<p>(The optimist in me hopes that this trend might somehow drive us towards cheap electricity; certainly here in California we don’t make anything near efficient use of natural resources to generate electricity, and of course Buckminster Fuller’s Global Energy Grid would make a lot of sense—but I suspect too many profit-oriented vested interests stand in the way of that; if you’re interested in that topic, see <a class="reference external" href="http://www.amazon.com/Power-Play-Control-Worlds-Electricity/dp/156584808X">Sharon Beder’s <cite>Power Play</cite></a>.)</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/economics/" rel="tag">economics</a>, <a href="http://tadhg.com/wp/tag/energy/" rel="tag">energy</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2009/10/30/plug-fun/">Plug Fun</a> <span class="related-post-date timestamp">Fri 30 Oct 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/11/05/inundation-of-spam/">Inundation of Spam</a> <span class="related-post-date timestamp">Mon 05 Nov 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/07/22/consumer-ephemera/">Consumer Ephemera</a> <span class="related-post-date timestamp">Sun 22 Jul 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/06/24/danah-boyd-on-online-class-divisions/">danah boyd on Online Class Divisions</a> <span class="related-post-date timestamp">Sun 24 Jun 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/02/12/cellphone-plans/">Cellphone Plans</a> <span class="related-post-date timestamp">Mon 12 Feb 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2006/12/24/escape-velocity/">Escape Velocity</a> <span class="related-post-date timestamp">Sun 24 Dec 2006</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/16/height-and-negotiation/">Height and Negotiation</a> <span class="related-post-date timestamp">Tue 16 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/">The Future of Tabletop Games? <cite>D&amp;D</cite> on the Microsoft Surface</a> <span class="related-post-date timestamp">Fri 26 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/10/15/energy-consumption-data-centers-and-heat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RTF/Word–reStructuredText Toolchain</title>
		<link>http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/</link>
		<comments>http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 20:05:00 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reStructuredText]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2227</guid>
		<description><![CDATA[It took me a while to get there, but I now have a working toolchain to automate going from an RTF file (or a Word document) to reStructuredText. The final link took the longest to find, and turned out to have been right there all along (no, I’m not going to turn this into a [...]]]></description>
			<content:encoded><![CDATA[<p>It took me a while to get there, but I now have a working toolchain to automate going from an RTF file (or a Word document) to <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>. The final link took the longest to find, and turned out to have been right there all along (no, I’m not going to turn this into a retelling of <cite>The Alchemist</cite>). But if you’re interested in how to get from Word to a sane format (like reStructuredText), this post will interest you.<br />
<span id="more-2227"></span><br />
What you need:</p>
<ul>
<li><a class="reference external" href="http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/textutil.1.html"><tt class="docutils literal"><span class="pre">textutil</span></tt></a>. If you’re not running OS X, I discuss some alternatives below.
</li>
<li><a class="reference external" href="http://johnmacfarlane.net/pandoc/">pandoc</a>. In <a class="reference external" href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29">Haskell</a>, so you need to install the <a class="reference external" href="http://hackage.haskell.org/platform/">Haskell Platform</a> for your system, and then run <tt class="docutils literal"><span class="pre">sudo</span> <span class="pre">cabal</span> <span class="pre">install</span> <span class="pre">pandoc</span></tt>.
</li>
</ul>
<p>Once you have those, it becomes pretty simple:</p>
<pre class="literal-block">
textutil -convert html -stdout {source_file} | pandoc -f html -t rst --no-wrap &gt; {output_file}
</pre>
<p>If you don’t have access to <tt class="docutils literal"><span class="pre">textutil</span></tt>, you could try <a class="reference external" href="http://www.gnu.org/software/unrtf/unrtf.html">UnRTF</a>, <a href="http://www.bekkoame.ne.jp/~n-iyanag/researchTools/rtf2taggedTextAndLaTeX.html" title="rtf to UTF-8 and pTeX" >some Perl scripts</a>, <a class="reference external" href="http://sourceforge.net/projects/rtf2latex2e/">rtf2latex2e</a> (if you don’t mind the lack of Unicode support), or <a class="reference external" href="http://sourceforge.net/projects/rtf2html/">rtf2html</a>. If your source files are Word documents rather than RTF documents, you could use <a class="reference external" href="http://www.openoffice.org/">OpenOffice.org</a>’s batch conversion utility to get them into RTF and proceed from there. (<a class="reference external" href="http://abisource.com/">AbiWord</a> is also an option.)</p>
<p>This is a rather powerful set of tools. It’s extremely useful for me to be able to automate the conversion of my older files, and once they’re in reStructuredText it’s not that hard to get them to other useful formats, including <a class="reference external" href="http://en.wikipedia.org/wiki/LaTeX">LaTeX</a> and PDF. I have some work yet to do (mainly on styling), but soon I should, for example, be able to have a single reStructuredText file for my résumé that a script can automatically convert to HTML, PDF, HTML suitable for my blog, RTF, Word doc, <a class="reference external" href="http://en.wikipedia.org/wiki/OpenDocument">OpenDocument</a> Text, and plain text. The same should apply for any of my other documents.</p>
<p>It took me quite some time to find the right pieces for this process, which I’ll describe below in case it’s of use to others.</p>
<hr class="docutils" />
A while ago I came across pandoc, an extremely useful tool that translates between quite a few different formats—including reStructuredText. It took me a while to get it working, as it’s in Haskell and the <a class="reference external" href="http://www.macports.org/">MacPorts</a> version of Haskell just wouldn’t install for me, so I eventually figured out that I should just use the standard Haskell Platform OS X release. Having access to pandoc meant that I wouldn’t have to write my own parser from some sane format to reStructuredText.</p>
<p>That did still leave me with the problem of getting from RTF to that unspecified sane format. <tt class="docutils literal"><span class="pre">rtf2latex2e</span></tt> looked extremely promising, but it turned out not to support Unicode in RTF. I found UnRTF, but it also had Unicode issues and furthermore would segfault whenever I ran it. <a class="reference external" href="http://www.ctan.org/tex-archive/support/rtf2latex/">rtf2latex</a> had some other issues. I found a <a href="http://www.bekkoame.ne.jp/~n-iyanag/researchTools/rtf2taggedTextAndLaTeX.html" title="rtf to UTF-8 and pTeX" >set of Perl scripts aimed at the problem</a>, but they gave me odd errors that I couldn’t fix. Finally I came across <a class="reference external" href="http://www.bluem.net/en/mac/others/">rtf2txt</a>, which had a critical reference to <tt class="docutils literal"><span class="pre">textutil</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">textutil</span></tt> is built into OS X, at least versions starting with 10.4, and handles formats including text, RTF, HTML&#8230; and even Word documents. Furthermore, the HTML it produces is quite sane, and in many respects better than the OpenOffice.org or AbiWord HTML output, particularly for simple documents—e.g. italics are surrounded with <tt class="docutils literal"><span class="pre">&lt;i&gt;</span></tt> tags and not <tt class="docutils literal"><span class="pre">&lt;span&gt;</span></tt> tags with some difficult-to-parse class defined elsewhere in the document.</p>
<p>I do some additional work in Python to infer document structure from my files and insert that into the reStructuredText, but that’s fairly trivial.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/personal/" rel="tag">personal</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/restructuredtext/" rel="tag">reStructuredText</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/writing/" rel="tag">writing</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/12/moving-from-word-processors-to-restructuredtext/">Moving From Word Processors to reStructuredText</a> <span class="related-post-date timestamp">Sun 12 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/29/2009-goals-review/">2009 Goals Review</a> <span class="related-post-date timestamp">Tue 29 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2008/01/27/some-minor-software-projects/">Some Minor Software Projects</a> <span class="related-post-date timestamp">Sun 27 Jan 2008</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pool-Playing Robot: Deep Green</title>
		<link>http://tadhg.com/wp/2009/09/17/pool-playing-robot-deep-green/</link>
		<comments>http://tadhg.com/wp/2009/09/17/pool-playing-robot-deep-green/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:27:49 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[artificial-intelligence]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[pool]]></category>
		<category><![CDATA[robotics]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2206</guid>
		<description><![CDATA[The Robotics and Computer Vision Lab at Queen’s University Ontario has produced a working robotic system that can play pool. Called Deep Green, it appears to have an excellent understanding of geometry, although it’s not clear that it understands the rules of the game per se, or that it can do its own shot selection.

TechCrunch [...]]]></description>
			<content:encoded><![CDATA[<p>The <a class="reference external" href="http://rcvlab.ece.queensu.ca/~rcvlab/">Robotics and Computer Vision Lab</a> at Queen’s University Ontario has produced a working robotic system that can play pool. Called <a class="reference external" href="http://www.deepgreenrobot.org/">Deep Green</a>, it appears to have an excellent understanding of geometry, although it’s not clear that it understands the rules of the game per se, or that it can do its own shot selection.<br />
<span id="more-2206"></span><br />
TechCrunch <a class="reference external" href="http://www.techcrunch.com/2009/09/17/deep-green-the-pool-playing-robot/">cover Deep Green here</a>, and include the following video:</p>
<p><object  type="application/x-shockwave-flash"  width="425"   height="344"   class="youtube-embed"   data="http://www.youtube.com/v/AENJxqR0g48&amp;fs=1" ><param name="allowscriptaccess" value="always"></param><param name="allowfullscreen" value="true"></param><param name="wmode" value="transparent"></param>
</object></p>
<p>In it, they also demonstrate “augmented reality pool“, a system that determines the angles being shot and projects them onto the pool table. This is presumably a projection of the system that Deep Green itself uses to figure out how to aim, like a rather more sophisticated version of “<a class="reference external" href="http://www.thespideronline.com/home.htm">The Spider</a>”, a pool training aid.</p>
<p>I suspect that projects like these, despite seeming frivolous on the surface, generate significant progress in robotics and artificial intelligence. Whatever about the future, the current state of AI means that its successes will come in limited domains, and games are excellent testbeds for this.</p>
<p>As for pool specifically, it’s possible that robotic pool players will be a luxury accessory at some point in the near future. Meanwhile, the assisted-vision aspect of it may well develop from requiring a setup worth tens of thousands of dollars, with perfect lighting and multiple cameras, projectors, and computers, to requiring merely a contact lens overlay and maybe a small separate camera—potentially bringing to pool halls everywhere the joys of <a class="reference external" href="http://en.wikipedia.org/wiki/Aimbot">aimbot</a> use accusations.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/artificial-intelligence/" rel="tag">artificial-intelligence</a>, <a href="http://tadhg.com/wp/tag/games/" rel="tag">games</a>, <a href="http://tadhg.com/wp/tag/pool/" rel="tag">pool</a>, <a href="http://tadhg.com/wp/tag/robotics/" rel="tag">robotics</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/26/the-future-of-tabletop-games-dd-on-the-microsoft-surface/">The Future of Tabletop Games? <cite>D&amp;D</cite> on the Microsoft Surface</a> <span class="related-post-date timestamp">Fri 26 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/22/the-perfect-is-the-enemy-of-the-good-duke-nukem-forever/">The Perfect is the Enemy of the Good: <cite>Duke Nukem Forever</cite></a> <span class="related-post-date timestamp">Tue 22 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/02/26/ai-and-games/">AI and Games</a> <span class="related-post-date timestamp">Thu 26 Feb 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2008/06/19/pool/">Pool</a> <span class="related-post-date timestamp">Thu 19 Jun 2008</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/05/11/sfmagicorg-database-structure/">sfmagic.org Database Structure</a> <span class="related-post-date timestamp">Fri 11 May 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/01/02/distractivities/">Distractivities</a> <span class="related-post-date timestamp">Tue 02 Jan 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2006/08/09/some-plans-for-sfmagicorg/">Some Plans for sfmagic.org</a> <span class="related-post-date timestamp">Wed 09 Aug 2006</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/08/inkscape/">Inkscape</a> <span class="related-post-date timestamp">Mon 08 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/05/doom-and-modern-first-person-shooters/"><cite>Doom</cite> and Modern First-Person Shooters</a> <span class="related-post-date timestamp">Fri 05 Mar 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/03/04/vim-the-killer-instinct-of-text-editors/">Vim: the <cite>Killer Instinct</cite> of Text Editors</a> <span class="related-post-date timestamp">Thu 04 Mar 2010</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/09/17/pool-playing-robot-deep-green/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Script for Subversion Status</title>
		<link>http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/</link>
		<comments>http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 07:48:19 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[version-control]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=2018</guid>
		<description><![CDATA[I find in my use of Subversion that I often want to see a side-by-side list of files that aren&#8217;t under version control and files that have some other status. I also want these lists to be sorted alphabetically. Naturally, I ended up writing a Python script for this.

I suspect it could be cleaner, but [...]]]></description>
			<content:encoded><![CDATA[<p>I find in my use of <a class="reference external" href="http://subversion.tigris.org/">Subversion</a> that I often want to see a side-by-side list of files that aren&#8217;t under version control and files that have some other status. I also want these lists to be sorted alphabetically. Naturally, I ended up writing a Python script for this.<br />
<span id="more-2018"></span><br />
I suspect it could be cleaner, but it works and I&#8217;m trying to keep in mind that “the perfect is the enemy of the good”.</p>
<pre class="python literal-block">
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Displays added and modified files in two columns (terminal space permitting)

import subprocess
import re

class SubversionSortedStatus(object):

    STATUS_NEW = &quot;svn st | grep '^\?'&quot; #check for new files
    STATUS_MODIFIED =  &quot;svn st | grep -v '^\?'&quot; #check for modified files

    def __init__(self):
        newfiles = self.get_new_files()
        newfiles_width = self.get_filename_width(newfiles)
        modfiles = self.get_modified_files()
        modfiles_width = self.get_filename_width(modfiles)
        terminal_width = self.terminal_size()[0]
        terminal_midpoint = self.get_midpoint(terminal_width, newfiles_width, modfiles_width)
        self.print_status(terminal_midpoint, newfiles, modfiles)

    def get_new_files(self):
        #the shell command:
        files = self.exec_shell_command(self.STATUS_NEW, stdout=subprocess.PIPE)

        #get rid of the status character:
        status_column = re.compile(r&quot;^\?( +)(?=[^ ]*)&quot;)
        lines = files.split(&quot;\n&quot;)
        lines.sort()
        replaced_lines = []
        for line in lines:
            line = status_column.sub(&quot;&quot;, line)
            replaced_lines.append(line)
        files = &quot;\n&quot;.join(replaced_lines)

        return files.strip()

    def get_modified_files(self):
        #the shell command:
        files = self.exec_shell_command(self.STATUS_MODIFIED, stdout=subprocess.PIPE)

        lines = files.split(&quot;\n&quot;)
        #sort using only the non-status columns:
        lines.sort(cmp = lambda x, y: cmp(x[6:], y[6:]))
        files = &quot;\n&quot;.join(lines)

        return files.strip()

    def get_filename_width(self, files):
        width = 0
        lines = files.split(&quot;\n&quot;)
        for line in lines:
            if len(line) &gt; width:
                width = len(line)
        return width

    def get_midpoint(self, width, newfiles_width, modfiles_width):
        if width &lt;= newfiles_width + modfiles_width + 1:
            return 0
        else:
            return newfiles_width + 1

    def print_status(self, midpoint, newfiles, modfiles):
        if midpoint:
            newlines = newfiles.split(&quot;\n&quot;)
            modlines = modfiles.split(&quot;\n&quot;)
            if len(newlines) &gt; len(modlines):
                maxlength = len(newlines)
            else:
                maxlength = len(modlines)
            for i in range(0, maxlength):
                if i &lt; len(newlines):
                    newfile = newlines[i]
                else:
                    newfile = &quot;&quot;
                if i &lt; len(modlines):
                    modfile = modlines[i]
                else:
                    modfile = &quot;&quot;
                separator = &quot; &quot; * ((midpoint - len(newfile)) + 1)
                print &quot;%s%s%s&quot; % (newfile, separator, modfile)
        else:
            print newfiles
            print &quot;-----&quot;
            print modfiles

    def exec_shell_command(self, command, stdout=None, wait=None, test_mode=False):
        if test_mode:
            print command
            return command

        output = &quot;&quot;
        if stdout:
            commandprocess = subprocess.Popen([command], shell=True, stdout=stdout)
            output = commandprocess.communicate()[0]
        else:
            commandprocess = subprocess.Popen([command], shell=True)
            commandprocess.wait()

        if wait:
            import time
            time.sleep(wait)

        return output

    &quot;&quot;&quot;
    The next two functions are from Chuck Blake's categorized ls, found at http://pdos.csail.mit.edu/~cblake/cls/cls.py

    &quot;&quot;&quot;
    def ioctl_GWINSZ(self, fd):                  #### TABULATION FUNCTIONS
        try:                                ### Discover terminal width
            import fcntl, termios, struct, os
            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
        except:
            return None
        return cr

    def terminal_size(self):                    ### decide on *some* terminal size
        import os
        env = os.environ
        cr = self.ioctl_GWINSZ(0) or self.ioctl_GWINSZ(1) or self.ioctl_GWINSZ(2)  # try open fds
        if not cr:                                                  # ...then ctty
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = self.ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass
        if not cr:                            # env vars or finally defaults
            try:
                cr = (env['LINES'], env['COLUMNS'])
            except:
                cr = (25, 80)
        return int(cr[1]), int(cr[0])         # reverse rows, cols

if __name__ == '__main__':
    svnstatus = SubversionSortedStatus()
</pre>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/version-control/" rel="tag">version-control</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2007/03/21/web-development-tools/">Web Development Tools</a> <span class="related-post-date timestamp">Wed 21 Mar 2007</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/">jEdit Macros in Python</a> <span class="related-post-date timestamp">Fri 17 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/">Some Character Encoding Gotchas</a> <span class="related-post-date timestamp">Thu 16 Jul 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better reST–WordPress Pipeline</title>
		<link>http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/</link>
		<comments>http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 07:15:47 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reStructuredText]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[web-development]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=1983</guid>
		<description><![CDATA[Last week I posted about my setup for going from reStructuredText to WordPress. It involved a shell script, some Python scripts, and the pbpaste and pbcopy commands. It worked, but it was a little on the convoluted side.
Now I have a slightly better process, and one that I will have used to publish this post.

The [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I posted about <a class="reference external" href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">my setup for going from reStructuredText to WordPress</a>. It involved a shell script, some Python scripts, and the <tt class="docutils literal"><span class="pre">pbpaste</span></tt> and <tt class="docutils literal"><span class="pre">pbcopy</span></tt> commands. It worked, but it was a little on the convoluted side.</p>
<p>Now I have a slightly better process, and one that I will have used to publish this post.<br />
<span id="more-1983"></span><br />
The previous version was launched via <a class="reference external" href="http://en.wikipedia.org/wiki/Quicksilver_(software)">Quicksilver</a> and operated on the contents of the clipboard; the new version is run from the command line—or, even better, from within jEdit—and operates on a file. It:</p>
<ul>
<li>Runs the contents of the file through my reST–Wordpress script, which uses <a class="reference external" href="http://unmaintainable.wordpress.com/2008/03/22/using-rst-with-wordpress/"><tt class="docutils literal"><span class="pre">rst2wp</span></tt></a> and some customized other Python scripts.</li>
<li>Submits the transformed text to WordPress via <a class="reference external" href="http://code.google.com/p/python-blogger/"><tt class="docutils literal"><span class="pre">python-blogger</span></tt></a>, a script for doing blog XMLRPC operations in Python.</li>
<li>Runs <tt class="docutils literal"><span class="pre">svn</span> <span class="pre">add</span></tt> on the file.</li>
<li>Opens the WordPress Edit Draft page for the submitted post.</li>
</ul>
<p>So, the previous steps for me were:</p>
<ul>
<li>Write post in reStructuredText in <a class="reference external" href="http://www.jedit.org/">jEdit</a>.</li>
<li>Select all.</li>
<li>Copy.</li>
<li>Invoke a shell script via <a class="reference external" href="http://en.wikipedia.org/wiki/Quicksilver_(software)">Quicksilver</a>.</li>
<li>Switch to WordPress new post tab in Firefox.</li>
<li>Paste.</li>
<li>Fiddle with the post settings slightly.</li>
<li>Post.</li>
</ul>
<p>While the new ones are:</p>
<ul>
<li>Write post in reStructuredText in jEdit.</li>
<li>Save.</li>
<li>Invoke a jEdit macro to run the Python script from within the editor.</li>
<li>Switch to WordPress new post tab in Firefox.</li>
<li>Fiddle with the post settings slightly.</li>
<li>Post.</li>
</ul>
<p>(As a bonus, this version also adds the file to Subversion.)</p>
<p>The jEdit macro seems</p>
<p>These are the components necessary to make it work:</p>
<ul>
<li><a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a>—of course, to handle the reStructuredText</li>
<li><a class="reference external" href="http://unmaintainable.wordpress.com/2008/03/22/using-rst-with-wordpress/"><tt class="docutils literal"><span class="pre">rst2wp</span></tt></a>, which I&#8217;ve modified a little for my own purposes.</li>
<li><a class="reference external" href="http://code.google.com/p/python-blogger/"><tt class="docutils literal"><span class="pre">python-blogger</span></tt></a>, to talk to WordPress in Python.</li>
<li><a class="reference external" href="http://blog.articlemarketingautomation.com/enabling-xml-rpc-on-wordpress">WordPress with XMLRPC enabled</a> so that software can talk to it.</li>
<li>A short script of my own that pulls the pieces together. (This uses <a class="reference external" href="http://docs.python.org/library/subprocess.html"><tt class="docutils literal"><span class="pre">os.subprocess</span></tt></a>, so Python 2.4 or better is required)</li>
<li>A jEdit macro to run the script from the last step within the editor.</li>
</ul>
<p>I&#8217;m pretty happy with it, and I think it should be fairly cross-platform, which is important to me as I&#8217;d like to take this whole setup with me if I switch environments in future.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/personal/" rel="tag">personal</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/restructuredtext/" rel="tag">reStructuredText</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/web-development/" rel="tag">web-development</a>, <a href="http://tadhg.com/wp/tag/wordpress/" rel="tag">WordPress</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2008/01/27/some-minor-software-projects/">Some Minor Software Projects</a> <span class="related-post-date timestamp">Sun 27 Jan 2008</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/">WordPress 2.9 Upgrade</a> <span class="related-post-date timestamp">Sun 10 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/29/2009-goals-review/">2009 Goals Review</a> <span class="related-post-date timestamp">Tue 29 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better Word Count in jEdit</title>
		<link>http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/</link>
		<comments>http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 06:33:11 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Jython]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=1934</guid>
		<description><![CDATA[I tend to care about word count in my writing. I&#8217;ve never been paid by the word, but nevertheless, it matters to me. From time to time I write fiction where I set the word count in advance, and then I try to hit it precisely. Even when that&#8217;s not the case, I just like [...]]]></description>
			<content:encoded><![CDATA[<p>I tend to care about word count in my writing. I&#8217;ve never been paid by the word, but nevertheless, it matters to me. From time to time I write fiction where I set the word count in advance, and then I try to hit it precisely. Even when that&#8217;s not the case, I just like to know how many words there are in a piece I&#8217;m writing. For this reason, a &quot;word count&quot; function is completely critical to me for whatever word processor or text editor I&#8217;m using to write.</p>
<p><a class="reference external" href="http://jedit.org/">jEdit</a> has such a feature. It&#8217;s more or less the same as the one that I&#8217;ve been using in <a class="reference external" href="http://abisource.com/">AbiWord</a>, and in various word processors before that. But for quite some time I&#8217;ve wanted a better word counter. Since <cite>jEdit</cite> is now my <a href="http://tadhg.com/wp/2009/07/12/moving-from-word-processors-to-restructuredtext/" title="Moving From Word Processors to reStructuredText" >application for all writing</a> and I <a href="http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/" title="jEdit Macros in Jython" >can script for it in Python</a>, it was time to make the word counter I wanted.<br />
<span id="more-1934"></span><br />
The problem was fairly simple: most applications only consider a few characters to be word separators, typically the line-end character, the space, and the tab. I think I&#8217;ve encountered some word processor that let you add more separators yourself, but I can&#8217;t remember what it was (possibly an earlier version of <a class="reference external" href="http://www.openoffice.org/">OpenOffice.org</a>.</p>
<p>What about dashes, though? The phrase &quot;double standard—I don’t&quot; has four words in it, but almost all applications would report that as being three words long. Similar instances include &quot;either/or&quot;, &quot;in&amp;out&quot; (granted, there really should be a space there, but it&#8217;s still not one word), and &quot;thirty–forty minutes&quot; (the elusive en dash makes an appearance). Save for that one word processor I can&#8217;t remember, no tool would account for those correctly.</p>
<p>Furthermore, the double hyphen is used often as a stand-in for the em dash, and the ellipsis is used without spaces from time to time (not a strictly correct practice, but sometimes style takes precedence), and I wanted a word count that would correctly deal with all of these eventualities.</p>
<p>Here it is, as a jEdit macro written in Jython (meaning it requires the <a class="reference external" href="http://plugins.jedit.org/plugins/?JythonInterpreter">JythonInterpreter</a> plugin):</p>
<pre class="python literal-block">
def word_count():
    &quot;&quot;&quot;
    jEdit macro for better word count.
    &quot;&quot;&quot;
    import re
    from org.gjt.sp.jedit import Macros

    LINE_SEPARATORS = (
        &quot;\r&quot;,
        &quot;\n&quot;
    )

    WORD_SEPARATORS = (
        &quot; &quot;,        # space
        &quot;\t&quot;,       # tab
        &quot;/&quot;,        # slash
        &quot;&amp;&quot;,        # ampersand
        u&quot;\u2013&quot;,  # en dash
        u&quot;\u2014&quot;,  # em dash
    )

    REPEATER_SEPARATORS = (
    #These are only separators if they're present consecutively, e.g. -- or ..
        &quot;-&quot;,
        &quot;.&quot;
    )

    # get local reference to textArea
    textArea = view.getTextArea()

    chars, words, lines = 0, 0, 0
    selection = textArea.getSelection()

    if len(selection) == 0:
        text = textArea.getText()
    else:
        text = textArea.getSelectedText()

    chars = chars + len(text)
    lines = lines + 1

    #go through the text character by character:
    word, previous_character = 0, None
    for character in text:
        if character in (LINE_SEPARATORS + WORD_SEPARATORS) or (character in REPEATER_SEPARATORS and previous_character in REPEATER_SEPARATORS):
            #it's a separator
            word = 0
            if character in (LINE_SEPARATORS):
                lines = lines + 1
        else:
            #it's part of a word.
            if not word:
                words = words + 1
                word = 1
        previous_character = character

    message = &quot;Characters: %s\nWords: %s\n Lines: %s&quot; % (chars, words, lines)
    Macros.message(view, message)

if __name__ == '__main__':
    word_count()
</pre>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/jython/" rel="tag">Jython</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/software/" rel="tag">software</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/writing/" rel="tag">writing</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/">jEdit Macros in Python</a> <span class="related-post-date timestamp">Fri 17 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/">Some Character Encoding Gotchas</a> <span class="related-post-date timestamp">Thu 16 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/12/moving-from-word-processors-to-restructuredtext/">Moving From Word Processors to reStructuredText</a> <span class="related-post-date timestamp">Sun 12 Jul 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jEdit Macros in Python</title>
		<link>http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/</link>
		<comments>http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 00:57:54 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Jython]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=1926</guid>
		<description><![CDATA[jEdit has long been my text editor of choice, and I&#8217;m using it more than ever now that I&#8217;m writing more or less everything in it. I&#8217;ve been waiting a while for 4.3 to come out, but overall I remain quite happy with it. I do occasionally wonder about switching to vim or Emacs, but [...]]]></description>
			<content:encoded><![CDATA[<p><a class="reference external" href="http://jedit.org/">jEdit</a> has long been my text editor of choice, and I&#8217;m using it more than ever now that <a href="http://tadhg.com/wp/2009/07/12/moving-from-word-processors-to-restructuredtext/" title="Moving From Word Processors to reStructuredText" >I&#8217;m writing more or less everything in it</a>. I&#8217;ve been waiting a while for 4.3 to come out, but overall I remain quite happy with it. I do occasionally wonder about switching to <a class="reference external" href="http://www.vim.org/">vim</a> or <a class="reference external" href="http://www.gnu.org/software/emacs/">Emacs</a>, but jEdit&#8217;s generally been able to do whatever I wanted it to.</p>
<p>I haven&#8217;t done much scripting with it, though. I recently came up with some use cases for scripts—involving reStructuredText, naturally—but I was a little reluctant to do the scripting because it involves Java and I really want to keep my current focus on Python and JavaScript.</p>
<p>I was therefore rather happy to discover the existence of the <a class="reference external" href="http://plugins.jedit.org/plugins/?JythonInterpreter">JythonInterpreter plugin</a>, which makes it possible to write macros for jEdit in Python.<br />
<span id="more-1926"></span><br />
I grabbed it and to try it out wrote a macro that looks for all the substitutions and link references in a file, then places corresponding lines at the bottom. That is, if you had the following reStructuredText:</p>
<pre class="literal-block">
`jEdit`_ has long been my text editor of choice, and I'm using it more than ever now that |I'm writing more or less everything in it|.
</pre>
<p>and you ran this script, you&#8217;d have this:</p>
<pre class="literal-block">
`jEdit`_ has long been my text editor of choice, and I'm using it more than ever now that |I'm writing more or less everything in it|.

.. |I'm writing more or less everything in it|
.. _jEdit:
</pre>
<p>Thus saving me the hassle of copying and pasting all of them manually. It works pretty well so far. Here&#8217;s the source if any jEdit and reStructuredText people are reading this (remember that you need the <a class="reference external" href="http://plugins.jedit.org/plugins/?JythonInterpreter">JythonInterpreter plugin</a> to make it work):</p>
<pre class="python literal-block">
def get_references():
    &quot;&quot;&quot;
    jEdit macro that finds all of the substitutions and links in the file and places corresponding references to them at the bottom of the file.
    &quot;&quot;&quot;
    import re

    # get local reference to textArea
    textArea = view.getTextArea()

    # current caret:
    caret = textArea.getCaretPosition()

    lines = textArea.getText().split('\n')

    #Substitutions:
    subs = {
        &quot;find&quot;: re.compile(&quot;\|[^\|]+\|&quot;),
        &quot;replace&quot;: lambda hit: &quot;.. %s &quot; % hit
    }
    #Links:
    lrefs = {
        &quot;find&quot;: re.compile(&quot;`[^`]+`_&quot;),
        &quot;replace&quot;: lambda hit: &quot;.. _%s: &quot; % (hit[1:-2])
    }

    #Citations and footnotes:
    frefs = {
        &quot;find&quot;: re.compile(&quot;\[[^`]+\]_&quot;),
        &quot;replace&quot;: lambda hit: &quot;.. %s &quot; % (hit[0:-1])
    }

    #the function to run for each operation:
    def run_ops(lines, opdict, matchlist):
        for line in lines:
            if not line.startswith(&quot;.. &quot;):
                search = opdict[&quot;find&quot;].findall(line)
                for hit in search:
                    hit = opdict[&quot;replace&quot;](hit)
                    matchlist.append(hit)
        return matchlist

    #run the operations in desired order:
    matches = []
    for op in [subs, lrefs, frefs]:
        run_ops(lines, op, matches)

    #Put the matches into a string:
    mstring = &quot;\n&quot;.join(matches)
    mstring = &quot;\n\n%s&quot; % mstring

    #Go to the end of the buffer and insert the string:
    textArea.goToBufferEnd(0)
    endcaret = textArea.getCaretPosition()
    textArea.getBuffer().insert(endcaret, mstring)

    #Go back to the original cursor position:
    textArea.setCaretPosition(caret)

if __name__ == '__main__':
    get_references()
</pre>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/java/" rel="tag">Java</a>, <a href="http://tadhg.com/wp/tag/jython/" rel="tag">Jython</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/19/better-word-count-in-jedit/">Better Word Count in jEdit</a> <span class="related-post-date timestamp">Sun 19 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/09/24/rtf_word_restructuredtext-toolchain/">RTF/Word–reStructuredText Toolchain</a> <span class="related-post-date timestamp">Thu 24 Sep 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/08/02/python-script-for-subversion-status/">Python Script for Subversion Status</a> <span class="related-post-date timestamp">Sun 02 Aug 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/">Some Character Encoding Gotchas</a> <span class="related-post-date timestamp">Thu 16 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/12/pylons-via-apache-port-issues/">Pylons Via Apache Port Issues</a> <span class="related-post-date timestamp">Fri 12 Jun 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/07/17/jedit-macros-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some Character Encoding Gotchas</title>
		<link>http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/</link>
		<comments>http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 18:31:32 +0000</pubDate>
		<dc:creator>Tadhg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://tadhg.com/wp/?p=1919</guid>
		<description><![CDATA[While scripting my reStructuredText to WordPress workflow, I ran into a bunch of character encoding problems.

The first thing to keep in mind is that character encoding is not a metadata property of a file. That is, unless a file type itself has some metadata that includes encoding, the only way the OS can determing character [...]]]></description>
			<content:encoded><![CDATA[<p>While scripting my <a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/" title="Moving From Word Processors to reStructuredText" >reStructuredText to WordPress workflow</a>, I ran into a bunch of character encoding problems.<br />
<span id="more-1919"></span><br />
The first thing to keep in mind is that character encoding is not a metadata property of a file. That is, unless a file type itself has some metadata that includes encoding, the only way the OS can determing character encoding is by reading the file and guessing.</p>
<p>I knew this, but despite having been caught by this before, I “knew” it in the sense that if you had asked me whether or not there&#8217;s some way outside the file for the OS to know what the encoding is, I would have answered “no”. However, that didn&#8217;t stop me from acting as if some such magical property existed.</p>
<p>I started out by playing with <tt class="docutils literal"><span class="pre">rst2html</span></tt> and opening its output in Firefox. As far as character encoding went, that was fine. Then I switched to <tt class="docutils literal"><span class="pre">rst2wp</span></tt>, which outputs a truncated version of the HTML containing essentially just the body text that you&#8217;re going to paste into WordPress. It worked, but the character encodings were screwed up. I spent a lot of time searching for what the difference between the two was in the source code before finding the obvious answer: <tt class="docutils literal"><span class="pre">rst2wp</span></tt> outputs just the body text.</p>
<p>In other words, it outputs to a file that doesn&#8217;t contain this:</p>
<pre class="html literal-block">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;body&gt;
</pre>
<p>Without that, the browser has to guess what the encoding is. Looking at the source code doesn&#8217;t help either, because that source code is also rendered in whatever the browser thinks the encoding is (which makes sense).</p>
<p>After I got past that issue, the next one involved writing to standard output from Python. This was consistently screwed up, and I couldn&#8217;t figure it out because when I sent the output to Terminal, the encodings were fine. But if I ran the same script either piped to another script, or outputting to <tt class="docutils literal"><span class="pre">stdout</span></tt> from within the script, they were wrong. It turns out that <a class="reference external" href="http://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/">you need the <tt class="docutils literal"><span class="pre">LC_CTYPE</span></tt> environment variable</a> to be set appropriately in order for Python to write your desired encoding to <tt class="docutils literal"><span class="pre">stdout</span></tt>, e.g. (for tcsh):</p>
<pre class="literal-block">
setenv LC_CTYPE en_US.utf-8
</pre>
<p>(Substituting <tt class="docutils literal"><span class="pre">en_US.utf-8</span></tt> for your preferred encoding, of course.)</p>
<p>This last one is specific to OS X. I&#8217;m copying to and from the clipboard using <tt class="docutils literal"><span class="pre">pbpaste</span></tt> and <tt class="docutils literal"><span class="pre">pbcopy</span></tt> as well as the usual keyboard shortcuts. When doing that from my scripts, the character encodings would get screwed up. To force OS X to use UTF by default, <a class="reference external" href="http://sigpipe.macromates.com/2005/10/11/clipboard-access-from-shell-utf-8/#comment-114">you need to set <tt class="docutils literal"><span class="pre">defaultStringEncoding</span></tt></a>, which is done in tcsh with:</p>
<pre class="literal-block">
setenv __CF_USER_TEXT_ENCODING 0x1F5:0x8000100:0x8000100
</pre>
<p>Note that <tt class="docutils literal"><span class="pre">0x1F5</span></tt> refers to your <tt class="docutils literal"><span class="pre">uid</span></tt>, in this case 501 expressed in hex.</p>
<p>Hopefully those three tips will save some readers a little pain in their scripting.</p>
<p>Tags: <a href="http://tadhg.com/wp/tag/coding/" rel="tag">coding</a>, <a href="http://tadhg.com/wp/tag/python/" rel="tag">python</a>, <a href="http://tadhg.com/wp/tag/tech/" rel="tag">tech</a>, <a href="http://tadhg.com/wp/tag/web-development/" rel="tag">web-development</a></p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://tadhg.com/wp/2009/07/28/better-rest-wordpress-pipeline/">Better reST–WordPress Pipeline</a> <span class="related-post-date timestamp">Tue 28 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/07/14/blog-workflow-with-restructuredtext/">Blog Workflow with reStructuredText</a> <span class="related-post-date timestamp">Tue 14 Jul 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/12/pylons-via-apache-port-issues/">Pylons Via Apache Port Issues</a> <span class="related-post-date timestamp">Fri 12 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/06/09/pywebsf-meetup-for-sf-area-python-web-developers/">PyWebSF: Meetup for SF-Area Python Web Developers</a> <span class="related-post-date timestamp">Tue 09 Jun 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/16/some-vim-script-implementation-testing-and-hackery/">Some Vim Script Implementation, Testing, and Hackery</a> <span class="related-post-date timestamp">Tue 16 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/02/14/first-post-with-vim/">First Post With Vim</a> <span class="related-post-date timestamp">Sun 14 Feb 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/17/better-word-count-in-vim/">Better Word Count in Vim</a> <span class="related-post-date timestamp">Sun 17 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2010/01/10/wordpress-2-9-upgrade/">WordPress 2.9 Upgrade</a> <span class="related-post-date timestamp">Sun 10 Jan 2010</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/12/08/gps-urls-math-python-featuritis/">GPS, URLs, Math, Python, Featuritis</a> <span class="related-post-date timestamp">Tue 08 Dec 2009</span></li><li class="related-post"><a href="http://tadhg.com/wp/2009/11/17/addons-mozilla-org-moving-from-cakephp-to-django/">addons.mozilla.org Moving from CakePHP to Django</a> <span class="related-post-date timestamp">Tue 17 Nov 2009</span></li></ul>]]></content:encoded>
			<wfw:commentRss>http://tadhg.com/wp/2009/07/16/some-character-encoding-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
