Thursday, 18 February 2010

Typing # in emacs on OS X with a UK keyboard

What a pain!

It's bad enough that the Apple UK keyboard doesn't have an obvious way of typing a # - alt-3 since you ask, and it's not printed on the key either like the Euro symbol, €, is! This isn't such a terrible thing in most editors since alt-3 isn't too hard to cope with. But in emacs the alt key is mapped to Meta, so alt-3, by default does something else - not sure what.

Thankfully, this is emacs so it's easy enough to put right, simply add the following to your .emacs file:
(global-set-key (kbd "M-3") "#")
Done and done.

Thursday, 11 February 2010

cdecl on the web

cdecl is a really useful tool for working out what a C type declaration is in English. For example:
const char** x
is translated into
declare x as pointer to pointer to const char
That is a very simple example, but it really comes into its own when given something nasty, like this:
char (*(*x())[5])()
which is:
declare x as function returning pointer to array 5 of pointer to function returning char
And you can go the other way too:
declare x as pointer to const pointer to int
becomes:
int * const *x
Which is all rather nice.

What is really useful is that it is available online at http://www.cdecl.org.

Tuesday, 9 February 2010

Using macports emacs-app from the command line

Having installed emacs-app from MacPorts I wanted to be able to use it like I do emacs under Linux, i.e:
emacs file.txt &

But you can't run 'proper' OS X applications like that. There is, however, a command called open which can help. Here is how you would rewrite the Linux example above using open:
open -a emacs file.txt

The -a switch tells open which application you want to use to open file.txt and it automatically looks in the Applications folder for it. Note that you don't need the ampersand on the end of the line as OS X appears to fork the application for you.

From there it is pretty easy to set up an alias to do all that for you. Simply add the following line to your .bashrc:
alias emacs='open -a emacs'

Nice.

Monday, 8 February 2010

Emacs Splash Screen...

For a couple of years now Emacs has been starting up with a splash screen showing by default. Even if you start it from the command line and give it a filename to load.

This has never bothered me under Linux because just clicking in the window with the mouse makes the splash screen disappear and brings the file you actually asked for to the front. I've recently installed emacs-app from MacPorts on my Mac though and upon startup it actually opens the splash screen in a different window (or "frame" in emacs parlance), which I really don't like. It's much too obtrusive now.

Thankfully, emacs being emacs, you don't have to stand for this outrage! You can turn off the splash screen completely by dropping the following into your .emacs file:
;; Remove splash screen
(setq inhibit-splash-screen t)

Sorted.