anything.el設定やり直し

fluxbuntu7.10に変えてから、設定するのが面倒くさかったので放置していたanythingの設定をやり直し。

したこと

下の3つをanythingから検索できる用にする。

  • file-cache
  • rubycodetools (codeの補完?まだ上手く設定できていない気がする)
  • ホームディレクトリのlocate

anything.elをdownload

buf="<*.elを入れておくディレクトリのpath>"
wget --directory-prefix=$buf http://www.emacswiki.org/cgi-bin/emacs/download/anything.el
wget --directory-prefix=$buf http://www.emacswiki.org/cgi-bin/emacs/download/anything-rcodetools.el
wget --directory-prefix=$buf http://www.emacswiki.org/cgi-bin/emacs/download/anything-config.el

rcodetoolsをinstall

sudo gem install rcodetools -y
#$ find /var/lib/gems/1.8/gems/ *.el | grep rcodetools\.el
#>/var/lib/gems/1.8/gems/rcodetools-0.7.0.0/icicles-rcodetools.el
#>/var/lib/gems/1.8/gems/rcodetools-0.7.0.0/rcodetools.el
cp /var/lib/gems/1.8/gems/rcodetools-0.7.0.0/rcodetools.el $buf

ホームディレクトリのlocate_dbを作成

locate -U ~/ -o -e  "<何か除外するディレクトリ>" "<locatedbを置くpath>" 

my-anything-config.elを作る

rubikitchさんの日記を参考にhttp://d.hatena.ne.jp/rubikitch/

(require 'anything-config)

(defvar anything-c-source-file-cache
  '((name . "File Cache")
    (candidates . file-cache-files)
    (type . file)))

;;;; locate
(defvar locate-home-database "<locatedbを置くpath>")
(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-complex-command-history))

(provide 'my-anything-config)

.emacsの設定

似たような設定の部分はletでくくると見やすいかもしれない。

(add-to-list 'load-path "<*.elを入れておくディレクトリのpath>")
;;file-cache
(require 'filecache)

(file-cache-add-directory-list
 (list "~/memo" "~/test" "~"))

;;anything;
(let ()
  (require 'anything)
  (require 'my-anything-config)

  ;; Ruby Completion
  (require 'anything-rcodetools)
  (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)
)

準備運動用のメニューを出力

shellを立ち上げるのも面倒になった。

最近は、PCをつけたらまずはじめにこんなかんじのことをしています。
(shellを立ち上げて、"quiz.rb"を起動。ー>一行程度でお題が出される。それを5分ぐらいでする。)
shellを立ち上げるのも面倒になりました。emacsでM-! quiz.rbとかも面倒。f3を押したら今日のメニューが出てくる位がいいです。そんなわけでこんな感じの関数を.emacsに記述。

;;quiz用。後でキー配置を変えるかもしれない。
(global-set-key [f3] (lambda () (interactive)
		       (shell-command "ruby ~/script/quiz.rb")))

これで、emacsが開いていればいつでも一瞬でquizのメニューが呼び出せるようになります。