Sunday 24 May 2009

Goodbye, Old Man

I buried Garfield's ashes today, under his favourite tree (claw marks included) at my mother's house. He went in the best way possible, but I've shed more than a few tears since his death.

He did well.

Rest in peace, old man.

Clojure on FreeBSD 7

Getting a native Java on FreeBSD 7 is not straightforward. It involves going through the instructions at freebsd.org/java and manually fetching packages that have generally since been superseded by point-versions (which you can't use or the ports system won't install them). Once they're all in /usr/ports/distfiles, a make install in /usr/ports/java/jdk16 will, several hours of hard compilation later, enable you to checkout a fresh copy of Clojure.

Finally, success:

Friday 22 May 2009

Switching between Header and Implementation Files with Emacs

I often find myself working with C or C++ code that follows the pattern of parallel source/include directories, probably with lots of layers in between (e.g. project/include/some-controller/some-aspect/something.h and project/src/some-controller/some-aspect/something.cpp). Quickly switching between both saves on keystrokes and sanity, so I wrote this little chunk of elisp, bound to ctrl-alt-g (for no particular reason other than the combination is easy to mash):


(defun djw-c-toggle-impl-header-view (create-if-nonexistent)
(interactive "P")
(let* ((mode (if (string-equal (file-name-extension (buffer-file-name))
"h")
:switch-to-implementation :switch-to-header))
(toggle-tags (list (cons "/Include/" "/Src/")
(cons "/include/" "/src/")))
(from-fn (if (eq mode :switch-to-implementation)
#'car #'cdr))
(to-fn (if (eq mode :switch-to-implementation)
#'cdr #'car))
(source-file-name (buffer-file-name))
(case-fold-search nil)) ;; I want case-sensitive matching throughout this block.
(dolist (pair toggle-tags)
(setf source-file-name (replace-regexp-in-string (funcall from-fn pair)
(funcall to-fn pair)
source-file-name)))
(setf source-file-name
(replace-regexp-in-string
(if (eq mode :switch-to-implementation)
"h\$" "cpp\$")
(if (eq mode :switch-to-implementation)
"cpp" "h")
source-file-name))
(message (format "Looking for %s" source-file-name))
(if (or (file-exists-p source-file-name)
create-if-nonexistent)
(find-file source-file-name)
(message (format "Can't find '%s'" source-file-name)))))


If the counterpart file is missing, it won't be created unless the function is invoked with a prefix argument (C-u C-M-g).

There's probably some extension to CC mode or the like that already does something like this, but in the absence of reading the manual, this works well for me.

Wednesday 13 May 2009

Sad Day

My cat died today.

His name was Garfield, and he was 19. I got him as a kitten when I was 13. I came downstairs this morning to find him on his favourite cushion on the couch; it was the only time that he didn't raise his head to meow/croak back at me.

He had a good life. His last day was spent sunning himself in the back garden; his last meal was his favourite roast chicken; and last night, when I was working at my computer, he came up for a cuddle and a purr.

As the vet said to me a few months ago, "You don't last that long without good bits". Garfield was made with the best.

garfield.jpg


Goodbye, old man.