(X)EmacsĀ Customization

I’m getting into modifying Emacs to do what I want, and (first) learning all that it’s capable of. It’s amazing when I actually poke around in what’s possible.

Here’s a great tutorial. This guy has a bunch of valuable tips (and I like that his favorite keyboard is the same as mine, the Microsoft Natural Keyboard 4000).

Here is his description of Emacs support for bookmarks, which I just happened to read about today.

And this is how I found it, frustrated that ctrl-j doesn’t work in Ruby mode, because that mode “overrides” my “globally” set key.

Finally a “new” (old) language to learn, ironically, one that I’ve been using for 15 years.


IDEs are all the rage in software development, but I’ve remained a devote Emacs user, or XEmacs to be more precise. Why? Primarily because XEmacs is primarily for editing files, and does the job extremely well. It can be customized to a great extent, where XEmacs is truly a platform in itself, allowing the user to tailor it to their needs. But even out of the box, XEmacs is phenomenally powerful, making it trivial to record keystrokes and record those as macros (hence the “mac” part of the name).

Some nifty XEmacs tricks:

  • Transposing two characters: control-t
  • Transposing two words: alt-t. This is all the more powerful in that words can be “dragged” forward by repeated alt-t sequences. And XEmacs mysteriously knows how to skip punctuation, making it very useful for when method arguments need to be reordered.
  • Transposing lines: switch the current line with the previous: control-x-control-t.
  • Reindenting code: highlight the region, then escape-ctrl-backslash (C-M-\ in Emacs-speak).
  • Inserting the basename of the current file. This is useful in Java code, where the file basename is the same as the public class in that file. This bit of Emacs Lisp does it:
  • (defun jep:file-split (file)
      "Split file name x.y by dot, returning the list (x y)."
      (let* (fn
    	 ;; extended so that foo.cpp => foo.cpp
    	 (re  "^\\(.*\\)[.]\\([^<]*\\)")
        (if (not (and (string-match re file)
                      (match-end 1) (match-end 2) ))
          (setq fn  (substring file (match-beginning 1) (match-end 1)))
          (setq ext (substring file (match-beginning 2) (match-end 2)))
        ; return a list containing the file name and the extension
        (if (and fn ext)
            (list fn ext)
    (defun jep:file-basename ()
      "Returns the file name, minus the directory and suffix."
      (let* ((bn (buffer-name))
             (namelist (jep:file-split bn))
        (if (or (null namelist) (= 1 (length namelist)))
          ;; first in the name list is the file name; second is the extension
          (setq fn  (nth 0 namelist))
    (defun jep:file-insert-basename ()
      "Inserts the basename at the current point."
      (let* ((fn (jep:file-basename))
        ;; Not doing a save-excursion, because we want to go to the end of what we
        ;; inserted.
        (insert fn)

That’s just a start; I’ll add more later.