My .emacs

emacs 當然不是最好上手的 editor,不過功能強大、擴充容易,目前仍然是程式開發最佳選擇之一。我的 .emacs 設定檔設定了 [f4] 為關檔、[f5] 為執行make、[ctrl-enter] 為設定記號,因為原先的 [ctrl-space] 會跟輸入法衝到。另外 (windmove-default-keybindings) 是超好用的視窗切換熱鍵,例如要移到下方的視窗,就是按 shift-down。印象中這功能在 21 版還沒有。剩下的功能都是直接在 emacs 裡頭執行 customize 來設定的,建議就不要手動改了。

幾個比較特別或有用的設定:

'(current-language-environment "Chinese-BIG5") 用來指定預設環境為BIG5中文。這環境在UTF-8以及BIG5底下都工作正常,但這到22版才真正有用。

'(default-major-mode (quote text-mode)) 由於 emacs 是我預設用來寫email的editor,所以設定預設模式為text-mode會比原本的fundamental-mode方便。

'(initial-frame-alist (quote ((width . 80) (height . 60)))) 改變預設視窗大小。

'(server-mode t) server-mode是個很好用的新功能。打開之後,只要在其他視窗打emacsclient xxx就會自動用已經在執行的emacs開檔。我目前環境變數EDITOR的內容為”emacsclient -a emacs”,試試看。

'(winner-mode t nil (winner))) 視窗調大小以後可以用winner-mode還原/重做。熱鍵是 Ctrl-C, left/right.

調字型的方法:22版對gtk支援,應該是不用調。真的要調的話,用shift-滑鼠左鍵叫出字型視窗,選到自己喜歡的以後,進入customize-group, basic-face, default底下,把那邊的值寫入.emacs即可。

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
;; global set key
(global-set-key [f4] `kill-buffer)
(global-set-key [f5] `compile)
(global-set-key [C-return] `set-mark-command)
(windmove-default-keybindings)

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(c-default-style (quote ((c-mode . "stroustrup") (java-mode . "java") (awk-mode . "awk") (other . "gnu"))))
'(current-language-environment "Chinese-BIG5")
'(default-major-mode (quote text-mode))
'(initial-frame-alist (quote ((width . 80) (height . 60))))
'(prolog-system (quote gnu))
'(scroll-bar-mode (quote right))
'(server-mode t)
'(show-paren-mode t)
'(tool-bar-mode nil)
'(user-mail-address "cylee@programmer.net")
'(winner-mode t nil (winner)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:stipple nil :background "black" :foreground "grey" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 105 :width normal :family "adobe-courier")))))