コンテンツメニュー
高機能で軽いはずの Sublime Text なのに、Mac にインストールした Sublime Text で日本語入力するともたつきませんか!?
そんなあなたに mozc(もずく)を使った日本語入力をご紹介します!
Macのメモリ使用率が高くなると、Sublime Text の日本語入力がすごくもっさりしてきます。
どのくらいもっさりしてくるかというと、キーボードの[a]
から[;]
まで、[a]→[s]→[d]→[f]→・・・→[l]→[;]
と、光の速さで指を走らせた時に、↓下のgifアニメぐらいもっさりしています。
それを、mozc_emacs_helper を使うことで、↓下のgifアニメぐらいに日本語入力が快適になります。
Mac OSX での日本語入力設定でも説明したとおり、
スニペットの展開と予測変換が同じ[tab]
キーに割り当てられているため、どちらかしか有効にできません。
Mac では、スニペット展開と予測変換はトレードオフでしたが、mozc を使って日本語入力すれば、[tab]
キーでスニペット変換も予測変換もすることが可能です!
前述の問題点を改善し、Sublime Text 3 で快適な日本語入力を実現してくれるのが、Mozc(もずく)です。
Sublime Text 3 で Mozc を使うには以下の2つが必要です。
Mozc を使った日本語入力はとても快適ですが、インストールから初期設定までが修羅の道であり、また Mozc 日本語入力にも癖があります。
以下に Mozc の特徴を記載しますので、確認したうえで導入するかどうかを決めると良いと思います。
前述の通り、兎に角軽いです。導入理由はこれが全てです。
速いことは正義です。
インストールから初期設定までが修羅の道です。
なかなか骨が折れますので、まとまった時間をとってから作業することをおすすめします。
Mac のIME切り替え[cmd]+[space]
のほうが優先度が高いらしく、[cmd]+[space]
に toggle_mozc
を割り当ててもmozc mode に切り替わりませんでした。
ただし、Mac のIME切り替えを別のキーバインディングズに変更すると、[cmd]+[space]
でmozc modeに切り替えできるようになります。
デフォルトはこうですが、キーバインディングズの設定で変更することが可能です。
それでは、Mac にインストールした Sublime Text 3 で Mozc 日本語入力するための設定手順を説明します。
インストールするのは以下の2つです。
以下を参考にしてインストールしました。ありがとうございます。
git-2.2.1-intel-universal-mavericks.dmg
を実行します。git-2.2.1-intel-universal-mavericks.pkg
を右クリックし、開く
を押して、インストールします。
本記事では、作業フォルダは~/Downloads/mozc
とします。
[ctrl]+[space]
で Mac の Spotlight 検索
を表示し、terminal
と入力して、terminal.app
を起動します。
mkdir ~/Downloads/mozc
mozc_emacs_helper のソースを取得するのに使用します。
以下のコマンドを実行して、depot_tools をダウンロードします。
cd ~/Downloads/mozc git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
もし、下記のエラーが発生した場合は、まだ Xcode のライセンスに同意していないということですので、
Xcode を起動してライセンスに同意してください。
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
mozc_emacs_helper はコンパイルして生成するため、mozc ソースをとってきます。
ソースの取得にはすこし時間がかかりますので、気長に待ちましょう。
cd ~/Downloads/mozc depot_tools/gclient config http://mozc.googlecode.com/svn/trunk/src depot_tools/gclient sync
Mac ではコンパイルが通らないため、Mac 用に src/build_mozc.py
を修正する必要があります。
ターミナルから以下のコマンドを入力してパッチを当てることで、ファイルが修正されます。
cd ~/Downloads/mozc/src curl -O https://gist.githubusercontent.com/guehara/856103d2ba2b55dd6789/raw/02262a4ae3f4eab2f3a6bb61d23c303d78ff23c6/build_mozc.py.diff patch -p0 < build_mozc.py.diff
変更点は以下の +
の部分です。
# Include subdirectory of win32 and breakpad for Windows if options.target_platform == 'Windows': gyp_file_names.extend(glob.glob('%s/win32/*/*.gyp' % SRC_DIR)) + elif options.target_platform == 'Mac': + gyp_file_names.extend(glob.glob('%s/unix/emacs/*.gyp' % SRC_DIR)) elif options.target_platform == 'Linux': gyp_file_names.extend(glob.glob('%s/unix/*/*.gyp' % SRC_DIR)) # Add ibus.gyp if ibus version is >=1.4.1.
'-project', '%s.xcodeproj' % xcode_base_name, '-configuration', options.configuration, '-target', target_name, + '-sdk', 'macosx', '-parallelizeTargets', 'BUILD_WITH_GYP=1'])
build_mozc.py を修正したらコンパイルします。
cd ~/Downloads/mozc/src python build_mozc.py gyp --noqt python build_mozc.py build -c Release mac/mac.gyp:GoogleJapaneseInput mac/mac.gyp:gen_launchd_confs unix/emacs/emacs.gyp:mozc_emacs_helper
error : There is no SDK ** BUILD FAILED **が発生する場合は、build_mozc.py を Mac 用に修正するをやっていない可能性があります。パッチを当ててリトライしましょう。
コンパイルが完了したら、ターミナルから以下を入力し、Mozc をインストールします。
cd ~/Downloads/mozc/src 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
インストールすると、Mac の IME に Mozc を追加できるようになります。
Mozc をインストールしたら、一度ログアウトし、再度ログインします。
ログインしなおしたら、ターミナルを起動し、以下のように入力してみましょう。
cd ~/Downloads/mozc/src echo -e '(0 CreateSession)\n(1 SendKey 1 97)' | out_mac/Release/mozc_emacs_helper
以下のように表示されればOKです。
((mozc-emacs-helper . t)(version . "2.16.2068.101")(config . ((preedit-method . roman)))) ((emacs-event-id . 0)(emacs-session-id . 1)(output . ())) ((emacs-event-id . 1)(emacs-session-id . 1)(output . ((id . "6172380657453702151")(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キーで選択")))(page-size . 9)))(status . ((activated . t)(mode . hiragana)(comeback-mode . hiragana)))(all-candidate-words . ((candidates ((id . 0)(index . 0)(value . "あ")(annotation . ((description . "ひらがな")))))(category . suggestion))))))
以下のように表示された場合は、Mozc のインストールまたはログインし直すをやっていない可能性があります。
((mozc-emacs-helper . t)(version . "2.16.2068.101")(config . ((preedit-method . roman)))) ((emacs-event-id . 0)(emacs-session-id . 1)(output . ())) ((error . session-error)(message . "Session failed"))
動作確認がOKなら、mozc_emacs_helper を /usr/local/bin
にコピーします。
/usr/local/bin
が存在するか確認します。
ls /usr/local git
上記のようにbin
ディレクトリが存在しない場合は、mkdir
で作成しましょう。
sudo mkdir /usr/local/bin
mozc_emacs_helper を /usr/local/bin
にコピーします。
cd ~/Downloads/mozc/src sudo cp out_mac/Release/mozc_emacs_helper /usr/local/bin/mozc_emacs_helper
以上で mozc_emacs_helper のインストールは完了です。
峠は超えました。あと少しです。
最後にSublimeMozcInputをインストールします。
add repo
というように入力し、Package Control: Add Repositoryを選択するinstall pack
というように入力し、Package Control: Install Package を選択するSublimeMozcInput から mozc_emacs_helper を呼び出せるように設定します。
[Preferences]→[Package Settings]→[Mozc Input]→[Settings - User]
{ "mozc_emacs_helper": "/usr/local/bin/mozc_emacs_helper" }
詳細な設定項目は 公式ページ をご参照ください。
以下の手順で、キーバインディングズを変更することが可能です。
ここでは、[alt]+[space]
に割り当てることにします。
[ctrl]+[shift]+[p]
でコマンドパレットを開くkeydef
というように入力し、Preferences: Key Bindings - User
を選択するDefault (Linux).sublime-keymap
が開くので、以下のように追記する
[ { "keys": ["alt+space"], "command": "toggle_mozc" }, ]
SublimeMozcInput のデフォルトは
[space]
が半角スペースで、[shift+space
]が全角スペースです。
この動作は、普段使っているIMEの動作とは反対です。
キーバインディングズに以下を追加することで
[space]
が全角スペースで、[shift+space
]が半角スペースになります。
[ // Zenkaku Space {"keys":[" "], "command":"insert", "args":{"characters":" "}, "context":[{"key":"mozc_mode"}]}, // 上記設定により、入力確定時に全角スペースに置き換わる現象を回避するため {"keys":[" "], "command": "mozc_send_key", "args":{"key": "space"}, "context": [{"key":"mozc_input_mode"}]}, // Hankaku Space {"keys":["shift+space"], "command":"insert", "args":{"characters":" "}, "context":[{"key":"mozc_mode"}]}, // shift を押しながら半角英数字入力中にshift+spaceを押した時に文字が消える現象を回避し、半角スペースが入力されるようにするため {"keys":["shift+space"], "command": "mozc_send_key", "args":{"key": "space"}, "context": [{"key":"mozc_input_mode"}]}, ]
原因は2つ考えられます。
それぞれ、以下のキーバインディングズを設定することで回避することができます。
{"keys": ["shift+enter"], "command": "mozc_send_key", "args": {"key": "enter"}, "context": [{"key": "mozc_input_mode"}]}, {"keys": ["ctrl+enter"], "command": "mozc_send_key", "args": {"key": "enter"}, "context": [{"key": "mozc_input_mode"}]},
SublimeMozcInput のデフォルトキーバインディングズは、 Default.sublime-keymap に記載されています。
この設定をカスタマイズして、Preferences: Key Bindings - User
に追記することで、かなり細かくキーバインディングズを設定することができます。
以下のようなエラーが発生した場合は、 build_mozc.py を Mac 用に修正する を実施するとエラーを回避できます。
lime:src seitaro$ python build_mozc.py build -c Release mac/mac.gyp:GoogleJapaneseInput mac/mac.gyp:gen_launchd_confs unix/emacs/emacs.gyp:mozc_emacs_helper INFO: Running: xcodebuild -project mac/mac.xcodeproj -configuration Release -target GoogleJapaneseInput -parallelizeTargets BUILD_WITH_GYP=1 Build settings from command line: BUILD_WITH_GYP = 1 === BUILD TARGET crash_report_handler OF PROJECT base WITH CONFIGURATION Release === Check dependencies error: There is no SDK with the name or path '/Users/seitaro/Downloads/mozc/src/base/macosx10.8' === BUILD AGGREGATE TARGET gen_mozc_tool_info_plist OF PROJECT gui WITH CONFIGURATION Release === Check dependencies === BUILD AGGREGATE TARGET gen_mozc_tool_info_strings OF PROJECT gui WITH CONFIGURATION Release === Check dependencies === BUILD TARGET protobuf OF PROJECT protobuf WITH CONFIGURATION Release === Check dependencies error: There is no SDK with the name or path '/Users/seitaro/Downloads/mozc/src/base/macosx10.8' ** BUILD FAILED ** The following build commands failed: Check dependencies Check dependencies (2 failures) Traceback (most recent call last): File "build_mozc.py", line 1454, in <module> main() File "build_mozc.py", line 1450, in main procedure[1](cmd_opts, cmd_args, original_directory_name) File "build_mozc.py", line 1068, in BuildMain BuildOnMac(options, targets, original_directory_name) File "build_mozc.py", line 1042, in BuildOnMac 'BUILD_WITH_GYP=1']) File "/Users/seitaro/Downloads/mozc/src/build_tools/util.py", line 99, in RunOrDie '=========='])) build_tools.util.RunOrDieError: ========== ERROR: xcodebuild -project mac/mac.xcodeproj -configuration Release -target GoogleJapaneseInput -parallelizeTargets BUILD_WITH_GYP=1 ========== lime:src seitaro$