This information is readily available on the GitHub support pages, but I’m posting it here for reference (do I won’t have to dig it out again the next time I need it).

  1. Save this file somewhere and source it from your .bashrc or .bash_profile. This provides all sorts of completion magic for git, but I’m not really sure if it’s required for the prompt trick to work :-)
  2. Update your PS1 to include __git_ps1. Example:
    export PS1='[ \u@\h \w$(__git_ps1 " (%s)") ]\$ '

Voila! You now see the current branch when CWD is inside a git repo:

[ jtj@nova ~/projects/eldorado (railsforum) ]$ 

Talking the talk

January 16, 2010

I have come to realize that I talk a lot about Clojure, but I don’t really use it.

I am very excited about functional programming in general and Clojure in particular, so I spend a lot of time catching up on the news on this front. Lots of stuff going on, always.

The other day I sat back for a moment and looked over the hundreds of blog entries piled up in my reading list. Suddenly I realized that most of these would be conveying actual experiences with some language or framework. Be it Ruby, Clojure, Erlang or what have you, these authors have actually tried something out and written about it.

This is more than I can say for myself, unfortunately. I do have several pet projects underway, but I’m not making nearly as much progress as I would like to. Why? Because I spend way too much time reading about new stuff. Reading about what everybody else have been making progress on.

So I have decided that I need to code more and read less. Pretty much the opposite decision from the one I made a few years ago, but hey, times change. It’s a tough balance to strike properly, but I guess we all do the best we can.

Right now I’m splitting my spare time between two areas: Functional programming and dynamic languages. More specifically Clojure and Rails. I have a lot of ideas for projects in both camps, but like I said I’m spending way too much time catching up. I have seriously considered ditching one of these areas completely, but I just can’t do it. Both are extremely interesting from different points of view.

And since I need be both places at once, I must be very careful about how I spend my time. If I want to move forward with my projects, I can’t afford to spend entire evenings reading up on almost a hundred technical blogs. Even worse, almost every single entry is tempting me to go on out on a tangent. So much interesting stuff to learn, so little time. But I’m not really in it for the learning. What I really love about being a geek is the part where I create new stuff. And I think that is what I’m good at, too.

I really need to start walking the walk. It’s OK that I’ll fall a little behind the newsstream, because I’ll gain a much deeper understanding of the areas I choose to focus on. And before long, I should be able to contribute interesting new stuff on my blog as well.

URL ABC

January 13, 2010

I don’t usually care much about Internet memes, but this one is pretty funny.

Via Mentalized.

It was started by Tim van Damme:

A simple game: Go to the address bar in your favorite browser, and
type one letter. Start with “a”, end with “z”.

Here goes:

I really, really like the Chrome/Chromium browser, and I’ve become more or less addicted to it. The ability to search directly from the address bar (or whatever it’s called) is a small but extremely useful feature. Also, in my experience it is both faster and less resource hungry than the alternatives, Safari and Firefox.

On Linux and Windows, I use it all the time without problems. But on OSX, one issue has just been too annoying to allow me to use Chrome exclusively: The spellchecker can’t be disabled. The issue it tracked here and here, they just haven’t gotten around to fixing it yet. And since I write a lot of email in Danish, all the red underlining it very distracting (I know that it can be disabled for one text field at a time, but that’s not very cool either).

So I decided to roll a custom build. As you would expect, disabling the spellchecker (permanently) is trivial:

Index: chrome/browser/spellchecker_mac.mm
===================================================================
--- chrome/browser/spellchecker_mac.mm	(revision 35439)
+++ chrome/browser/spellchecker_mac.mm	(working copy)
@@ -145,24 +145,25 @@
 static int last_seen_tag_;
 
 bool CheckSpelling(const string16& word_to_check, int tag) {
-  last_seen_tag_ = tag;
+//   last_seen_tag_ = tag;
 
-  // [[NSSpellChecker sharedSpellChecker] checkSpellingOfString] returns an
-  // NSRange that we can look at to determine if a word is misspelled.
-  NSRange spell_range = {0,0};
+//   // [[NSSpellChecker sharedSpellChecker] checkSpellingOfString] returns an
+//   // NSRange that we can look at to determine if a word is misspelled.
+//   NSRange spell_range = {0,0};
 
-  // Convert the word to an NSString.
-  NSString* NS_word_to_check = base::SysUTF16ToNSString(word_to_check);
-  // Check the spelling, starting at the beginning of the word.
-  spell_range = [[NSSpellChecker sharedSpellChecker]
-                  checkSpellingOfString:NS_word_to_check startingAt:0
-                  language:nil wrap:NO inSpellDocumentWithTag:tag
-                  wordCount:NULL];
+//   // Convert the word to an NSString.
+//   NSString* NS_word_to_check = base::SysUTF16ToNSString(word_to_check);
+//   // Check the spelling, starting at the beginning of the word.
+//   spell_range = [[NSSpellChecker sharedSpellChecker]
+//                   checkSpellingOfString:NS_word_to_check startingAt:0
+//                   language:nil wrap:NO inSpellDocumentWithTag:tag
+//                   wordCount:NULL];
 
   // If the length of the misspelled word == 0,
   // then there is no misspelled word.
-  bool word_correct = (spell_range.length == 0);
-  return word_correct;
+//   bool word_correct = (spell_range.length == 0);
+  // return word_correct;
+  return true;
 }
 
 void FillSuggestionList(const string16& wrong_word,

The diff is a bit messy, but I just commented out the entire body of the CheckSpelling method and replaced it with “return true”. As in “Sure, that word is correct” :-)

If you want it, you can download it from here.

Of course, this means that I now use Chromium instead of Google Chrome, but so far I haven’t noticed any adverse effects from making that switch.

I’ve been considering upgrading my Emacs installation on OSX for a while. Until now, I’ve been using Carbon Emacs, and I have been quite pleased with it.

However, Emacs 23 has been the recommended release for a while now, and it’s probably time to move on. So I thought I’d use this entry to sum up my findings so far about making the switch.

The facts

First, a note about naming. “Carbon Emacs” is Emacs 22.x, distributed by Apple (CORRECTION: No, it is built and distributed by Seiji Zenitani. Thanks Ian). Not maintained or supported by Apple, but they have a pretty download page for it nonetheless. As of this writing, the build is about 6 months old.

To get Emacs 23 on the Mac, you need the Cocoa version, called simply “Emacs.app”. It can be downloaded from here, and the current version is 23.1.

Pros

Much nicer fonts

Ah yes, this is what everybody has been talking about. I know very little about typography, but I think it has to do with antialiasing and the fact that Emacs.app uses the Cocoa libraries instead of Carbon (which has been around since Mac OS 9).

The fonts look great. At first I almost couldn’t tell the difference, but it becomes very apparent once you switch to a smaller font. In Carbon Emacs, I never managed to use a 10pt font for very long at a time, because it was pretty hard for me to read. Now, it is very clear. This is obviously a huge improvement because it allows me to have more text on the screen.

–daemon mode

I haven’t really played with this yet, but it looks cool.

This feature allows you to run emacs in “daemon mode”, meaning that it evaluates all startup files but does not open a frame. It then opens a socket and listens for clients.

To open an Emacs frame, use emacsclient. It seems to require a little extra tweaking in my setup, because when opening a client frame the toolbar is not disabled, the Meta key is not properly set up etc. But I’m sure that would be easy to fix.

The great news here is that it allows you to have one master instance of Emacs running and open files in it easily. For example, set your $EDITOR variable to “emacsclient -t”. The advantage of this method is that you can use the same instance of Emacs throughout your system. Right now I’m used to invoking something like “emacs -q -nw /etc/foo” if I need to quickly edit a file in the shell and don’t want to wait for my sea of customizations to be loaded.

Cons

weblogger.el is messed up again

I know I have no right to say this, but I want to be honest. This really, really pisses me off. I cannot believe how fragile the weblogger.el/xml-rpc.el combination is.

Until I updated to the latest versions, it didn’t work at all. I already forgot what was wrong, because I’ve gotten so used to just trying out all sorts of tweaks until it works (or I give up).

So after installing the latest versions, I am able to download the list of posts (with weblogger-fetch-entries). But alas, all of a sudden there is some issue with longlines-mode, so when writing a new entry, the text just becomes invisible. Figuring that out within a few minutes gave me a sense of Deja Vu. I must have been bitten by this issues at some time in the past, or I would never have figured out so quickly what was wrong. (UPDATE: It turned out that only the showing of hard newlines had to be turned off, and that this is not related to weblogger.el. But somewhere along the way, this entry was messed up so real newlines were inserted.)

Having to disable longlines-mode is painful to be sure, but the annoyance passes quickly as I discover another two issues.

After saving an entry (weblogger-send-entry) the *weblogger-entry* buffer is buried. Why?? (UPDATE: It turns out that this was also the case in the previous versions. I had just forgotten that I had made a dirty hack in weblogger.el to fix it).

Also, the interaction with wordpress.com is just painfully slow. It takes me about 10 secs to save an entry. I have no idea why that is. I haven’t started using https or anyting like that. A quick look at tcpdump reveals an 8 second pause that is new since my Emacs 22 setup.

twit.el broken

This is another regression I just discovered while writing this entry. When trying to run twit-show-recent-tweets, I get the following error.

error in process sentinel: Symbol's value as variable is void: url-http-attempt-keepalives

Again, no idea what is wrong. I updated to the latest twit.el (which worked fine in Carbon Emacs). When trying in an Emacs with no customizations, it just hangs.

Fullscreen mode broken

This is a well-known issue, and a pretty serious one IMO. I get some extra text from reducing the font size, but it is wasted on menubar and window decorations as long as I can’t properly fullscreen the frame.

Verdict

So, is it time for me to upgrade to Emacs 23? Absolutely not. It has taken me way too long just to write this blog entry simply because stuff keeps falling apart.

I’m afraid I’ll have to spend a significant amount of time tweaking all my customizations to work with Emacs 23. And I’m afraid it is going to be a while before I have nothing better to do. Until then, I’m stuck with Emacs 22.

But hey, that’s not so bad, is it?

Follow

Get every new post delivered to your Inbox.