Emacs backup files

Emacs loves to create billions of little ugly-twin backup files all over your hard disk that look like ‘myfile~’ and ‘myfile.txt~’. Here are some better alternatives:

- add the following to your .emacs (this is the best solution)
(setq make-backup-files t)
(setq version-control t)
(setq backup-directory-alist
     (quote ((“.*” . “~/backup/emacs_autosave/”))))
; otherwise it keeps asking
(setq kept-new-versions 30)
(setq delete-old-versions t)

[i've forgotten which of these does what, but they're all in my .emacs file...]

make sure to create ~/backup/emacs_autosave first. this will create multiple snapshots of every file you edit and store them in that directory. this avoids having all the blah~ files in your current directory, and is useful if you want to revert to the way you had things 5 minutes ago.

- a quick alias to remove them (courtesy of Randy O’Reilly)
alias cleanup ‘/bin/rm *~ .*~ #* .#*’

- finally, put Dropbox into ‘pack rat’ mode, so that it stores every single version of your Dropbox files for eternity.

Emacs Freex gets a new home

Emacs Freex mode is a minor mode for organizing and editing a massively-hyperlinked database of your notes and ideas. It’s a personal wiki on steroids. Per Sederberg & I released the Emacs Freex code under the GPL two years ago.

I’ve just moved it to a new home on Google Code, and also recorded my first ever screencast, to demonstrate how it works.

There are probably still some teething problems with the installation instructions, and I think perhaps I could be clearer in the screencast. Do let me know what I can do to make it easier for new users.

WriteRoom? DarkRoom? MushRoom!

Mark Pilgrim said it best:

I’ve been peripherally following the latest fad of full-screen “writing-focused” text editors. Here’s what I’ve learned so far: in the beginning, there was WriteRoom (Mac OS X, $24.95). WriteRoom is “just about you and your text.” WriteRoom begat DarkRoom (Windows + .NET, $0), which is also “just about you and your text” but requires a 22 MB runtime environment. DarkRoom begat JDarkRoom (Java, $0), which is just about you, your text, and somebody else’s multi-megabyte runtime environment.

Here’s the basic problem: you’re writing a text editor. Stop doing that. It’s 2007. Saying to yourself “I’m gonna build my own text editor” is as silly as saying “I’m gonna build my own build system” or “I’m gonna build my own amusement park.”

Reading the change logs of these programs is like traveling back in time. Way back. Latest changes in JDarkRoom 8: Undo / Redo. Seriously. Version 8, and they now support undo. No offense, but what the fuck?

Anyway, so I had a nose around, and it turns out that Emacs has both undo/redo and very capable full screen capabilities. The EmacsWiki includes the following function, which I’ve renamed from ‘write-room’ and tweaked a little for the mac:

;; http://www.emacswiki.org/cgi-bin/wiki/WriteRoom
(defun mush-room ()
“Make a frame without any bling”
(interactive)
(let* ((frame (make-frame ‘(;; (minibuffer . nil)
(vertical-scroll-bars . nil)
(left-fringe . 235); big fringe to center
(right-fringe . 160)
(background-mode . dark)
(background-color . “black”)
(foreground-color . “green”)
(cursor-color . “green”)
(border-width . 0)
(border-color . “black”); should be unnecessary
(internal-border-width . 20) ; whitespace
(cursor-type . box)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(mode-line-format . nil); dream on… has no effect
(fullscreen . t); does not work on all systems
(unsplittable . t)))))
(select-frame frame)
(setq mode-line-format nil); is buffer local unfortunately
(set-face-background ‘fringe “black”)
(set-frame-font gjd-gin-font)
(mac-toggle-max-window)))

I’ve also added the following auxiliary bits and bobs to make this work well:

(setf gjd-gin-font “-apple-courier ce-medium-r-normal–18-180-72-72-m-180-mac-centraleurroman”)

(defun unfullscreen ()
(interactive)
;; restores mode line
(setq mode-line-format (default-value ‘mode-line-format))
(set-face-background ‘fringe “grey95″)
)

(defun delete-frame-and-unfullscreen ()
(interactive)
(delete-frame)
(unfullscreen))

(global-set-key “\M-w” ‘delete-frame-and-unfullscreen)

Evangelizing Emacs (in terms of economics)

As may have become apparent, I harbour somewhat fanatically evangelical feelings about Emacs, though i’m very aware of its failings and idiosyncracies too.

Let me try my pitch for why you should learn Emacs in terms of economics. As a computer user, you want the biggest bang for your buck, the most reward for effort spent mastering a tool – one way to ensure this is for that tool to be useful in a variety of situations. Keyboard shortcuts, customizations, regular expressions and the like all provide enormous economies of scale. That is, they provide value, but they have a high marginal cost initially. However, the more you use them, that cost gets amortized, and so the more you profit from them.

Anyway, Emacs has a huge huge barrier to entry. Getting the hang of it is a pain, mainly because it has a huge amount of jargon and all of its keyboard shortcuts seem to involve 3 keys. The good news is that with a little effort, you can change them all to something a little more reasonable. Furthermore, once you’ve got the hang of a few, then you get to reuse them for almost everything you do.

Perhaps I should just quote Neal Stephenson, who said it best a long time ago:

“I use Emacs, which might be thought of as a thermonuclear word processor. It was created by Richard Stallman; enough said. It is written in Lisp, which is the only computer language that is beautiful. It is colossal, and yet it only edits straight ASCII text files, which is to say, no fonts, no boldface, no underlining. In other words, the engineer-hours that, in the case of Microsoft Word, were devoted to features like mail merge, and the ability to embed feature-length motion pictures in corporate memoranda, were, in the case of Emacs, focused with maniacal intensity on the deceptively simple-seeming problem of editing text. If you are a professional writer–i.e., if someone else is getting paid to worry about how your words are formatted and printed–Emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish. For page layout and printing you can use TeX: a vast corpus of typesetting lore written in C and also available on the Net for free.”

My take on emacsclient

Emacs is pretty lightweight relative to most modern editors, though by the time it loads all the modes and gets through all the uncompiled junk in my .emacs configuration, you wouldn’t know it.

Emacsclient is the solution – when you open a file with emacsclient, it doesn’t start up a whole new emacs – it just opens it in the running emacs, which is more or less instantaneous.

There are lots of webpages on this, so I won’t go into detail. Unfortunately, although you’d hope that calling ‘emacsclient’ would work just like ‘emacs’, this isn’t true:

  • I wanted to tell emacsclient to display an emacs frame, without feeding it any filename arguments to display. No dice.
  • If I don’t have a running emacs server (necessary for emacsclient to connect to), it just gives you an error message, rather than taking matters into its own hands and opening up a new emacs instance.
  • If I have emacs running on one computer, and I ssh into that computer, then I want to be able to type emacsclient and have a window show up. No dice. You have to explicitly feed it a display.

These issues were annoying enough that I nearly stopped using emacsclient. Various people have offered shell script hacks that handle some of these issues and more, but none of them solved the ones that bothered me. Plus, I like Python and I hate shell scripts. So I offer up a teeny python script, emf-on-display. If you alias ‘emf-on-display’ to something handy like ‘e’, then it makes emacsclient behave in a way that I find much more consistent with emacs.

P.S. I have not dealt with the possibility that you’re running this in the terminal, and you don’t have an X11 display at all.

P.P.S. I suspect that it requires emacs 22 (or gnuclient) to work, since it relies on being able to pass ‘make-frame-on-display’ as elisp code to be evaluated.