William Roe

Supreme Nerdery

What Font Is That?

I often come across web pages that use fonts that I like and wonder what they are (I’m not that good at guessing fonts). On the whole this situation happens while reading on my iPhone because that’s the only high-resolution screen I use - good fonts look amazing on the iPhone 4S.

This just happened to me while reading a post linked from daring fireball - the “of course” principle of design. I really liked the look of that font on the iPhone. (I also noted that I should reduce the margins on my blog for small screens because you have to zoom to read really). So how, on an iPhone, you do find out what font that is?

What I wanted was a bookmarklet, so I searched for “what font bookmarklet” and found WhatFont Tool which provides a powerful bookmarklet for finding out what font a page is using (and whether it is from Google webfonts or Typekit). Problem is, bookmarking JavaScript is not easy on the iPhone - you have to copy/paste the JavaScript somehow. Because WhatFont only provides a button (to drag to your bookmarks bar), I had to find another way. I decided to try the Mercury web browser, guessing it might have a way to copy the JavaScript for a link/button. Thankfully I was right and it allowed me to copy the JavaScript, then switch to Safari and create then edit a bookmark for it. It works wonderfully. Just touch the bookmark to active it, then touch any piece of text on a website to see info on what fonts it’s using. Simple.

For your copy/paste convenience, I have provided the code for the WhatFont bookmarklet:

1
javascript:(function(){var%20d=document,s=d.createElement('scr'+'ipt'),b=d.body,l=d.location;s.setAttribute('src','http://chengyinliu.com/wf.js?o='+encodeURIComponent(l.href)+'&t='+(new%20Date().getTime()));b.appendChild(s)})();

Turned out that that post was using Crimson Text from Google Webfonts. Nice.

It looks like Crimson Text is a promising free font that might have Polytonic Greek characters at some point so that’s useful to know for me.

Further Haskell Exploration

Today I decided to embark on an exploration of Haskell web development. I have previously bootstrapped a basic Snap setup but never got into actual hacking. Today I decided to give Yesod a go. I ran into a number of difficulties that drained away all my spare time this evening but in the end I feel like I’m ready to dive in tomorrow.

I started off by attempting to install Yesod, with a simple cabal install yesod. This command took about 10 minutes to finish compiling dependencies on my ThinkPad X61 before it died with an error. The problem seemed to be the version of haskell-platform was rather out-of-date, meaning a tool, called alex was too old for Yesod. To solve this rather small issue I took the rather drastic step of upgrading Ubuntu on the ThinkPad to Precise Pangolin because this includes the latest haskell-platform…and its all new and…just because! This is Ubuntu after all - trigger happy upgrades are the name of the game.

Meanwhile, in Mac land. While that upgrade was running I tried to run the new yesod web app on a Mac. Unfortunately I ran into all the problems I’ve encountered before with cabal-dev on OS X.

Firstly there’s some weirdness with cabal-dev being set to install everything in the system library location. This just makes no sense for cabal-dev - the whole point is for it to install libraries in a vendored, per-project location - not interfering with system libraries. It manifested itself as asking for a password all the time (turn on verbose -v3 to see it running all cabal commands with sudo - O_o). To fix that you edit the config file, outlined in a blog post I found. Annoying.

Another problem I had was ghc/ld spamming the terminal with loads of linker warnings. This really slowed down compilation. I didn’t really solve this (happened on my Mac Mini - didn’t happen on my work MacBook Air). I remember having to set options for GHC to silence that crap, but I forget the details…

In order to get it all working on my Mac I:

  • Uninstalled haskell-platform (this is homebrew installed for me)
  • Re-installed haskell-platform
  • cabal installed cabal-dev, yesod

Everything worked then. There’s also strange voodoo you have to run to unregister old packages - brew info haskell-platform splits out the necessary commands.

After all that, things worked…mostly. Currently there seems to be some car crash of dependencies caused by a new release of something called tls-extras. A helpful stranger in IRC (#yesod) told me to cabal-dev install tls-extra-0.4.2.1 - this forces a working version of that library and then you can happily install yesod and everything’s groovy.

Who said Haskell was difficult? Not me.

So now I have a skeleton Yesod project up and running and it’s all looking very promising. The helper script for creating projects gave me some confidence - specifically asking if I wanted sqlite, postgres, MongoDB or nothing seemed pretty good to me - this doesn’t appear to be a web framework/persistence system tied to a particular way of doing things.

The main reason why I decided to dive into Yesod however was the high volume of interesting yesod-related blog traffic - this is a pretty crucial metric in gauging the health of a library community in my opinion and my RSS reader has been bombarded with posts about it so I felt I had to see what all the fuss was about.

Hopefully happy Haskell hacking henceforth

Learning Haskell

So I have started to learn Haskell (again - I learned the basics at university for the Functional Programming class and loved it, I have since forgotten most of that).

Haskell is weird

When you first start out learning this language - or even just read some articles about it - the first thing that will strike you is that it seems completely obscure. The syntax is obscure, the concepts are obscure, but most of all - the language used to describe what things are is incredibly obscure. Every programming language community has evolved its own lingo of course and Haskell’s is awash with mathematics. If you subscribe to the planet Haskell RSS feed you will get the impression that Haskell is pretty much just an extension of Mathematics and is only used for “pure” problems and therefore completely irrelevant to real world problems. Then you will notice there’s a book called “Real World Haskell” and you’ll think it an anomaly, just some noise in the data.

Why learn this?

Apart from wanting to become a better programmer in general (which would explain why I’d want to learn functional programming in general and in more detail than I already do from Erlang and Clojure), I want to learn how Haskell can be a practical language - how it can help me create great products. I suspect that behind the terseness and high degree of greek characters is a toolkit that will be at least as empowering as Erlang/OTP has been. I want that toolkit.

The elephant in the room

Sooner or later you will arrive at the Haskell trial stage. In order to print anything out from your programme, or accept any input or read a file etc. you will have to use monads. At first the syntax will seem very strange, just a load of terse boilerplate for doing what more pragmatic languages make super easy, but you’ll think “whatever, let’s just get on with learning this thing”. At some point the tutorial or book you’re reading will have to explain monads to you. More than likely this is the point where you stared at the screen/page in disbelief and your heart sank as you realised you would have to understand level 3000 mathematics to print something on screen. For most people, this is the last they ever deal with Haskell.

Later on, a Haskell wizard will act all puzzled and amused that you found monads hard to understand. This will lower your self-esteem so low you consider giving up entirely and becoming a farmer instead. They will go on to tell you that you’ve been using monads the whole time in whatever programming language you like. They will explain how this is so and you will not be enlightened. It’ll sound all too convenient, just a bunch of semantic drivel.

The reason so many of us have such a frustrating initial experience with Haskell is that most of the books on the subject are appallingly badly written. Programming books are in general a complete shambles and very few are useful to anyone who isn’t already pretty hot at the whole thing anyway. If you were lucky enough to find a well-written helpful introduction to Haskell (there are some), then you might not be feeling this way. Also if you were born a Haskell wizard, this will sound like complete gobbledegook to you. But then you’re not really human now are you? Admit it.

Anyway, I will be attending the Haskell hoodlums meetup this Thursday so hopefully I’ll start understanding this thing. Don’t give up people! Good luck.

David Cameron on AV

David Cameron:

“I just feel it, in my gut, that AV is wrong. Politics shouldn’t be some mind-bending exercise.

British people are pretty thick. I mean, have you seen them? I seriously doubt they understand the whole “tick the party you want in government” thing - how are they going to understand they can actually vote for their views with this system. Given that we’ve slashed education funding, it’s unlikely we’re gonna end up with a whole lot of people who can understand anything about politics, which is how we like it. Nice and stupid. Means we don’t have to say anything meaningful to get them to vote for us.

“It’s about what you feel in your gut – about the values you hold dear and the beliefs you instinctively have. And I just feel it, in my gut, that AV is wrong.

Gut feeling as a way to decide who should be in power. So a knee-jerk reaction is what we’re looking for, we don’t want Brits having to look at the policies of the parties - we want them to vote tribally.

“There are three big problems with AV that strike at the heart of how I believe our democracy should work. First, I believe power should lie with the people – and AV would take some of that power away.

I’m not going to explain why it takes power away because obviously it doesn’t. All you need to do is vote once to get the exact same vote as you would under FPTP, so the system doesn’t take any power away from the individual. But this is some scary sounding rhetoric. Hopefully people will be scared enough not to question the assertion.

“Second, I believe there should be real accountability between the pledges politicians put in their manifestos and the action they take in government.

Because this is obviously the case now. Also it’s easy for me, we didn’t put any actual pledges in the Conservative manifesto, so it looks like we’ve stuck to it pretty closely.

“AV would damage that chain of accountability. And third, I believe in the principle of one person, one vote.

I have no actual reason for saying no to AV except it would make us work harder to retain those safe seats.

“If you want a system that makes your politicians accountable. “If you want a system that enshrines the principle of one person, one vote. “You must vote on May 5th, and you must vote No to AV. “The biggest danger right now is that Britain sleepwalks into this second-rate system, waking up on May 6th with a voting system that damages our democracy. “We must not let that happen. So we’ve got to get out there and fight, and get out there and win.”

Voting for something is like sleep-walking because all the people voting YES are all asleep. Let’s keep Britain’s electoral system thoroughly in the dark ages!

How to Install Ubuntu Natty on the Sony Vaio VPC Y21 S1E

This is a howto guide for installing Ubuntu Natty on the troublesome Sony Vaio VPC-Y21-S1E. I say troublesome because no distribution of Linux installs a fully working system on this laptop to the best of my knowledge, even though the hardware is all very common and not very new. Owning this laptop and running Linux is like going back in time to the early 2000s when installing Linux was a week’s work on any machine. It’s horrendous that even distros that favour ease of use by default have yet to achieve good hardware support.

Step 1 - install Ubuntu

I used the alternative amd64 ISO image for this (and a USB CDROM drive). The text mode installer worked fine as usual and installed in an hour or so. Not exactly quick, but probably that’s due to very slow IO on this machine.

Once Ubuntu Natty is installed and reboots into your new system, you will notice a couple of things. Firstly the graphics will be running in some kind of generic mode with the wrong resolution. The native resolution of this panel is the now relatively standard 1366x768 of this class of laptop. Out of the box though, Ubuntu will boot in 1024x768 and it looks horrendous. According to Xorg.0.log it will select the VESA driver instead of the intel one it should be using. This is why it will start in unaccelerated, not much works mode. Needless to say, Unity will not be making an appearance yet. I think this is because there is a regression in the 2.6.36 kernel - according to another user of this laptop, the previous kernel version (2.6.37rc8) should work fine.

Step 2 - get a working kernel

You’re going to need to get the network setup before you can do anything useful. Out of the box, I’m not sure if the wireless is working or not because no mouse will work. The touchpad does nothing and any mouse I plugged in didn’t work either. This is extremely poor if even a simple USB mouse won’t work.

The first thing to try is to get a working kernel installed. I headed here Index of /~kernel-ppa/mainline/v2.6.37-rc8-natty to get the headers and image packages for the amd64. It’s pretty difficult to get anything onto the laptop since USB isn’t working at all under Natty. I tried using a USB flash drive to copy the kernel files over - no luck. So what I did was shorten the kernel-ppa link http://bit.ly/ieDkmQ, connected the laptop to my ADSL router with an ethernet cable and downloaded those files. I had to keep telling myself it was in fact still 2011.

Once I’d installed the older kernel and rebooted, things started to work. The bootup screen was garbled however and I got what looked like a kernel panic, with a stackframe all over the place - but it wasn’t because I could switch to a random VC and back to the 7th VC and see GDM there. It’s just a complete mess. I think I’m gonna have to disable the bootspash stuff because it’s so incredibly messed up (for every other install of Linux on this laptop I’ve had to do that).

Step 3 - Change the default kernel

We need to change the default kernel that boots to avoid booting a broken kernel every time we turn the laptop on.

  • Set GRUB_DEFAULT=saved in the file /etc/default/grub, so we can set the default kernel.
  • I wanted to find out what the menuentry is for the kernel I’ve just installed, so I ran:
1
grep menuentry /boot/grub/grub.cfg

This will print out every entry in GRUB. This is all from the Grub2 page.

  • Now use the appropriate menuentry to set as the default. If you installed the same one I did, then that will be “Ubuntu, with Linux 2.6.37-020637rc8-generic”:
1
sudo grub-set-default 'Ubuntu, with Linux 2.6.37-020637rc8-generic'
  • Save all that to grub:
1
sudo update-grub

That’s it, should be set now. This didn’t work for me though. With ever release of grub and ubuntu tools, it gets more and more difficult to do simple things. It’s cool that update-grub can detect all the OSes on your hard drive and boot them (it ignored the other Ubuntu install ironically so it’s not included in the boot menu, pretty silly bug). But please! the ability to set a default kernel or menuentry should be easy and should work. In the end, I set GRUB_SAVEDEFAULT=true in /etc/default/grub and chose the kernel I wanted so that in future it’ll boot that one every time. What a joke.

For my sanity, I turned off the bootscreen which, on this laptop is severly broken. Even though I’ve turned the boot splash off, I still have to switch to another VC and back to 7 to see the GDM login screen. Broken.

Step 4 - Getting wireless working

Now we have the mouse working, and USB mice work and graphics are as good as you’ll probably ever get on Linux (i.e. not great).

Wireless is disabled though and you can’t enable it from the networking icon (Network Manager). This is an issue I’ve had with Ubuntu on this machine before and I had to dig around to find out how to force it to be enabled.

Enabling the wirelss is not a simple task. It involves messing around with rfkill and it’s not a simple matter of running rfkill unblock all either - which is maddening. The wireless card is still soft-blocked after that. (Hard blocked means the hardware switch is off and soft blocked means it’s turned off in software somewhere).

I couldn’t find the solution by googling and browsing a million Ubuntu forum threads, but checking my /etc/modprobe.d/ directory in the other Ubuntu install pointed the way. You need a file with the following contents:

1
blacklist acer-wmi

I called that file blacklist-acer-wmi.conf and this time I remembered to copy it into my Dropbox folder so that I won’t forget about it again.

Suspend

Suspend and resume works with Natty! Yay! It didn’t work on this laptop with Maverick. So we have some progress.

Multiple monitors

I tried plugging a VGA monitor in and it was detected and the correct resolution was selected. Wonderful. However, when I tried to change the layout of the monitors, it messed up completely and I ended up with random desktops being drawn all over the monitors. Unplugging and plugging the monitor in fixed that, with only some minor rendering issues (there was a black border around much of the second desktop that went away when I moved a window around). This sort of thing should have been sorted a long time ago, it’s tiresome to be messing around with such a mess.

Other problems

  1. When you launch the Update Manager, it still reports everything is up do date without checking first. This is really stupid, having to click on “Check” to download the latest package definitions before it realises there are updates to install. It should take the fact that you’ve deliberately openned Update Manager for the sole purpose of checking whether your software is up-to-date and not tell you out-of-date information.
  2. Keyboard navigation is still horrible in Gnome (that’s the Classic desktop thing that Ubuntu puts you in if there are problems with your drivers - very likely).

Summary

Linux and Ubuntu have a very long way to go before they can start to compete with the commercial alternatives. Although Unity is a refreshing innovation on desktop interfaces, it really needs to be backed up with great hardware support and general ease of use that goes a little more than skin deep.

I think I will be posting a review of Natty later - that will focus on Natty as a working system, rather than specific to this laptop. So far though, having used it for a couple of hours setting up my environment, it’s a great system. It needs a lot more QA to sort out the hardware and system problems though.

Parsing and Ebook Making

I have just finished a 6 hour hacking session on parse_perseus. The aims were to fix most of the encoding problems, split the content up into books and create a table of contents. Other than a few problems with encoding, I managed to complete all that.

Tables of contents

The table of contents was a bit strange. The Kindle’s mobi format pretty much ignores the epub standard .ncx file (which is an XML file that contains <navPoint> elements that get mapped to entries in a generated table of contents - Adobe Digital Editions uses this for example). Here’s an abridged version of the NCX file I had generated:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
   "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en">
  <head>
    <meta name="dtb:uid" content="http://en.wikipedia.org/wiki/The_Odyssey"/>
    <meta name="dtb:depth" content="1"/>
    <meta name="dtb:totalPageCount" content="0"/>
    <meta name="dtb:maxPageNumber" content="0"/>
  </head>
  <docTitle>
    <text>Ὀδύσσεια</text>
  </docTitle>
  <navMap>
    <navPoint id="toc" playOrder="0">
      <navLabel>
        <text>Table of Contents</text>
      </navLabel>
      <content src="toc.html"/>
    </navPoint>
    <navPoint class="chapter" id="book-1" playOrder="1">
      <navLabel>
        <text>Book 1</text>
      </navLabel>
      <content src="book-1.xhtml"/>
    </navPoint>
  </navMap>
</ncx>

There were obviously more chapters/books than that. The Kindle/mobi format doesn’t use this for the table of contents, so when you open a converted epub on a Kindle (or using the Kindle desktop software), the menu item to go to the table of contents is greyed out. After digging around on the web I discovered that the mobi format uses a toc file, which is basically an html file full of links. In order for that to work, you need to reference the toc file in the OPF file. Here’s an abbreviated version of the one I generated:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="2.0"
   unique-identifier="odyssey_gk">
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:dcterms="http://purl.org/dc/terms/"
      xmlns:opf="http://www.idpf.org/2007/opf"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <dc:title>Ὀδύσσεια</dc:title>
    <dc:language xsi:type="dcterms:RFC3066">en-us</dc:language>
    <dc:identifier id="odyssey_gk" opf:scheme="URL">
             http://en.wikipedia.org/wiki/The_Odyssey
    </dc:identifier>
    <dc:creator opf:file-as="Homer" opf:role="aut">Homer</dc:creator>
    <meta name="cover" content="cover-image"/>
  </metadata>
  <manifest>
    <item id="book-1" href="book-1.xhtml" media-type="application/xhtml+xml"/>
    <item id="stylesheet" href="style.css" media-type="text/css"/>
    <item id="ncx" href="book.ncx" media-type="application/x-dtbncx+xml"/>
    <item id="cover" href="cover.html" media-type="application/xhtml+xml"/>
    <item id="toc" href="toc.html" media-type="application/xhtml+xml"/>
    <item id="cover-image" href="cover.jpg" media-type="image/jpeg"/>
  </manifest>
  <spine toc="ncx">
    <itemref idref="cover" linear="no"/>
    <itemref idref="toc" linear="no"/>
    <itemref idref="book-1"/>
  </spine>
  <guide>
    <reference href="cover.html" type="cover" title="Cover"/>
    <reference href="toc.html" type="toc" title="Table of Contents"/>
    <reference href="book-1.xhtml" type="text" title="Text"/>
  </guide>
</package>

The important bit there is the <reference> element inside <guide> that is of type “toc”. After that, the actual table of contents file is pretty straightforward:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Table of Contents</title>
    <style type="text/css">img { max-width: 100%; height: 100% }</style>
  </head>
  <body>
    <div id="contents">
      <h2>Contents</h2>
      <ul>
        <li>
          <a href="book-1.xhtml">Book 1</a>
        </li>
      </ul>
    </div>
  </body>
</html>

That’s just a standard content file and can be formatted, using CSS, the way you want it rendered on the e-reader.

Encoding

I managed to solve the problem I was having rendering the correct unicode for Iota Dialytika Tonos. I don’t expect anyone to know what that is, I didn’t and it’s still just a character to me. But it looks like this:

ΐ

In betacode, this is written as i/+. Normally, the parser encodes the character i, then each diacritic in turn: /, then + into combining diacritics. This resulted in characters 0x03b9 0x0301 0x0308, which would be normalized using Java’s Normalizer/normalize function as:

ί̈

The frustrating thing is that it’s quite difficult to tell the difference on the terminal, when running tests - even when I’d bumped the font size up to crazy levels.

In order to match that symbol, I created the following rule:

1
2
3
(def iota-dialytika-tonos
     (constant-semantics (lit-conc-seq "i/+" lit)
                         (char 0x0390)))

Then I’d redefined character to be:

1
(def character (alt iota-dialytika-tonos final-sigma upper-char lower-char))

Which means that the rule iota-dialytika-tonos takes precedence over any other character (to prevent the dumb combining diacritic rules from matching it).

And that brings me on to final sigma. Final sigma has given me quite a lot of pain, ever since I started building this parser. For those of you who don’t know Greek, like me, they have two sigma characters - one is used in the middle of a word:

σ

But if sigma is at the end of a word, it must use the final sigma character, thus:

ς

The problem with matching something at the end of a word is that fnparse’s matchers are mostly greedy. There’s no equivalent rule, as far as I can tell, to the regular expression (.+)s. The rep+ rules always greedily gobble all the tokens, including the last s. At the moment, all I have is the following rule for final sigma:

1
2
3
(def final-sigma (constant-semantics (lit-conc-seq "s " lit)
                                     (str (char (- (beta-char-to-greek-char \s) 1))
                                          \space)))

This isn’t ideal because it can’t match either the last s of the last word in a string (or line), or s followed only by a non-character (such as :). This is something I have to work on, but fnparse isn’t making it easy for me here.


References

  • fnparse which is awesome for taming parse-m monads in Clojure.
  • Thanks to Greek Diacritics for information about combining diacritics.
  • EPUB Wikipedia’s writup on the EPUB standard is almost all you need.
  • OPF The OPF/NCX standard.
  • The Odyssey From the Perseus Digital Library, the source for the XML files I have been consuming in this project.

NaNoWriMo Begins

I’ve started to write my book for NaNoWriMo. For those who don’t know, the goal is to write a novel (or, more accurately, a first draft of a novel) in a month - November. A novel, in this competition is defined as a work of fiction totaling 50,000 words. It sounds like a lot for a month initially. Then you break that down to 1,667 words per day - which sounds manageable - I tried writing a chapter last month and got 2,033 words done in about an hour and a half.

Day 1 of November proceeded in the same way every day had for the last couple of weeks. Suffice to say I have been rather overloaded at work and have had to put in a lot of hours - usually till about half past midnight to get things done. This is not a good recipe for becoming a best selling author. Day 1, therefore, ended with a word count of zero. Having committed myself to this challenge, I felt the failure keenly.

Day 2 of November showed no signs of being any different. This time, however, I was determined to get writing, whatever happened. I left work as soon as I could, squeezed myself onto the overcrowded train to Clapham Junction and popped into Debenhams to pick up my repaired watches. Even though I was eager to get home and get typing, I was in Debenhams so I decided to have a wander around the mens department. Masterful procrastination I know! I must have been there for around half an hour - bought two jumpers, a white shirt and two ties. Debenhams is a dangerous place. Then I finally made my merry way homewards. The rest of the evening involved trying to write while fielding various questions and requests from colleagues on Skype. I don’t recommend this as a strategy for writing or even as a strategy for working. It’s definitely not a good combination for one’s sanity. However, I managed a measly 500 words. I was too embarrassed to update my word count on my profile though and went to sleep feeling defeated.

Day 3 might as well be forgotten entirely. Quite apart from the work I continued to do during the evening, I made no attempt to write anything - content to investigate various programming ideas and generally waste my time watching programmes on the iPlayer…until quite late actually - for no good reason. Novel? What novel?

Today was different. Well, not so much actually. By the time work was over, I was pretty much exhausted. I elbowed, pushed and shoved my way onto the inhumane device some people laughably refer to as public transport and made my way home like a zombie with a mission. Slow but determined. I only hope I have more literally skill than your average zombie. Or failing that, raw typing speed.

So aside from the work I inevitably had to do this evening, I’ve completed 1,788 words, bringing my total so far to 2,288. I am obviously well short of where I should be but I’m hoping I can put some serious typing hours in on the weekend. It’s not like I’ll have anything else to do. Except procrastinate of course.

If anybody else out there in the ether is having problems writing their novel, or writing anything for that matter, rest assured your problems are not unusual. I’m still wavering between determination to complete the challenge to get my first novel written; and defeat, apathy that no matter how hard I try, life will always get in my way. When I was at school, if a teacher had set me homework to write a 2,000 word essay or story, I would have left it to the last minute, written less than half of what was required and handed it in late. If I don’t rise above this pattern of under-achievement now, I fear I never will. So, in summary, I will finish this novel on time. I might not enjoy it, but I will complete it.

Emacs for Android Development

Today I started using Emacs rather than Eclipse to work on an Android project. There are a couple of things you need to get started though.

Firstly you will need the Android SDK (which you will have already if you’ve started with Eclipse Android development) and you need to know where it is located on your hard drive.

There is a mode for Emacs that provides a few Android-related keybindings (for running ant tasks like install/reinstall/compile/start emulator/start ddms etc.), you can find it here: android-mode. Git clone that repository in your .emacs.d directory (~/.emacs.d/), which should already be in your emacs load path. (Emacs config for this later on).

Because Java for Android uses Java 1.5 or above, it will be full of annotations such as “@Override”. The C/Java modes for emacs don’t appear to have been updated to support this syntax so indentation won’t be quite right. To fix this, you need a minor mode called java-mode-indent-annotations.el <- click on the Download link on that page and save the file as ~/.emacs.d/java-mode-indent-annotations.el

Now the emacs config for all the above is as follows:

1
2
3
4
5
6
7
(setq android-mode-sdk-dir "~/android-sdk-mac_86/")
(require 'android-mode)
(require 'java-mode-indent-annotations)

(setq java-mode-hook
    (function (lambda()
       (java-mode-indent-annotations-setup))))

Remember to change the android-mode-sdk-dir to match where you keep your Android SDK. This variable needs to be set before the android-mode is loaded. Also, if you have any other java-mode-hooks defined, you won’t want to setq that variable, but use add-hook ‘java-mode instead - otherwise this will overwrite your existing java-mode hooks.

If you try to use any of the provided keybindings, listed below:

Key binding Function
C-c C-c c android-ant-compile
C-c C-c d android-start-ddms
C-c C-c e android-start-emulator
C-c C-c i android-ant-install
C-c C-c l android-logcat
C-c C-c r android-ant-reinstall
C-c C-c u android-ant-uninstall

They will probably fail because by default, when you start an Android project in Eclipse, it will not create a build.xml file and ant requires this for any of the above to work (you can probably start the emulator though as that doesn’t rely on a per-project build file). So in order to have an ant build file in your project directory you need to run the following command:

1
android update project --name <project_name> --target <target_ID> --path path/to/your/project/

Name and target are optional, as you have most likely already defined those from Eclipse. But in order to list the targets available, run:

1
android list targets

That’s pretty much it. Remember that you can’t run the install task each time because it’ll fail if the project is already installed - just run the reinstall task each time you want to test your changes.

Thanks to fmaj7’s blog where I found most of the information I used to get up and running.