For a long time I’d been using railwaycat/homebrew-emacsmacport , a build of Emacs with the Mac port patches applied.
Why I Switched to the NS Build
Over the past few years, though, I’d been feeling the following pain points.
- The Mac port hasn’t kept up with the latest Emacs
- The current latest Emacs is 30.2, but the Mac port only supports 29.4
- With the latest railwaycat/homebrew-emacsmacport release, emacs-29.4-mac-10.1 , I ran into the problem in issue #389 on my setup, so I’d been sticking with the previous emacs-29.1-mac-10.0
- Ideally, I’d like to use the latest Emacs
The only reason I used the Mac port build in the first place was to automatically turn off Japanese input when I hit M-x and the like, then restore it to its original state afterward. Here’s the configuration
.
As long as I could reproduce this behavior, I’d be able to switch to the standard NS build. This time, that finally happened.
By the way, NS stands for NeXTSTEP, which on macOS refers to the GUI build that uses Cocoa (AppKit).
I Found That sis Could Solve It
After looking into it, I found that emacs-smart-input-source (hereafter “sis”) could reproduce what I’d been doing with the Mac port build.
On macOS, sis uses a CLI called macism as the backend for switching input sources. It’s by @laishulu , the same author as sis.
Installing the NS Build of Emacs
First, I installed the build from emacsformacosx.com via Homebrew.
$ brew install --cask emacs-app
Configuring sis Solved It
Installing macism
I installed macism via Homebrew.
$ brew install laishulu/homebrew/macism
macism can switch input sources from the command line on its own, like this.
# Set the input source to "ABC"
$ macism com.apple.keylayout.ABC
# Set the input source to Google Japanese Input's "あ"
$ macism com.google.inputmethod.Japanese.base
Configuring sis
This is all I configured.
;; When moving the cursor to the minibuffer, automatically switch to English mode,
;; and restore the Japanese input state after returning to the original buffer.
(sis-ism-lazyman-config
"com.apple.keylayout.ABC" ;; ABC
"com.google.inputmethod.Japanese.base") ;; Google Japanese Input
(sis-global-respect-mode 1)
;; Switch the cursor color to match the input mode.
(sis-global-cursor-color-mode 1)
sis-global-respect-mode switches to English input when you move to the minibuffer with M-x and the like, and restores the Japanese input state when you return to the original buffer. This is exactly what I’d been doing with the Mac port build.
With that, sis solved it without any issues, and I successfully switched to the standard NS build.
Conclusion
I was able to switch from the Mac port build I’d used for years to the standard NS build. I’m glad I could solve the input source switching on M-x, which was my one and biggest pain point.
Compared to the Mac port build, there’s nothing in particular that feels inconvenient.
I can now keep up with the latest Emacs. Emacs 30 feels faster when it comes to networking. You can really tell when using navi2ch (!).
I hope this helps someone.
Related
Appendix
Switching Input Sources by Context with sis-global-context-mode
sis also has sis-global-context-mode, which looks at the characters around the cursor (the context) and switches the input source automatically.
(sis-global-context-mode 1)
For example, when you “write Japanese → edit somewhere else → return to the original spot and keep writing,” it switches to Japanese input if you land mid-Japanese, or to English if you land mid-English. It determines whether the characters before and after the cursor are Japanese or English, and only switches when it can make that determination, so there are few false triggers.
That said, the default for sis-context-hooks, which decides when it fires, is '(evil-insert-state-entry-hook), which assumes evil
. If you don’t use evil, this hook never gets called and it won’t work, so you’ll need to add hooks that match your own workflow.
If sis-global-respect-mode (switching to English on M-x and back) is enough for you, I don’t think you need to force this one on.
Mixing English Words into Japanese with sis-global-inline-mode
sis also has sis-global-inline-mode, which is handy when you want to mix English words into the middle of Japanese text.
(sis-global-inline-mode 1)
For example, when you want to write 日本語 some english text 日本語, you just type 日本語<space>some english text<space><RET>日本語. The moment you put a space right after the Japanese, it automatically switches to English input just for that spot (highlighted with an overlay), and a trailing space, RET, or moving the cursor outside the region returns you to Japanese input. There’s no need to switch the IME manually.
By default, only “English within Japanese” is handled (sis-inline-with-english). If you also want “Japanese within English,” add (setq sis-inline-with-other t).
Whereas sis-global-respect-mode / sis-global-context-mode handle “switching” the input source, this one creates a temporary English region on the spot — that’s the difference.
I tried it for a day, but of course this behavior only applies inside Emacs, so character input behaves differently between Emacs and everything else. That subtle inconsistency was disorienting, so I stopped using it. Another reason is that even within Emacs, it didn’t turn out to be all that intuitive.