Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
emacs with mozc on macos sierra

Setup emacs

Install emacs or emacs-plus and prerequisite software by brew

$ brew install emacs
$ brew install ninja

download mozc

$ git clone https://github.com/google/mozc.git -b master --single-branch --recursive
$ cd mozc && git show HASH
f5dcadf0dee0382612398965adc2c110ef027d9c
$

Modify source code to compile for macOS sierra

$ git diff
diff --git a/src/build_mozc.py b/src/build_mozc.py
index a56aaaf..d419f49 100644
--- a/src/build_mozc.py
+++ b/src/build_mozc.py
@@ -167,6 +167,8 @@ def GetGypFileNames(options):
   # 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.
diff --git a/src/mac/mac.gyp b/src/mac/mac.gyp
index 76b540d..2ee4006 100644
--- a/src/mac/mac.gyp
+++ b/src/mac/mac.gyp
@@ -586,7 +586,6 @@
             ['branding=="GoogleJapaneseInput"', {
               'dependencies': [
                 'DevConfirmPane',
-                'codesign_client',
               ],
             }],
           ],
           

Compile

$ cd src
$ GYP_DEFINES="mac_sdk=10.12 mac_deployment_target=10.12" python build_mozc.py gyp --noqt --branding=GoogleJapaneseInput
$ python build_mozc.py build -c Release unix/emacs/emacs.gyp:mozc_emacs_helper

confirm whether the mozc program is successfully compiled

$ echo -e '(0 CreateSession)\n(1 SendKey 1 hiragana)\n(2 SendKey 1 hiragana)\n(3 SendKey 1 97)' | out_mac/Release/mozc_emacs_helper
((mozc-emacs-helper . t)(version . "2.19.2643.101")(config . ((preedit-method . roman))))
((emacs-event-id . 0)(emacs-session-id . 1)(output . ()))
((emacs-event-id . 1)(emacs-session-id . 1)(output . ((id . "4087100232139049092")(mode . hiragana)(consumed . nil)(key . ((special-key . kana)))(status . ((activated . t)(mode . hiragana)(comeback-mode . hiragana))))))
((emacs-event-id . 2)(emacs-session-id . 1)(output . ((id . "4087100232139049092")(mode . hiragana)(consumed . nil)(key . ((special-key . kana)))(status . ((activated . t)(mode . hiragana)(comeback-mode . hiragana))))))

Install the program

$ sudo cp out_mac/Release/mozc_emacs_helper /usr/local/bin

Configure your emacs init.el

Copy the following emacs lisp file to your library path

$ cp mozc/src/unix/emacs/mozc.el "YOUR EMACS ELISP PATH"

Add the following code to your emacs init.el

  (require 'mozc)
  (setq default-input-method "japanese-mozc")

Check whether your configuration works or not

In emacs, you may change input method by C-. You can input Japanese if you success the installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment