Monthly Archives: February 2009

Emacs creeps up on me

I have used vim for years—since I started coding PHP. (Sometimes I preferred the Zend Studio editor because nothing does a better job of cross-linking in PHP projects. Unfortunately, almost anything could do a better job of memory management. As WordPress grew, the Zend editor became too slow to be usable. Too bad. I miss it.) Now that I am writing some Erlang, I am learning to use emacs.

The credit for this switch belongs entirely to the lovely erlang-mode. (I tried TextMate’s erlang mode but I couldn’t get past TextMate’s strange navigation keys, etc. I wish there were standard navigation keys in OS X. Too bad. I’ve heard TextMate is great.) The emacs erlang-mode helps me write beautiful code. Now that I’m also learning to use emacs in php-mode I rarely become disoriented and type “:w” to save a file. (I don’t miss vim.)

Not everything about emacs is perfect. It doesn’t understand my Mac’s right-delete key. Left-delete (backspace) won’t delete a tab; it converts it the tab spaces and deletes one of them so that I have to hit backspace many times to delete a single tab. And in php-mode, the indentation rules are far more complex than the WordPress coding standards; I just want tabs in php-mode.

Even though I have these problems, you have to hand it to emacs for being customizable. It took a couple of hours to find all the solutions, but I solved all of the above problems above by adding these lines to my .emacs file:

;; Map OS X Terminal SSH delete key                                                                                                                                  
(global-set-key (read-kbd-macro "ESC [ 3 ~") 'delete-char)

;; Backspace should delete, not convert tabs to spaces                                                                                                               
(setq c-backspace-function 'backward-delete-char)

;; In PHP, never indent; always insert TAB.
(require 'php-mode)
(defun my-php-mode-hook ()
  (local-set-key (kbd "TAB") 'self-insert-command))
(add-hook 'php-mode-hook 'my-php-mode-hook)

This works for me even though I understand less than half of it. There is so much to learn.