Bill Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

April 2005
Sun Mon Tue Wed Thu Fri Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Mar  May

Customizing Emacs for Mac OS X

Sunday, April 17, 2005

When I'm doing Lisp work, I live in Emacs (I've written previously about my Emacs setup for Mac OS X CL programming here and here). However, I use a lot of different software and I find it preferable to get my Emacs configuration to be as similar as possible to the key binding standards of the OS I'm using. For example, when I was using Win32 as my primary OS, I customized my Emacs configuration to use Win32 defaults for a lot of key and mouse operations (I published a version of my configuration on the CL Cookbook site). When I switched to Mac OS X, I initially stuck with my Win32 settings because that was what I was used to and I thought it would be easier to leave things alone until I decided what worked best for me under OS X. However, the more I used OS X, the more irritating the old Win32 bindings became for me. So, I've gradually adopted a more Mac OS X flavored set of key bindings. Some of these I've adapted from other people's .emacs file settings (see here), some of them just seemed "right" to me or were ideas I picked up along the way from others. So, for anyone who is in a similar situation and would like some ideas for their .emacs file, you might want to have a look at my .emacs file (which has both Win32 and Mac OS X configuration settings as well as a lot of Lisp-specific stuff).

If you're primarily interested in the Mac-specific stuff, the main things that I've done are

For my Mac OS X platform-specific changes, here are the code snippets from my .emacs file:
;; See if we're on MS Windows or Mac OS X
(defvar mswindows-p (string-match "windows" (symbol-name system-type)))
(defvar macosx-p (string-match "darwin" (symbol-name system-type)))
(require 'cua-base) (cua-mode t)
(if macosx-p (progn ;; fix a mac-specific problem with ptys (setq process-connection-type nil) ;; repair bogus default directory (if (equal default-directory "/") (setq default-directory "~/"))
;; Mac-style cut/copy/paste (setq mac-command-key-is-meta nil) (setq cua-enable-cua-keys nil) (global-set-key [(alt x)] 'cua-cut-region) (global-set-key [(alt c)] 'cua-copy) (global-set-key [(alt v)] 'cua-paste) (global-set-key [(alt a)] 'mark-whole-buffer) (global-set-key [(alt s)] 'save-buffer) (global-set-key [(alt S)] 'write-file) (global-set-key [(alt p)] 'ps-print-buffer) (global-set-key [(alt o)] 'find-file) (global-set-key [(alt q)] 'save-buffers-kill-emacs) (global-set-key [(alt w)] 'kill-buffer-and-window) (global-set-key [(alt z)] 'undo) (global-set-key [(alt f)] 'isearch-forward) (global-set-key [(alt g)] 'query-replace) (global-set-key [(alt l)] 'goto-line) (global-set-key [(alt m)] 'iconify-frame) (global-set-key [(alt n)] 'new-frame) (global-set-key [kp-delete] 'delete-char) (global-set-key [(control kp-home)] 'beginning-of-buffer) (global-set-key [(control kp-end)] 'end-of-buffer) ;; Mac Open/Execute from dired (define-key dired-mode-map "w" (function (lambda () (interactive) (shell-command (concat "/usr/bin/open " (dired-get-filename))))))))
I would be interested in hearing from others what Emacs modifications they have made in order to make their Mac OS X experience better.

emacs Copyright © 2005 by Bill Clementson