[ Content | Sidebar ]

Archives for programming

Emacs commit message mode

March 12th, 2011

Here’s a really trivial Emacs major mode for editing Git and Mercurial commit messages: commit-msg-mode.el. It works in basically the same way as the Vim mode, highlighting the summary line, help text, etc.

To use it, put it on your load-path and add the following to your .emacs:

(autoload 'commit-msg-mode "commit-msg-mode"
  "Major mode for editing commit messages." t)
(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . commit-msg-mode))
(add-to-list 'auto-mode-alist '("hg-editor-.*$" . commit-msg-mode))

If you’re anything like me you’ll appreciate having your commit message spell-checked which you can do with:

(add-hook 'commit-msg-mode-hook
          (lambda ()
            (flyspell-mode t)))

Cuckoo Hashes in Lisp

February 20th, 2011

I’ve been learning about cuckoo hashing this evening and to help with that I’ve written an implementation in Common Lisp that others might find useful: cuckoo.lisp. It provides a package cuckoo which exports make-cuckoo-hash, cuckoo-insert, cuckoo-lookup, and cuckoo-delete which perform the obvious hash-table operations. The key feature of cuckoo hashes, if you haven’t come across them before, is that they have constant worst-case lookup time. They are also quite amenable to implementation in hardware.

The keys are implicitly fixnums since it’s a prototype for a C/VHDL implementation, but it shouldn’t be too hard to extend to a generic key type. The insert function automatically rehashes in-place if the table becomes full. The hash function is the xor of three randomly selected universal hash functions, as recommended by the Pagh and Rodler paper.

Chicken SLIME now an Egg

January 22nd, 2011

The Chicken Scheme SWANK implementation I’ve been working on is now available from the main Egg repository. So now you don’t need to faff about with Git and can install it like any other extension using:

$ chicken-install slime

Follow the instructions on the Chicken Wiki to get it set up.

I’ll be mirroring changes in the Chicken SVN to the existing GitHub repository so you can carry on using that if you like.

Since I last posted about this Christian Kellermann has submitted some great patches which improve the SLDB support allowing you to examine lexical scopes in the call chain. For example:

Hit enter or click on a frame in the backtrace that says “more …” and you will see a list of the lexical variables in that scope.

List outgoing changesets in Git

January 8th, 2011

I normally use Git for my personal projects but at work I use Mercurial. While I prefer Git overall, Mercurial has some nice commands that are missing from Git. One particularly useful one is hg out which prints the changesets in your local repository that are missing from the remote. Here is a simple script which does approximately the same thing for Git:

#!/bin/sh
for i in $(git push -n $* 2>&1 \
    | awk '$1 ~ /[a-f0-9]+\.\.[a-f0-9]+/ { print $1; }')
do
    git log --oneline $i
done

Store it as git-out somewhere in your PATH and you can use git out just like a regular Git command.

Chicken SLIME describe and apropos

January 2nd, 2011

The latest version of swank-chicken.scm now supports describe (C-c C-d d) and apropos (C-c C-d a) commands using the chicken-doc egg. Here’s an example:

This apropos window works too: hit C-c C-d a, type a regexp, and a popup window will list the matching symbols; hit enter on the one you’re interested in and you will see the documentation.

Note for all this to work you will need to have the Chicken documentation installed – follow the instructions on the wiki.

Update to Chicken SWANK server

January 1st, 2011

I’ve made some improvements to the Chicken Scheme SWANK server I posted previously. Thank you to all the people who emailed me about it! I’ve fixed several minor bugs and implemented some new features:

The SLIME autodoc minor mode now works giving more detailed parameter hints. For example:

Autodoc is not enabled by default so you’ll need to add

(slime-setup '(slime-autodoc))

to your .emacs. It’s not perfect as it gets confused by symbols exported from Chicken modules (e.g. it does not work when the function has a module# prefix). Any suggestions on how to work around this would be appreciated :).

Several more SLIME commands are now implemented – e.g. C-x C-e and C-x C-r work as expected. Let me know if there’s a command you frequently use that doesn’t work. I’d love to have M-. supported but I can’t see a way to extract the required location information from Chicken.

Simple tab-completion of symbols now works too:

The problems with interrupts from Emacs I mentioned last time have now been fixed and you can easily break out of infinite loops using C-c C-c like this:

Follow the instructions in the last post to get started. If you’ve tried it already a git pull should be all you need. Note that the dependencies have changed slightly:

$ chicken-install fmt apropos symbol-utils

will install the required libraries.

Let me know if you have any questions or comments!

Scheme on TV

December 24th, 2010

Here’s a collection of interesting Scheme videos you can watch instead of the usual Christmas TV:

http://programming-musings.org/2009/12/23/scheme-lectures-mostly

The Guy Steele Designing by Accident talk on the history of Scheme is really good (download the slides first). Watch the Gerald Sussman one too (it’s short!). Also, who doesn’t want to know the value of ((call/cc call/cc) (call/cc call/cc))?? Holiday fun for all the family.

This talk on a Scheme documentation language (and DSLs in general) is good also. From last year’s ICFP:

http://www.vimeo.com/6630691

Using SLIME with Chicken Scheme

December 12th, 2010

Common Lisp programmers are blessed with the awesome SLIME development environment for Emacs; but sadly Schemers have nothing comparable. There are a few SLIME backends for various Schemes around, in varying states of completeness, but as far as I can tell none for my Scheme implementation of choice: Chicken Scheme.

Therefore I present swank-chicken: a SWANK server written in Chicken Scheme. (SWANK is the protocol SLIME uses to talk to the inferior Lisp process.) I’ve been hacking it together over the past week or two and it’s now reached the point where it is more or less usable. Click on the screenshot below for an example:

Supported features so far:

  • REPL support with input/output (i.e. read and write work as expected)
  • Complile region and load file commands (e.g. C-c C-l, C-c C-c)
  • Basic SLDB support with back trace
  • Parameter argument hints in the minibuffer

Huge swathes of SLIME features are obviously missing at the moment, but the most useful ones are there. In particular, I think it’s at least as functional as the normal inferior-scheme mode. The most significant omission at the moment is support for interrupting Scheme evaluation from Emacs – C-c C-c at the REPL will currently kill the backend process completely. Na├»vely this should be implemented in the same way as the debugger-abort command: by calling the top-level continuation. However, perhaps unsurprisingly, calling a continuation from a Scheme SIGINT handler turns out to be a bad idea. So if you have a runaway process you must kill and restart it with C-c C-c M-x slime-restart-inferior-lisp.

UPDATE: some of these issues have been fixed.

To get started clone the git repository using:

git clone git://github.com/nickg/swank-chicken.git

Alternatively just download swank-chicken.scm and chicken-slime.el.

First we need to install a few Chicken extensions:

chicken-install format symbol-utils

Obviously you also need to install SLIME: I’ve been using the latest code from CVS but older versions should work too.

Next, place chicken-slime.el somewhere in your Emacs load-path and add the following to your .emacs:

(autoload 'chicken-slime "chicken-slime" "SWANK backend for Chicken" t)
(setq swank-chicken-path "/path/to/swank-chicken.scm")
 
(add-hook 'scheme-mode-hook
          (lambda ()
            (slime-mode t)))

Now you should be able to use SLIME commands in a Scheme buffer. To start a Scheme REPL do M-x chicken-slime.

That’s it! Let me know if you have any problems/suggestions. I intend to do some more work on this and package it up as an Egg. The code is available under the MIT license.

Qemu resizing blurriness

September 25th, 2010

Are you annoyed when Qemu randomly resizes its window causing all the text to be scaled and blurred? Maybe it’s just my window manager, but here is a trivial patch to disable that annoying feature:

--- sdl.c.old   2010-09-25 13:30:48.000000000 +0100
+++ sdl.c       2010-09-25 13:30:50.000000000 +0100
@@ -102,7 +102,7 @@
 
     //    printf("resizing to %d %d\n", w, h);
 
-    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_RESIZABLE;
+    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
     if (gui_fullscreen)
         flags |= SDL_FULLSCREEN;
     if (gui_noframe)

Cowshell

July 2nd, 2010

Blodgett just reminded me of another useful tool we made a few years ago: cowshell! Cowshell provides a more user-friendly interface to the Linux shell by wrapping the output in multi-coloured cows. Here is an example session:

Cowshell is a Perl script that you can acquire here. You will need cowsay and maybe some Perl modules for it to work.