Emacsでmigemo(cmigemo)がうまく動作して・やっと動いたよ！

# Emacsでmigemo(cmigemo)がうまく動作してくれない

軽く疲労困憊です。
ようやく動作してくれたのでご報告を。

## 環境

macOS Catalina 10.15.7
cmigemo HEAD version cmigemo - C/Migemo Library 1.3 Driver これでいいのか？
GNU Emacs 27.2 railwaycat/emacsmacport/emacs-mac: stable emacs-27.2-mac-8.3, HEAD

おまけで、点いたり消えたりして強制的に休憩を押し付けてくるストレス高いディスプレイGW2255
このディスプレイが一番私の精神を削った

## 環境ログ

```bash:cmigemo
$ brew info cmigemo
cmigemo: stable 20110227 (bottled), HEAD
Migemo is a tool that supports Japanese incremental search with Romaji
https://www.kaoriya.net/software/cmigemo
/usr/local/Cellar/cmigemo/HEAD-9a1cec4 (24 files, 11.7MB) *
  Built from source on 2022-02-13 at 19:09:36
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/cmigemo.rb
License: MIT
==> Dependencies
Build: nkf ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
See also https://github.com/emacs-jp/migemo to use cmigemo with Emacs.
You will have to save as migemo.el and put it in your load-path.
==> Analytics
install: 58 (30 days), 226 (90 days), 714 (365 days)
install-on-request: 58 (30 days), 226 (90 days), 712 (365 days)
build-error: 0 (30 days)
FireZone ~/.emacs.d$
```

```bash:emacs
$ brew info emacs-mac
Warning: Treating emacs-mac as a formula. For the cask, use railwaycat/emacsmacport/emacs-mac
railwaycat/emacsmacport/emacs-mac: stable emacs-27.2-mac-8.3, HEAD
YAMAMOTO Mitsuharu's Mac port of GNU Emacs
https://www.gnu.org/software/emacs/
/usr/local/Cellar/emacs-mac/emacs-27.2-mac-8.3 (4,056 files, 123.7MB) *
  Built from source on 2022-01-31 at 19:51:40 with: --with-modern-icon
From: https://github.com/railwaycat/homebrew-emacsmacport/blob/HEAD/Formula/emacs-mac.rb
==> Dependencies
Required: autoconf ✔, automake ✔, gnutls ✔, pkg-config ✔, texinfo ✔
Recommended: jansson ✔, libxml2 ✔
Optional: glib ✔, imagemagick ✔
==> Options
--with-ctags
	Don't remove the ctags executable that emacs provides
--with-dbus
	Build with d-bus support
--with-emacs-big-sur-icon
	Using Emacs icon: emacs-big-sur-icon
--with-emacs-icons-project-EmacsIcon1
	Using Emacs icon: emacs-icons-project-EmacsIcon1
--with-emacs-icons-project-EmacsIcon2
	Using Emacs icon: emacs-icons-project-EmacsIcon2
--with-emacs-icons-project-EmacsIcon3
	Using Emacs icon: emacs-icons-project-EmacsIcon3
--with-emacs-icons-project-EmacsIcon4
	Using Emacs icon: emacs-icons-project-EmacsIcon4
--with-emacs-icons-project-EmacsIcon5
	Using Emacs icon: emacs-icons-project-EmacsIcon5
--with-emacs-icons-project-EmacsIcon6
	Using Emacs icon: emacs-icons-project-EmacsIcon6
--with-emacs-icons-project-EmacsIcon7
	Using Emacs icon: emacs-icons-project-EmacsIcon7
--with-emacs-icons-project-EmacsIcon8
	Using Emacs icon: emacs-icons-project-EmacsIcon8
--with-emacs-icons-project-EmacsIcon9
	Using Emacs icon: emacs-icons-project-EmacsIcon9
--with-emacs-icons-project-emacs-card-blue-deep
	Using Emacs icon: emacs-icons-project-emacs-card-blue-deep
--with-emacs-icons-project-emacs-card-british-racing-green
	Using Emacs icon: emacs-icons-project-emacs-card-british-racing-green
--with-emacs-icons-project-emacs-card-carmine
	Using Emacs icon: emacs-icons-project-emacs-card-carmine
--with-emacs-icons-project-emacs-card-green
	Using Emacs icon: emacs-icons-project-emacs-card-green
--with-emacs-sexy-icon
	Using Emacs icon: emacs-sexy-icon
--with-glib
	Build with glib support
--with-gnu-head-icon
	Using Emacs icon: gnu-head-icon
--with-imagemagick
	Build with imagemagick support
--with-mac-metal
	use Metal framework in application-side double buffering (experimental)
--with-modern-icon
	Using Emacs icon: modern-icon
--with-native-comp
	Build with native compilation (only with --HEAD, experimental, check issue #274 before installation)
--with-natural-title-bar
	Build with a patch for title bar color inferred by theme (not recommended to use with --HEAD option)
--with-no-title-bars
	Build with a patch for no title bars on frames (not recommended to use with --HEAD option)
--with-retro-sink-bw
	Using Emacs icon: retro-sink-bw
--with-rsvg
	Build with rsvg support
--with-sjrmanning-icon
	Using Emacs icon: sjrmanning-icon
--with-spacemacs-icon
	Using Emacs icon: spacemacs-icon
--with-starter
	Build with a starter script to start emacs GUI from CLI
--without-jansson
	Build without jansson support
--without-libxml2
	Build without libxml2 support
--without-modules
	Build without dynamic modules support
--HEAD
	Install HEAD version
==> Caveats
This is YAMAMOTO Mitsuharu's "Mac port" addition to
GNU Emacs 27. This provides a native GUI support for Mac OS X
10.6 - 12. After installing, see README-mac and NEWS-mac
in /usr/local/opt/emacs-mac for the port details.

Emacs.app was installed to:
  /usr/local/opt/emacs-mac

To link the application to default Homebrew App location:
  ln -s /usr/local/opt/emacs-mac/Emacs.app /Applications
Other ways please refer:
  https://github.com/railwaycat/homebrew-emacsmacport/wiki/Alternative-way-of-place-Emacs.app-to-Applications-directory

If you are using Doom Emacs, be sure to run doom sync:
  ~/.emacs.d/bin/doom sync

For an Emacs.app CLI starter, see:
  https://gist.github.com/4043945

Emacs mac port also available on MacPorts with name "emacs-mac-app" and "emacs-mac-app-devel", but they are not maintained by the maintainer of this formula.
FireZone ~/.emacs.d$
```

## やったこと

とにかく色々やった。何が正しいか原因の追求なんて気にせず色々やった。

### 内容

1. cmigemoをHEADから持ってきてビルドした
1. ターミナルからcmigemo環境が動くか確認した
1. init.el内容を１行づつ順番に有効にしていった

これ正常に動いているからね

```bash:ターミナルからcmigemo環境が動くか確認した
FireZone ~$ cmigemo -d /usr/local/Cellar/cmigemo/HEAD-9a1cec4/share/migemo/utf-8/migemo-dict -e
migemo_open("/usr/local/Cellar/cmigemo/HEAD-9a1cec4/share/migemo/utf-8/migemo-dict")=0x7fb6ed405b40
clock()=0.129864
QUERY: tamokutekikurenza-
PATTERN: \(ﾀ\s-*ﾓ\s-*ｸ\s-*ﾃ\s-*ｷ\s-*ｸ\s-*ﾚ\s-*ﾝ\s-*ｻ\s-*ﾞ\s-*ｰ\|タ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*イ\s-*イ\s-*チ\s-*ニ\s-*チ\s-*ブ\s-*ン\s-*オ\s-*フ\s-*ル\s-*ー\s-*ツ\|や\s-*さ\s-*い\s-*い\s-*ち\s-*に\s-*ち\s-*ぶ\s-*ん\s-*お\s-*ふ\s-*る\s-*ー\s-*つ\|ｙ\s-*ａ\s-*ｓ\s-*ａ\s-*ｉ\s-*ｉ\s-*ｃ\s-*ｈ\s-*ｉ\s-*ｎ\s-*ｉ\s-*ｃ\s-*ｈ\s-*ｉ\s-*ｂ\s-*ｕ\s-*ｎ\s-*ｎ\s-*ｏ\s-*ｆ\s-*ｕ\s-*ｒ\s-*ｕ\s-*−\s-*ｔ\s-*ｕ\|y\s-*a\s-*s\s-*a\s-*i\s-*i\s-*c\s-*h\s-*i\s-*n\s-*i\s-*c\s-*h\s-*i\s-*b\s-*u\s-*n\s-*n\s-*o\s-*f\s-*u\s-*r\s-*u\s-*-\s-*t\s-*u\)
oyasai
\(ｵ\s-*ﾔ\s-*ｻ\s-*ｲ\|オ\s-*ヤ\s-*サ\s-*イ\|お\s-*や\s-*さ\s-*い\|ｏ\s-*ｙ\s-*ａ\s-*ｓ\s-*ａ\s-*ｉ\|o\s-*y\s-*a\s-*s\s-*a\s-*i\)
yasai
\(ﾔ\s-*ｻ\s-*ｲ\|ヤ\s-*サ\s-*イ\|野\s-*菜\|や\s-*さ\s-*い\|ｙ\s-*ａ\s-*ｓ\s-*ａ\s-*ｉ\|y\s-*a\s-*s\s-*a\s-*i\)
shibui
\(ｼ\s-*ﾌ\s-*ﾞ\s-*ｲ\|シ\s-*ブ\s-*イ\|四\s-*分\s-*一\|渋\s-*井\|し\s-*ぶ\s-*い\|ｓ\s-*ｈ\s-*ｉ\s-*ｂ\s-*ｕ\s-*ｉ\|s\s-*h\s-*i\s-*b\s-*u\s-*i\)
^C
FireZone ~$
```

これは失敗パターン。辞書ファイル名まで指定しないと失敗する。

```bash:ターミナルからcmigemo環境が動くか確認した
FireZone ~$ cmigemo -d /usr/local/Cellar/cmigemo/HEAD-9a1cec4/share/migemo/utf-8 -e
^C
FireZone ~$ cmigemo -d /usr/local/Cellar/cmigemo/HEAD-9a1cec4/share/migemo/utf-8/ -e
^C
FireZone ~$ cmigemo -d /usr/local/Cellar/cmigemo/HEAD-9a1cec4/share/migemo/utf-8/ -e
aa
b
^C
FireZone ~$
```

## init.el -- migemo

```emacs-lisp:init.el 抜粋
(leaf migemo
  :doc "Japanese incremental search through dynamic pattern expansion"
  :url "https://github.com/emacs-jp/migemo"
  :el-get emacs-jp/migemo
  ;; :commands migemo-init
  :custom
  (migemo-command . "/usr/local/bin/cmigemo")
  (migemo-options . '("-q" "--emacs"))
  (migemo-dictionary . "/usr/local/Cellar/cmigemo/HEAD-9a1cec4/share/migemo/utf-8/migemo-dict")
  (migemo-user-dictionary . nil)
  (migemo-regex-dictionary . nil)
  (migemo-coding-system 'utf-8-unix)
  (migemo-use-pattern-alist . t)
  (migemo-use-frequent-pattern-alist . t)
  (migemo-pattern-alist-length . 1024)
  :config
  (load-library "migemo")
  (migemo-init)
  )
```

辞書指定ではファイル名まで書かないとCPU99%になりEmacsがフリーズします。
C-g 連打とプロセス着るで活発に動くミゲちゃんがいなくなったら、画面が無反応でもC-x C-cで終了出来ると思う。

## 非常に軽快に動いてますわー

はっはっは

init.el を全面改装ついでにleafパッケージ管理に切り替えたのがまずかった。
書き方も手探りで、余裕がなかったんだよ。
今になってウェブ検索すると、このまま記載すれば何の問題もなく動いたんじゃないかと思った。
そりゃ、まー、正解を知ってから検索すりゃ、正解してるサイトばかり見つかるのは道理なんですけど。
というか、これと同じ設定でも試してはいたはずなんだよ。コピペして使ってたはずですし。
やめて！これ以上、ぼくをいじめないで！って気分はナウシカ。

ありがたやありがたや

+ Cygwin の Emacs で migemo を使うには | ゴルディアスの涙目 https://gordiustears.net/migemo-on-cygwin-emacs/
+ Emacs の設定 | Youhei SASAKI’s official site https://uwabami.github.io/cc-env/Emacs.html
+ 【Emacs/macOS】migemoを有効にし、ローマ字のまま日本語検索する | The modern stone age. https://www.yokoweb.net/2017/03/05/emacs-macos-migemo/