この投稿はEmacs Advent Calendar 2012の 7日目の記事です。
拙作の helmプラグインを紹介しようかと思ったのですが、
そもそも helm(anything)を使っている人がものすごく多いって
わけではなさそうなので、おすすめの拡張をいくつか紹介しようと
思います。
事前準備
helmは MELPA, el-get等でインストールできます。
package.elでのインストール方法を事前に示します。
以下の設定を ~/.emacs.d/init.el, ~/.emacs等に追加してください。
(require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/")) (package-initialize)
以下のコマンドを実行します。
M-x package-refresh-contents M-x package-install(インストールする拡張を問われるので helmと入力してください)
helm-recentf
個人的に一番多用するのは helm-recentfです。
recentfの helm-interfaceですが、素の recentfのインタフェースが
若干微妙なのでかなり使いやすくなります。過去に開いたファイルを
開くということはかなり多い作業なので、これが使いこなせれば、
find-fileをする回数が劇的に減ります。良く使うので私は "C-x C-r"に
バインドしています。
helm-show-kill-ring
yank-popの helm interfaceです。過去にコピーしたものの貼り付けが
楽になります。browse-yankをより便利にしたような感じでしょうか。
これはそのまま M-yにバインドしています。
helm-git-project
これは@yaottiさんのこの記事に掲載される anything向けのものを
helm対応し、トップディレクトリを起点に表示する修正を加えたものです。
Gitプロジェクトの中のファイルを開くというものです。Gitで管理される
プロジェクトは多いと思いますので、すごく役立つ場面があります。
変更を加えたもの、未登録のもの、その他のソースを分けているので、
見やすくなっていて重宝しています。なお "C-;"にバインドしています。
コード
(defun helm-c-sources-git-project-for (pwd) (loop for elt in '(("Modified files" . "--modified") ("Untracked files" . "--others --exclude-standard") ("All controlled files in this project" . nil)) for title = (format "%s (%s)" (car elt) pwd) for option = (cdr elt) for cmd = (format "git ls-files %s" (or option "")) collect `((name . ,title) (init . (lambda () (unless (and (not ,option) (helm-candidate-buffer)) (with-current-buffer (helm-candidate-buffer 'global) (call-process-shell-command ,cmd nil t nil))))) (candidates-in-buffer) (type . file)))) (defun helm-git-project-topdir () (file-name-as-directory (replace-regexp-in-string "\n" "" (shell-command-to-string "git rev-parse --show-toplevel")))) (defun helm-git-project () (interactive) (let ((topdir (helm-git-project-topdir))) (unless (file-directory-p topdir) (error "I'm not in Git Repository!!")) (let* ((default-directory topdir) (sources (helm-c-sources-git-project-for default-directory))) (helm-other-buffer sources "*helm git project*"))))
helm yasnippet
@sugyanさんのこの記事の anythingのものを
helm対応したものです。TABとかでスニペットの展開は苦手なのですが、
これは使いやすいと感じています。キーワードを打ってTAB等を使う場合
キーワードを覚えている必要があり、なんだっけ?ってなることが
ありますが、helm(anything)を使えばスニペットの nameヘッダに
説明を書いておいて、それを元に絞り込むことができるので使いやすいです。
"M-="にバインドしています。
コード
(defun my-yas/prompt (prompt choices &optional display-fn) (let* ((names (loop for choice in choices collect (or (and display-fn (funcall display-fn choice)) choice))) (selected (helm-other-buffer `(((name . ,(format "%s" prompt)) (candidates . names) (action . (("Insert snippet" . (lambda (arg) arg)))))) "*helm yas/prompt*"))) (if selected (let ((n (position selected names :test 'equal))) (nth n choices)) (signal 'quit "user quit!")))) (custom-set-variables '(yas/prompt-functions '(my-yas/prompt)))
その他おすすめ
- helm-M-x
- helm-imenu
- helm-c-apropos
- helm-elscreen
- helm-gtags(拙作)
- helm-ack(拙作)
などあります。あと各種プログラミングモードで便利なものが
あることもありますので、よく書く言語で何か便利な helm拡張が
ないか探してみるのも良いでしょう。
明日は@kubosho_さんの color-themeについてです。
お楽しみに。