Emacs をタブブラウザ化する (Vine Linux 4.2)

  • これは Emacs の「タブブラウザ化」(tabbar.el) + 「前回終了時のバッファ状態復元」(revive.el) の設定を一般ユーザで行った際の作業メモです
  • 動作確認済の環境

設定後の見た目と操作

  • タブ表示
    • タブ選択: マウスクリック,Ctrl-TabCtrl-Shift-Tab
    • 表示・非表示の変更: F4
  • バッファ状態復元
    • 状態復元: Ctrl-x F
    • 状態保存: Ctrl-x S または Emacs 終了時

準備

$ mkdir -p ~/lib/emacs
$ cd ~/lib/emacs

タブを表示する(tabbar.el)

$ tar -xvzf tabbar-1.3.tar.gz
  • 設定
    • ~/.emacs.my.el に以下の設定を追記する
      • タブをグループ化しない
      • scratch buffer はタブを非表示にする
      • タブの色を変更
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; tabbar-mode: バッファ上部にタブを表示する
;   
; - 参考ページ 
; -- EmacsWiki - Tab Bar Mode:
;      http://www.emacswiki.org/cgi-bin/wiki/TabBarMode
; -- 見た目の変更 - Amit's Thoughts: Emacs: buffer tabs:
;      http://amitp.blogspot.com/2007/04/emacs-buffer-tabs.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; scratch buffer 以外をまとめてタブに表示する
(require 'cl) ; for emacs-22.0.50 on Vine Linux 4.2
 (when (require 'tabbar nil t)
    (setq tabbar-buffer-groups-function
	  (lambda (b) (list "All Buffers")))
    (setq tabbar-buffer-list-function
          (lambda ()
            (remove-if
             (lambda(buffer)
               (find (aref (buffer-name buffer) 0) " *"))
             (buffer-list))))
    (tabbar-mode))

;; Ctrl-Tab, Ctrl-Shift-Tab でタブを切り替える
  (dolist (func '(tabbar-mode tabbar-forward-tab tabbar-forward-group tabbar-backward-tab tabbar-backward-group))
    (autoload func "tabbar" "Tabs at the top of buffers and easy control-tab navigation"))
  (defmacro defun-prefix-alt (name on-no-prefix on-prefix &optional do-always)
    `(defun ,name (arg)
       (interactive "P")
       ,do-always
       (if (equal nil arg)
  	 ,on-no-prefix
         ,on-prefix)))
  (defun-prefix-alt shk-tabbar-next (tabbar-forward-tab) (tabbar-forward-group) (tabbar-mode 1))
  (defun-prefix-alt shk-tabbar-prev (tabbar-backward-tab) (tabbar-backward-group) (tabbar-mode 1))
  (global-set-key [(control tab)] 'shk-tabbar-next)
  (global-set-key [(control shift tab)] 'shk-tabbar-prev)

;; 外観変更
 (set-face-attribute
   'tabbar-default-face nil
   :background "gray60")
  (set-face-attribute
   'tabbar-unselected-face nil
   :background "gray85"
   :foreground "gray30"
   :box nil)
  (set-face-attribute
   'tabbar-selected-face nil
   :background "#f2f2f6"
   :foreground "black"
   :box nil)
  (set-face-attribute
   'tabbar-button-face nil
   :box '(:line-width 1 :color "gray72" :style released-button))
  (set-face-attribute
   'tabbar-separator-face nil
   :height 0.7)

;; F4 で tabbar-mode
(global-set-key [f4] 'tabbar-mode)

前回終了時のバッファ状態を復元する(revive.el)

$ wget http://www.gentei.org/~yuuji/software/revive.el
  • 設定
    • ~/.emacs.my.el に以下の設定を追記する
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; revive.el: buffer 状態の保存・復元
;
; - 参考ページ
; -- Emacs で前回終了時のバッファ(全て)を復元したい - Hasta Pronto.org:
;      http://www.hasta-pronto.org/archives/2008/01/30-0235.php
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'save-current-configuration "revive" "Save status" t)
(autoload 'resume "revive" "Resume Emacs" t)
(autoload 'wipe "revive" "Wipe emacs" t)
(define-key ctl-x-map "S" 'save-current-configuration)    ; C-x S で状態保存
(define-key ctl-x-map "F" 'resume)                        ; C-x F で復元
(add-hook 'kill-emacs-hook 'save-current-configuration)   ; 終了時に状態保存

動作確認

  • Emacs でいくつかファイルを開いて終了する
  • Emacs を起動する
    • Ctrl-x F でバッファ状態が復元することを確認する
    • タブが表示されることを確認する