ひとつの .emacs で設定を書き分けるための Tips。

追記 この記事を元に書籍が出来ました!

時間と命を削って、より詳細に解説しましたので、Emacs に興味がある人はぜひ一度手に取ってみて下さい。

Emacs実践入門 ?思考を直感的にコード化し、開発を加速する (WEB+DB PRESS plus)

Emacs実践入門 ?思考を直感的にコード化し、開発を加速する (WEB+DB PRESS plus)

導入 Elisp 別の書き分け方法の記事を書きましたので、併せてどうぞ。
様々な環境で Emacs を使う場合、それぞれの環境に合せた .emacs を用意する必要があります。
ですが、環境別に複数のファイルを用意するのは非常に面倒なので、使うシステムによって要不要を判断してくれる分岐を行なうと便利です。
僕の場合は、elim んの .emacsから勉強させてもらい、環境によって真偽値を返す変数を作成し、それを使って分岐する方法を使っています。
具体的にはこうです。

(defun x->bool (elt) (not (not elt)))

;; emacs-version predicates
(setq emacs22-p (string-match "^22" emacs-version)
	  emacs23-p (string-match "^23" emacs-version)
	  emacs23.0-p (string-match "^23\.0" emacs-version)
	  emacs23.1-p (string-match "^23\.1" emacs-version)
	  emacs23.2-p (string-match "^23\.2" emacs-version))

;; system-type predicates
(setq darwin-p  (eq system-type 'darwin)
      ns-p      (eq window-system 'ns)
      carbon-p  (eq window-system 'mac)
      linux-p   (eq system-type 'gnu/linux)
      colinux-p (when linux-p
                  (let ((file "/proc/modules"))
                    (and
                     (file-readable-p file)
                     (x->bool
                      (with-temp-buffer
                        (insert-file-contents file)
                        (goto-char (point-min))
                        (re-search-forward "^cofuse\.+" nil t))))))
      cygwin-p  (eq system-type 'cygwin)
      nt-p      (eq system-type 'windows-nt)
      meadow-p  (featurep 'meadow)
      windows-p (or cygwin-p nt-p meadow-p))

で、例えば Mac での様々なバージョン向けの設定をひとつのファイルに書きたい場合は、

(when darwin-p
  (setq grep-find-use-xargs 'bsd)
  (setq browse-url-generic-program "open")
  (setq visible-bell t)
  (define-key global-map [(super right)] 'split-window-horizontally)
  (define-key global-map [(super down)] 'split-window-vertically)
  (define-key global-map [(super w)] 'delete-window)
  (when carbon-p
	(setq mac-command-key-is-meta nil)
	(setq mac-option-modifier 'meta)
	(setq mac-command-modifier 'super)
	(setq mac-pass-control-to-system t)
	(scroll-bar-mode -1)
	(tool-bar-mode -1)
	(when emacs22-p
	  (define-key global-map [(super v)] 'yank)))
  (when ns-p
	(setq ns-command-modifier 'super)
	(setq ns-alternate-modifier 'meta)
	(scroll-bar-mode -1)
	(require 'ns-platform-support)
	(ns-extended-platform-support-mode 1)))

という感じで書き分けることができます。
ちなみに、ターミナルかどうかを判断する場合は、window-system という変数があるので、それを使う形になるでしょう。