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
- Use the Mac "Option" key as "Meta" rather than the Mac "Command" key and use the Mac "Command" key for "Alt" functionality in Emacs. This allows me to leave existing Emacs "Meta" key mappings alone and to add some of the standard Mac command mappings to the "Command" key. That way, my Emacs "finger memory" can stay the same and my Mac "finger memory" can stay the same too!
- In dired, the "w" key will either open or execute the file that the cursor is on using the default action for that file type.
;; 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)))I would be interested in hearing from others what Emacs modifications they have made in order to make their Mac OS X experience better.
(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))))))))

