Posts Tagged ‘emacs’

Clojure-refactoring gets a little love, a new release and a new maintainer.

Monday, October 24th, 2011

clojure-refactoring, the Emacs/SLIME based toolkit for doing refactoring wasn’t getting enough love and attention, so I fixed a few things. Tom Crayford unfortunately doesn’t have the time to work on it any further so I’m taking over as the maintainer. Inspect the code at the new “official” repository.

For now, I’m focused on fixing parsing issues first, then installing ease (I’m thinking about packaging everything Emacs-related on marmalade but that depends on what’s the easiest way to get stuff integrated for the user on the Emacs and Clojure sides). I’ve already removed the dependencies on out-dated libraries. Basically, everything I need to make the current functionality reliable enough for production use. Next up is support for clojure 1.3, probably, if that needs any work (I’m running 1.2 in production everywhere for now).

For the further future, I’d like this code to be useful for other editors/APIs/tools, so the SLIME/swank/Emacs specific stuff probably has to be separated out at some point. Some more refactorings will also be useful.

For now, version 0.6.1 is on clojars. Get it while it’s hot.

In search of a better keyboard; The IBM Model M

Wednesday, September 1st, 2010

IBM Model M, full size 101-key version

By far the oldest board in this series. Production of these things started in 1985 and slightly modified versions are still being build by Unicomp (the Customizers are the closest to the standard IBM Model M, but always make sure you pick the Buckling Spring versions, see below).

Build quality

I’ve been using a Model M keyboard for the last couple of years, and in many respects it’s the best keyboard I’ve ever used: it’s very sturdy, will last for decades (mine is 15 years old and still working fine) and the key switches are phenomenal.


This was one of the first keyboards with what’s now more or less the standard PC layout and it’s probably the reason that that layout became so popular. Probably not remarkable – even boring – these days, but on the whole it’s very well thought out and effective. Especially if you map the CAPS Lock key to Control (Unicomp sells models with CAPS and Left-CTRL swapped, but you can swap the keys on any OS and I don’t really see the point of looking at a keyboard when you’re typing on it).

Buckling Spring switch technology

The switches work via a so called “buckling spring” mechanism, which means every key is set on top of a fairly long spring that “collapses” sideways when you’ve pressed the key about half way down and activates the mechanical “hammer” attached to the bottom of the spring. You can easily feel when that is about to happen, and once it does you can feel the key “give” and it makes a very satisfying CLICK sound.

On this keyboard you simply can’t get fooled about whether you’ve pressed a key or not: the auditory and tactile feedback is very immediate.


As you can probably tell, I really like this keyboard, but there a few issues with it that are annoying:


This is a large keyboard, even for a full size standard layout: the MS Natural 4000 has a big wrist rest and a “split” main cluster and it’s still only marginally larger than the Model M.

Size is especially important if you’re a right handed mouse user. With the num-pad to the right, your mouse is quite a long way away from the main alphanumeric cluster where your hands are when you’re typing, which means that you’re not always using an optimal position for the mouse, the keyboard or both. You can tell these things were invented before PCs had mice.

There used to be Model M variants that didn’t have a numeric key pad, but production of those stopped somewhere in the early ’90s. Expect them to be expensive – if you can find one. Ebay US seems to have a few, but once you include shipping, you might want to consider something else if you live in Europe. Clickykeyboards (where that link is to) sells them for fairly reasonable prices, but they don’t seem to have them all that often – and you still have to pay shipping from the US.

Finger fatigue

The switches on these keyboards are very good, but also quite heavy: they require noticeably more force than most conventional keyboards. You get used to it, especially since the force is consistent over all keys, but for me, it’s just barely on the edge of “too heavy”.


The click sound, while satisfying, can get on your nerves late at night. Not that much of an issue for me, but sometimes you just wish it made a bit less noise. If you have coworkers or family in the same room, I expect they won’t like this keyboard much.

Pro: price

On the other hand, second hand full-size Model Ms are cheap and not that hard to get. New ones from Unicomp are also very competitively priced compared to other well-built keyboards with mechanical switches (the basic model is $69), even if you have to ship them across the Atlantic.

Previous episode: In search of a better keyboard – Early history.

Next episode: what now? (not finished, stay tuned).

In search of a better keyboard; Early history

Sunday, August 29th, 2010

When you’re typing as much as I do, sooner or later you realize that having a good keyboard is important. Years ago I was having issues with wrist-pain and switching keyboards was – for me – a very effective way of almost eliminating the problem.

But this is not about health issues directly. What I found is that the best way to stay healthy while working is to keep irritation to a minumum, and keyboards can do a lot of things that are just plainly annoying:

  • Keys in wierd and/or hard to reach places
  • Keys in half-size
  • Keys that only work most of the time
  • Keys that are much harder to press than the others

Looking at that list, there are two main things that can go wrong: keyboard layout and the key switch technology. I’m going to address both throughout this short series.

I’m going to present the main keyboards I’ve used in chronological order (that is; order that I used them), but I’m ignoring the very early stuff. Some were not that good (Commodore 64), some were horrible (Atari 400, I’m not even sure if I’d call that thing you’ve got a keyboard) and some were pretty nice (like the Amiga 500). My focus is on keyboards that are still available and useful to today’s PC or Mac user.

As an example of frustrating design, I present:

The MS Natural Elite

MS Natural Elite keyboard

All in all it’s not a bad board; they’re cheap and they’re fairly pleasant to type on with light-weight keys, but all the navigation keys are in half-size AND in non-standard places (and yet close enough to the standard locations to get really confusing). Get used to pressing INSERT instead of END and fumbling for the cursor keys. Bad, ugly and unnessessary. Also, in my experience, they break after 3 years or so.

The MS Natural 4000

The successor to the Elite that solved most of the issues with the layout, but the modifier keys and especially the space bar were so heavy I found myself slamming my thumbs on them which can’t be good.

The extras, like the horrible multimedia “keys” and the vertical “joystick” or whatever that thing is, I won’t further address, since I never used them.


Also, it broke down after only a year. Not good at all for a keyboard that cost about 60 euros at the time.

By now I was getting frustrated by key switches, and I wanted something that would actually let me type in a consistent way and KNOW that I was really pressing a key when I thought I was, without me having to slam every one of them into the ground.

Which brings me to the next post: In search of a better keyboard; The IBM Model M.

Choosing your clojure startup script from Emacs/SLIME

Thursday, December 3rd, 2009

The standard instructions for swank-clojure (the clojure backend to SLIME) imply you always use the same binary and/or classpath for starting your clojure code. The problem with that is that for different projects you generally want to specify at least additional classpaths and possibly even a completely different clojure version.

At the same time, most projects already contain some kind of startup/REPL script, so why not use that? swank-clojure only really needs some code that starts a repl and has the swank-clojure code in its classpath.

Below is my emacs code to do just that. Just put it somewhere in your emacs init scripts, type M-x clojure and select your startup script and away you go. The following is all my clojure-specific code, but the really “interesting” bit is the (defun clojure ...) bit.

;; this is needed because swank-clojure complains if you don't have any
;; value for this variable. When you use the clojure command it'll override
;; this value
(setq swank-clojure-binary "clj")

(require 'clojure-mode)
(require 'swank-clojure-autoload)
(require 'swank-clojure)
(require 'slime)

(add-hook 'clojure-mode-hook 'slime-mode)

(add-hook 'clojure-mode-hook 'start-paredit)

 '(slime-fancy ;; turns on fancy inspector, autodoc and other useful stuff

(defun clojure (binary)
  (interactive "fbinary: ")
  (setq swank-clojure-binary (or binary "clj"))
  (setq slime-lisp-implementations
        `((clojure (,swank-clojure-binary) :init swank-clojure-init))) 

My complete emacs init stuff is at

Oh, before I forget: the code above does assume that you’re only using SLIME with clojure and not also with other lisps. If you do need that functionality, you can probably figure out how to make it work.

Javascript regex en string literal highlighting in Emacs

Wednesday, October 31st, 2007

De beste javascript mode voor Emacs is deze van Karl Landström. Hij heeft alleen moeite met het correct detecteren van strings en regexes:


Niet leuk als je de source van jQuery opent. (Waarschuwing, dit crasht emacs!)

Ook niet leuk is dat Emacs’ ingebouwde syntax-table niet overweg kan
met de complete overloading van / in Javascript (als deel-operator, regex quote, en 2 soorten commentaar marker). Boeh voor Emacs!

De oplossing is dan om alle auto-quoting uit te zetten en het zelf te doen. Kan je net zulke ingewikkelde syntax mee highlighten als je wilt. Hoera voor Emacs!

Relevante passages:

;; --- Syntax Table And Parsing ---

(defvar javascript-mode-syntax-table
  (let ((table (make-syntax-table)))
    (c-populate-syntax-table table)

    ;; switch off build-in quoted string detection
    ;; since that just makes it really hard to detect
    ;; regular expressions and comments
    ;; this also has the benefit that multiline strings
    ;; are now not recognized as strings (since javascript does
    ;; not allow them)
    (modify-syntax-entry ?' "." table)
    (modify-syntax-entry ?\" "." table)

    ;; The syntax class of underscore should really be `symbol' ("_")
    ;; but that makes matching of tokens much more complex as e.g.
    ;; "\\" matches part of e.g. "_xyz" and "xyz_abc". Defines
    ;; it as word constituent for now.
    (modify-syntax-entry ?_ "w" table)

  "Syntax table used in JavaScript mode.")
(defconst js-quoted-string-re "\\(\".*?[^\\]\"\\|'.*?[^\\]'\\)")
(defconst js-quoted-string-or-regex-re "\\(/.*?[^\\]/\\w*\\|\".*?[^\\]\"\\|'.*?[^\\]'\\)")

(defconst js-font-lock-keywords-1
   (list js-function-heading-1-re 1 font-lock-function-name-face)
   (list js-function-heading-2-re 1 font-lock-function-name-face)

   ;; detect literal strings following a + operator
   (list (concat "+[ \t]*" js-quoted-string-re)  1 font-lock-string-face)

   ;; detect literal strings used in "literal object" keys
   (list (concat "[,{][ \t]*" js-quoted-string-re "[ \t]*:" ) 1 font-lock-string-face)

   ;; detects strings and regexes when assigned, passed, returned
   ;; used as an object key string (i.e. bla["some string"]), when used
   ;; as a literal object value (i.e. key: "string"), used as an array
   ;; element, or when they appear as the first expression on a line
   ;; and a few other hairy cases
   (list (concat "[=(:,;[][ \t]*" js-quoted-string-or-regex-re)  1 font-lock-string-face)
   (list (concat "^[ \t]*"      js-quoted-string-or-regex-re) 1 font-lock-string-face)
   (list (concat "return[ \t]*" js-quoted-string-or-regex-re) 1 font-lock-string-face)

   ;; detect "autoquoted" object properties... clases with "switch { ...  default: }"
   ;; may not be worth the trouble
   (list "\\(^[ \t]*\\|[,{][ \t]*\\)\\(\\w+\\):" 2 font-lock-string-face))

  "Level one font lock.")

En dan:

Patch is onderweg naar Karl. In de tussentijd kun je hier mijn versie downloaden.