2014年12月18日木曜日

「このEmacs Lispを使っている人はこんなEmacs Lispも使っています」がわかるwebサービス、el-moreを作っています

これは Emacs Advent Calendar 2014 の18日目の記事です。

Emacs Lispパッケージをおすすめするwebサービス、el-more を作っています。 「このEmacs Lispを使っている人はこんなEmacs Lispも使っています」がわかります。

現在、Herokuで動いています。

このEmacs Lispを使っている人はこんなEmacs Lispも使っています

expand-region を使っている人は multiple-cursorsyasnippet も使っているようです。

yaml-mode を使っている人は markdown-modecoffee-mode みたいな言語用のmajor-modeも使っているようです。

おもしろいですね。

みなさんもお気に入りのEmacs Lispのページを見てみてください。知らなかった素敵なEmacs Lispが見つかるかもしれません。

しくみ

  • GitHubで公開されているCaskファイルを検索 ()。 これで誰がどのEmacs Lispパッケージを使っているかがわかります。
  • MELPA からEmacs Lispパッケージの情報を取得します。
  • パッケージどうしの類似度 (この場合は一緒にインストールされる確率) を計算します。

実装

Ruby on Railsで作りました。

Herokuで動いています。Herokuで無料で使えるのは

  • DB (Heroku Postgres) 10000行
  • key-value store (Redis Cloud) 25MB

とかで、データ量をこれ以下に抑えるために泣く泣く集計対象のユーザ数を絞っています。(現在は100人)

ソースコード

ソースコードはGitHubにあります。

おわりに

公開したばかりでまだまだ未完成だと思います。

問題点、改善案、疑問、使ってみた感想など、何でも気軽にご連絡ください (Twitter)。

2014年9月2日火曜日

MacのEmacsでmozc.elを使う (mozc-serverをVagrantで動かす)

前回 、MacのEmacsでmozc.elを使うために、mozc-serverをビルドする手順を紹介しました。しかしその手順でビルドできない方がいたので、別の方法を試してみます。

今回はmozc-serverを仮想マシンで動かします。

  • Vagrant
  • VirtualBox

が必要です。

手順

結果

mozc.elが動きました。

mozc.elが動けばac-mozcも動くはずです。

2014年4月17日木曜日

MacのEmacsでmozc.elを使う (Mozcのビルド)

Mozcは、Google 日本語入力のオープンソース版のIMEです。 そしてmozc.elは、Mozcを使ってEmacsで日本語入力するためのEmacs Lispです。

今回は、Mac上のEmacsでmozc.elを使って日本語入力できるようにします。

EmacsとMozcは以下のような感じで通信しているみたいです。

[Emacs + mozc.el] <-- S式 --> [mozc_emacs_helper] <-- IPC --> [Mozc server]

EmacsとMozc serverが通信するのにmozc_emacs_helperが必要ですが、公式にはMac上でのビルドに対応していません。 なのでビルド用のスクリプトをちょっといじって、ビルドできるようにしました。

要件

公式のMacBuildInstructionsには

  • システム要件
    • OSX 10.5 or later intel only
  • ソフトウェア要件
    • Xcode
    • Qt 4.6.3 or later (optional)

とあります。Qtはオプションということなので今回は無しでビルドします。

私は OS X 10.9.2 + Xcode 5.1.1 で実行しました。

ビルド手順

詳細は公式のMacBuildInstructionsも参照してください。

ソースコードの取得

$ cd ~/
$ svn co http://src.chromium.org/svn/trunk/tools/depot_tools
$ export PATH=`pwd`/depot_tools:"$PATH"
$ mkdir -p ~/src/mozc
$ cd ~/src/mozc
$ gclient config http://mozc.googlecode.com/svn/trunk/src
$ gclient sync

gclient sync

Error: Command svn checkout https://src.chromium.org/chrome/trunk/src/tools/clang/scripts@171017 ...

みたいなエラーが出ましたが気にしないことにします。

build_mozc.pyを上書きします。

$ cd ~/src/mozc/src
$ curl -O https://raw.githubusercontent.com/igjit/mac-emacs-mozc/master/build_mozc.py

ビルドの実行

$ python build_mozc.py gyp --noqt
$ python build_mozc.py build_tools -c Release
$ python build_mozc.py build -c Release mac/mac.gyp:GoogleJapaneseInput mac/mac.gyp:gen_launchd_confs unix/emacs/emacs.gyp:mozc_emacs_helper

インストールします。

$ sudo cp -r out_mac/Release/Mozc.app /Library/Input\ Methods/
$ sudo cp out_mac/DerivedSources/Release/mac/org.mozc.inputmethod.Japanese.Converter.plist /Library/LaunchAgents
$ sudo cp out_mac/DerivedSources/Release/mac/org.mozc.inputmethod.Japanese.Renderer.plist /Library/LaunchAgents

ここで一旦GUIをログアウトします。 再ログイン後にMozcが使えるようになります。

動作確認

$ cd ~/src/mozc/src
$ echo -e '(0 CreateSession)\n(1 SendKey 1 97)' | out_mac/Release/mozc_emacs_helper
((mozc-emacs-helper . t)(version . "1.13.1651.101")(config . ((preedit-method . roman))))
((emacs-event-id . 0)(emacs-session-id . 1)(output . ()))
((emacs-event-id . 1)(emacs-session-id . 1)(output . ((id . "9469176874988818267")(mode . hiragana)(consumed . t)(preedit . ((cursor . 1)(segment ((annotation . underline)(value . "あ")(value-length . 1)(key . "あ")))))(candidates . ((size . 1)(candidate ((index . 0)(value . "あ")(annotation . ((description . "ひらがな")))(id . 0)))(position . 0)(category . suggestion)(display-type . main)(footer . ((label . "Tabキーで選択")))))(status . ((activated . t)(mode . hiragana)(comeback-mode . hiragana)))(all-candidate-words . ((candidates ((id . 0)(index . 0)(value . "あ")(annotation . ((description . "ひらがな")))))(category . suggestion))))))
$ 

Emacsの設定

init.elに以下を追記します。

;; (require 'mozc)
(load "~/src/mozc/src/unix/emacs/mozc.el")
(setq default-input-method "japanese-mozc")

;; exec-pathが通っていれば不要
(setq mozc-helper-program-name "~/src/mozc/src/out_mac/Release/mozc_emacs_helper")

C-\ で日本語入力が切り替わるはずです。 動作確認ができたら mozc.el, mozc_emacs_helper をそれぞれ load-path, exec-path の通った場所に置いてください。

See also

mozc.elを使ったモードレス日本語入力インタフェース、ac-mozc を作っています。 良かったらこちらも試してみてください。

(追記)

この手順でビルドできない方がいたので、別の方法を試してみました。

MacのEmacsでmozc.elを使う (mozc-serverをVagrantで動かす)