続、Emacsを統合環境として使おう

昨日の続き

基本的な設定

id:naoyaが以前WEB+DB PRESSで特集していたサーポートページに基本的な設定を書いたdot.emacsがあるのでそれを参考にして設定

WEB+DB PRESS Vol.40 特集2 サポートページ

以下を~/.emacsに追加

;; 日本語設定 (UTF-8)
(set-language-environment "Japanese")
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)

;; フォントロックモード (強調表示等) を有効にする
(global-font-lock-mode t)

;; 一時マークモードの自動有効化
(setq-default transient-mark-mode t)
  
;; C-x C-u が何もしないように変更する (undo の typo 時誤動作防止)
(global-unset-key "\C-x\C-u")

;; 括弧の対応をハイライト.
(show-paren-mode 1) 

;; バッファ末尾に余計な改行コードを防ぐための設定
(setq next-line-add-newlines nil) 

;; C-x l で goto-line を実行
(define-key ctl-x-map "l" 'goto-line) 

;; 時間を表示
(display-time) 

;; 列数表示
(column-number-mode 1) 

;; メニューバーを消す
(menu-bar-mode -1)

;; C-h でカーソルの左にある文字を消す
(define-key global-map "\C-h" 'delete-backward-char)

;; C-h に割り当てられている関数 help-command を C-x C-h に割り当てる
(define-key global-map "\C-x\C-h" 'help-command)

;; C-o に動的略語展開機能を割り当てる
(define-key global-map "\C-o" 'dabbrev-expand)
(setq dabbrev-case-fold-search nil) ; 大文字小文字を区別

;; 日本語・英語混じり文での区切判定
;; http://www.alles.or.jp/~torutk/oojava/meadow/Meadow210Install.html
(defadvice dabbrev-expand
  (around modify-regexp-for-japanese activate compile)
  "Modify `dabbrev-abbrev-char-regexp' dynamically for Japanese words."
  (if (bobp)
      ad-do-it
    (let ((dabbrev-abbrev-char-regexp
           (let ((c (char-category-set (char-before))))
             (cond 
              ((aref c ?a) "[-_A-Za-z0-9]") ; ASCII
              ((aref c ?j) ; Japanese
               (cond
                ((aref c ?K) "\\cK") ; katakana
                ((aref c ?A) "\\cA") ; 2byte alphanumeric
                ((aref c ?H) "\\cH") ; hiragana
                ((aref c ?C) "\\cC") ; kanji
                (t "\\cj")))
              ((aref c ?k) "\\ck") ; hankaku-kana
              ((aref c ?r) "\\cr") ; Japanese roman ?
              (t dabbrev-abbrev-char-regexp)))))
      ad-do-it)))

;; BS で選択範囲を消す
(delete-selection-mode 1)

;; The local variables list in .emacs と言われるのを抑止
(add-to-list 'ignored-local-variables 'syntax) 

rails.elの設定

http://d.hatena.ne.jp/higepon/20061222/1166774270を参考にしまっす。


以下からrails.elをダウンロードしてロードパスの通ったところに置きます。
https://opensvn.csie.org/mvision/emacs/.emacs.d/rails.el


~/.emacsに以下を追加

;;;;emacs-Rails
(require 'find-recursive)

;;setq load-path (cons "~/elisp/rails" load-path))
(require 'rails)
(require 'rails-ruby)
(define-key rails-minor-mode-map "\C-c\C-p" 'rails-lib:run-primary-switch)
(define-key rails-minor-mode-map "\C-c\C-n" 'rails-lib:run-secondary-switch)

rcodetoolsのインストール

xmpfilterは激しく便利なので入れておく

gemから入れる
sudo gem install rcodetools*1

これだけでemacsからM-x xmpするだけで使える

楽ちん

詳しくはhttp://d.hatena.ne.jp/bornite/20080712/1215830649をみるとわかりやすい

せっかくrcodetoolsを入れたのでEclipseっぽくメソッド名とか補完する機能をつかう


なにやらM-x rct-complete-symbolすると入力途中の補完候補がミニバッファにでてくる

かなり素敵!!

どうせならanythingと連携させてみる

最新版の0.8.0からは標準でanything-rcodetools.elがついてくるみたい

ロードパスが通ったところに以下からanything.elをダウンロードして配置
http://www.emacswiki.org/cgi-bin/wiki/Anything

あとmy-anything-configを作る
http://d.hatena.ne.jp/trotr/20071121を参考に

(require 'anything-config)
(defvar anything-c-source-file-cache
  '((name . "File Cache")
    (candidates . file-cache-files)
    (type . file)))
;; locate
(defvar locate-home-database "/var/db")
(defvar anything-c-source-locate-home
  '((name . "Locate")
    (candidates . (lambda ()
                    (start-process "locate-process" nil
                                   "locate" "-d" locate-home-database "-i" "-r" anything-pattern)))
    (type . file)
    (requires-pattern . 3)
    (delayed))
"Source for retrieving files in home directory matching the current input patternwith locate.")

(setq anything-sources (list anything-c-source-buffers
                             anything-c-source-files-in-current-dir
                             anything-c-source-file-cache
                             ;;anything-c-source-bookmarks
                             ;;anything-c-source-file-name-history
                             anything-c-source-emacs-commands
                             ;;anything-c-source-locate-home
                             ;;anything-c-source-man-pages



                             anything-c-source-complete-ruby-all
                             anything-c-source-complete-ruby
                             ;;anything-c-source-complex-command-history
                             ))

(defun anything-get-sources ()
  "Return `anything-sources' with the attributes from
  `anything-type-attributes' merged in."
  (mapcar (lambda (source)
            (let* ((source (if (listp source)
                               source
                             (symbol-value source)))
                   (type (assoc-default 'type source)))
              (if type
                  (append source (assoc-default type anything-type-attributes) nil)
                source)))
          anything-sources))


(provide 'my-anything-config)

以下を~/.emacsに追記

  (require 'anything)

  ;; Ruby Completion
  (require 'anything-rcodetools)
  (require 'my-anything-config)
  (global-set-key "\C-c\C-c" 'anything)


 ;; (global-set-key [f7] 'anything)
  (define-key anything-map (kbd "M-n") 'anything-next-source)
  (define-key anything-map (kbd "M-p") 'anything-previous-source)

  ;; Command to get all RI entries.
  (setq rct-get-all-methods-command "PAGER=cat fri -l")
  ;; See docs
  (define-key anything-map "\C-z" 'anything-execute-persistent-action)
  (global-set-key "\M-o" 'rct-complete-symbol--anything)

あとfast-riも必要みたいだから別途いれる

今日はここまで

*1:rodetoolsになっていたので修正しました