anything から refe.el を使う
Emacs から「るりま」を引くときは anything を使うのが普通らしい。
anything から refe.el を使えるようにしてみた。
refe.el を使う意味は?
特にない。
やってみたかったから。
refe.el の修正
refe に検索する単語を渡せるようにする。
(defvar refe-program-name (if (featurep 'meadow) "ruby" "refe")) (defvar refe-program-args (if (featurep 'meadow) '("-S" "refe") nil)) (defvar refe-buffer-name "*Refe*") (defvar refe-completion-table nil) (defun refe-call-process (buf &rest args) (let ((coding-system-for-read 'euc-japan)) (apply 'call-process refe-program-name nil buf nil (append refe-program-args args)))) (defun refe-make-completion-table () (setq refe-completion-table (make-vector 547 0)) (with-temp-buffer (refe-call-process t) (goto-char (point-min)) (while (looking-at "[A-Z][A-Za-z_0-9:]*") (intern (match-string 0) refe-completion-table) (skip-chars-forward "^ \n") (skip-chars-forward " \n"))) (with-temp-buffer (refe-call-process t "") (goto-char (point-min)) (while (looking-at "\\(\\$[^ \n]*\\|[A-Z][A-Za-z_0-9:]*[#.][^ \n]*\\)") (intern (match-string 0) refe-completion-table) (skip-chars-forward "^ \n") (skip-chars-forward " \n"))) nil) (refe-make-completion-table) (defun refe-get-word-at-point () (save-excursion (while (looking-at "\\sw\\|\\s_") (forward-char 1)) (if (or (re-search-backward "\\sw\\|\\s_" (save-excursion (beginning-of-line) (point)) t) (re-search-forward "\\(\\sw\\|\\s_\\)+" (save-excursion (end-of-line) (point)) t)) (progn (goto-char (match-end 0)) (buffer-substring (point) (progn (forward-sexp -1) (while (looking-at "\\s'") (forward-char 1)) (point)))) nil))) (defun refe (&optional word) (interactive) (if (null refe-completion-table) (refe-make-completion-table)) (let* ((default (refe-get-word-at-point)) (completion-ignore-case t) (buf (or (get-buffer refe-buffer-name) (generate-new-buffer refe-buffer-name))) (pop-up-windows t) (pop-up-frames nil)) (if (null word) (setq word (completing-read (if default (format "Class or Method (default %s): " default) "Class or Method: ") refe-completion-table nil nil nil nil default))) (set-buffer buf) (setq buffer-read-only nil) (erase-buffer) (refe-call-process buf word) (goto-char (point-min)) (if (re-search-forward "^---" nil t) nil (let ((klass-table (make-vector 17 0)) (completion-ignore-case t) klass) (goto-char (point-min)) (while (looking-at "\\([A-Z][A-Za-z_0-9:]*\\)[#.][^ \n]*") (intern (match-string 1) klass-table) (skip-chars-forward "^ \n") (skip-chars-forward " \n")) (if (= (point) (point-min)) nil ; (message "no such class or method: %s" word) (setq klass (completing-read "Class: " klass-table nil nil nil nil nil)) (erase-buffer) (refe-call-process buf "--all" klass word)))) (set-buffer-modified-p nil) (setq buffer-read-only t) (goto-char (point-min)) (display-buffer buf))) (provide 'refe)
以前書いたように refe.el のライセンスは、なんともフワフワした状態なので要注意。
refe.e の作成
こんなスクリプトを用意した。
#! /usr/local/bin/bash RUBY=/usr/local/bin/ruby19 sexp() { $RUBY -ne 'puts %Q<# (refe "#{$_.strip.gsub(/"/, %q[\\"]).sub(/\.#/, %q[.])}")>' } classes() { refe -l } methods() { refe -l '' } (classes; methods) | sexp
やってることは rubikitch さんと同じ (はず)
実行結果を refe.e に保存する。
anything の設定
上記 rubikitch さんのエントリからパクる。
elisp で , とか ` とか出てきたら、もうお手上げ。
毎月公開される「るりま」のスナップショットが出たら refe.e だけ作り直せば OK.