Emacs .emacs
設定内容
Elisp
  一番重要な .emacs
  データ型
    assoc 連想リスト
  制御構造
    if
    cond
    progn
  条件
    等しいか eq equal
    述語の種類
    数字の比較
    list の比較
    文字の比較
    変数内容が空の時
  関数定義
試す(評価する)
    Lisp Interaction
    eval-region
    c-x c-e
良く使う文
  setq
    setq と defvar
    append
    list
    cons
  autoload
  global-set-key
  custom-set-variables
  add-hook
    どんな hook があるか
良く使われる変数
    変数の値の調べ方
    load-path
    file-coding-system-alist
    debug-on-error
    default-frame-alist
    auto-mode-alist
    fill-column
  variables
  others
日本語環境
  coding-system
      まとめて
設定のこつ
    info を見る
    *.el の最初の方に
     *-vars.el の中
    だらだらと書かない
  mode line 等
    mail 状況
    時刻を表示
    行・桁番号
    スクロールバーの位置
  key
  scroll mouse
  Emacs 版別
  X Window System
  dired
    cc
  文字に色を付ける
    color-mate
  Font Lock
    set-face-font
  Faces
  fontset
  他の方の .emacs
  その他の URL
  DEFAULTS
  かっこ合せ
    add-change-log-entry
    add-log-mailing-address

emacs-21 | dot.emacs | application | 始め方 | emacs-20 | らくらく入門

add-hook

hook というのは、「ひっかけるかぎ」である。 それぞれの Elisp の中に用意されていて、その名前が分ったら、利用出来る。 例えば C-x C-f (find-file) には find-file-hooks というのが用意されている。
(add-hook 'find-file-hooks
          (function (lambda ()
                      (if (string-match "makoto/writing" buffer-file-name)
                          (setq fill-column 44))
                      (if (string-match "makoto/writing/jk" buffer-file-name)
                          (setq fill-column 84))
                      (if (string-match "vertical/" buffer-file-name)
                          (setq fill-column 40))
                      (if (string-match "Mail/draft/" buffer-file-name)
                          (setq fill-column 60)) ;; not good now
                      (if (string-match "makoto/diary/" buffer-file-name)
                          (setq default-buffer-file-coding-system 'euc-japan)
                        (setq default-buffer-file-coding-system 'iso-2022-jp ))
)))
次のようにして試す。
(add-hook 'find-file-hooks
          (function (lambda ()
                      (if (string-match "\\.eeee$" buffer-file-name)
                          (set-buffer-file-coding-system 'euc-japan))
)))
こうしておくと、譜を新規に開ける時に、 *.eeee という名前の時には euc, それ以外の場合には iso-2022-jp になる。

どんな hook があるか

というのは、変数名と同じで、次のような探し方があると思う。
  • Standard hooks に書いてある
  • info 等の説明に書いてある
  • *.el や *var.el の中を見る
  • M-x apropos RET packagename.*hook RET として探す
例えば M-x apropos RET find-file.*hook RET とすると、次の三つが見つかる。
find-file-hooks
  Variable: List of functions to be called after a buffer is loaded from a file.
  Plist: variable-documentation
find-file-not-found-hooks
  Variable: List of functions to be called for `find-file' on nonexistent file.
  Plist: variable-documentation
vc-find-file-hook
  Function: Function for `find-file-hooks' activating VC mode if appropriate.
この画面は Jeedosaquin によって表示しています。
Last Update: Sat, 07 Jun 2014 22:16:17 GMT 1.66 2008/03/08