アウトラインモード

Emacsphp-modeを使う時に関数やコメントを折りたたむアウトラインモードのelisp

;;; アウトラインモード(php)
 (add-hook
  'php-mode-hook
  '(lambda ()
    (setq outline-regexp "^<\\?\\|^\\?>\\|^class\\|^  function\\|^    function\\|^/\\*\\*\\|^  /\\*\\*\\|^    /\\*\\*")
    (setq outline-level
     (function (lambda ()
      (save-excursion
        (let ((str nil))
          (looking-at outline-regexp)
          (setq str (buffer-substring-no-properties
                     (match-beginning 0) (match-end 0)))
          (cond
           ((string-match "^/\\*\\*" str) 1)
           ((string-match "^<\\?" str) 1)
           ((string-match "^\\?>" str) 1)
           ((string-match "^class" str) 1)
           ((string-match "^  /\\*\\*" str) 2)
           ((string-match "^    /\\*\\*" str) 2)
           ((string-match "^  function" str) 3)
           ((string-match "^    function" str) 3)
           ))))))
     (outline-minor-mode t)
     (hide-body)))

;; ついでにタブ幅なんかも
(add-hook
 'php-mode-hook
 '(lambda ()
    (setq tab-width 4
          c-basic-offset 4
          c-hanging-comment-ender-p nil
          indent-tabs-mode nil))
 )

マッチする正規表現や最後の(hide-body)はお好みで。


簡易マニュアル

  • C-c @ C-a : 全表示
  • C-c @ C-e : 展開
  • C-c @ C-c : 折りたたみ

これくらいしか使ってないから、枝レベルの設定がちゃんとしてない・・。



※参考
何でもアウトラインモード
http://www.bookshelf.jp/pukiwiki/pukiwiki.php?%B2%BF%A4%C7%A4%E2%A5%A2%A5%A6%A5%C8%A5%E9%A5%A4%A5%F3%A5%E2%A1%BC%A5%C9