[[https://melpa.org/#/sis][file:https://melpa.org/packages/sis-badge.svg]]
[[./README.zh.org][中文版]]
About ~sis~ (smart input source) enables less manual switch for native or OS input source (input method):
A global mode: ~sis-global-respect-mode~ to respect buffer/mode by proper input source
A buffer local mode: ~sis-context-mode~ to switch input source smarted according to context. It also has a global version ~sis-global-context-mode~ to enable the mode for all buffers. When to switch input source according to context can be configured easily by a variable, whose default value indicates when entering ~evil~ insert mode.
A buffer local mode: ~sis-inline-mode~ to enable the automatically triggering of a temporary overlay to input English/other language and then back to original input source without switching input sources manually. It also has a global version ~sis-global-inline-mode~ to enable the mode for all buffers.
A global mode: ~sis-global-cursor-color-mode~ to automatically change cursor color according to current input source.
Features
Install Just install ~sis~ from ~melpa~.
Prepare /input source manager (ISM)/ ** Emacs-native input method Here uses ~rime~ as an example:
(sis-ism-lazyman-config nil "rime" 'native)
** MacOS The default MacOS input sources are shown in the following.
;; Not needed if your input sources are the same with the default values (sis-ism-lazyman-config "com.apple.keylayout.US" "com.sogou.inputmethod.sogou.pinyin")
Note:
*** GUI Emacs Mac Port (EMP) EMP is a Emacs distribution enhanced for MacOS. It has builtin native API to interact with MacOS input sources efficiently. EMP can be installed by the following commands:
brew tap railwaycat/emacsmacport brew install emacs-mac --with-modules --with-rsvg --with-imagemagick --with-natural-title-bar
*** ~macism~ If your Emacs is not GUI EMP, the pre-configured ~macism~ should be installed.
brew tap laishulu/macism brew install macism
Note:
(setq sis-do-set (lambda(source) (start-process "set-input-source" nil "macism" source "50000")))
Some Emacs "distributions" package together a number of Emacs binaries for various macOS versions in a single folder, and dynamically at runtime chooses the right one for your system. This means that the icon you click to start the program is really a "placeholder" that is not Emacs itself, but rather just starts up Emacs. This "placeholder" often takes the form of a Ruby script. If this is the case, you'll need to drag the Ruby program on to the list. Ruby comes with macOS by default. You can find the program by opening Finder, and then from the "Go" menu choose "Go to Folder". Enter "/usr/bin" and you'll get that folder opened in Finder. In the folder, you'll find the ruby program that you can drag on to the Accessibility list.
** Microsoft Windows *** ~w32~ ~Emacs 28+~ in Windows provide APIs to switch imput method directly without emploring external tools. ~sis~ has builtin support for those APIs under the ISM type of ~w32~, which is auto detected and configured. So the follow codes are not required actually.
; (sis-ism-lazyman-config nil t 'w32)
*** ~im-select~ [[https://github.com/daipeihust/im-select][im-select]] can be used as a drop-in replacement of ~macism~ in Microsoft Windows.
(sis-ism-lazyman-config "1033" "2052" 'im-select)
[[./screenshots/windows-im-select.jpg]]
** Linux *** ~fcitx~
(sis-ism-lazyman-config "1" "2" 'fcitx)
*** ~fcitx5~
(sis-ism-lazyman-config "1" "2" 'fcitx5)
*** ~ibus~
(sis-ism-lazyman-config "xkb:us::eng" "OTHER_INPUT_SOURCE" 'ibus)
** Internals for configuring ISM The core of the configuring of ISM is the two variables :
(setq sis-do-get
(setq sis-do-set
They are provided for ~EMP~ and ~macism~ by default.
If you have a ISM ~YOUR_ISM~:
Then you can simply use ~YOUR_ISM~ as a drop in replacement for ~macism~:
(setq sis-external-ism "YOUR_ISM")
You can configure ISM by yourself, but a convenient command ~sis-ism-lazyman-config~ is also provided for common ISMs.
(use-package sis ;; :hook ;; enable the /context/ and /inline region/ mode for specific buffers ;; (((text-mode prog-mode) . sis-context-mode) ;; ((text-mode prog-mode) . sis-inline-mode))
:config ;; For MacOS (sis-ism-lazyman-config
;; English input source may be: "ABC", "US" or another one. ;; "com.apple.keylayout.ABC" "com.apple.keylayout.US"
;; Other language input source: "rime", "sogou" or another one. ;; "im.rime.inputmethod.Squirrel.Rime" "com.sogou.inputmethod.sogou.pinyin")
;; enable the /cursor color/ mode (sis-global-cursor-color-mode t) ;; enable the /respect/ mode (sis-global-respect-mode t) ;; enable the /context/ mode for all buffers (sis-global-context-mode t) ;; enable the /inline english/ mode for all buffers (sis-global-inline-mode t) )
Tips:
** About /inline english mode/
For example final result ~中文 some english text 中文~,
just input ~中文
Note:
| Command Name | Description | |--------------------------+------------------------------------------------------------| | ~sis-ism-lazyman-config~ | Configure input source manager | | ~sis-get~ | Get the input source | | ~sis-set-english~ | Set the input source to English | | ~sis-set-other~ | Set the input source to other language | | ~sis-switch~ | Switch the input source between English and other language | |--------------------------+------------------------------------------------------------|
** About /cursor color mode/ | Variable | Description | Default | |----------------------------+---------------------------------------------+--------------------------| | ~sis-default-cursor-color~ | Default cursor color, also used for English | ~nil~ (from envrionment) | | ~sis-other-cursor-color~ | Cursor color for other input source | ~green~ | |----------------------------+---------------------------------------------+--------------------------|
** About /respect mode/ | Variable | Description | Default | |-------------------------------------------------+--------------------------------------------------------+------------------------| | ~sis-respect-start~ | Switch to specific input source when mode enabled | ~'english~ | | ~sis-respect-evil-normal-escape~ | esc to English even in evil normal state | ~t~ | | ~sis-respect-prefix-and-buffer~ | Handle prefix key and buffer | ~t~ | | ~sis-respect-go-english-triggers~ | Additional trigger to save input source and go English | ~t~ | | ~sis-respect-restore-triggers~ | Additional trigger to restore input source | ~nil~ | | ~sis-respect-minibuffer-triggers~ | Commands trigger to set input source in minibuffer | see variable doc | | ~sis-prefix-override-keys~ | Prefix keys to be respected | ~'("C-c" "C-x" "C-h")~ | | ~sis-prefix-override-recap-triggers~ | Functions trigger the recap of the prefix override | see variable doc | | ~sis-prefix-override-buffer-disable-predicates~ | Predicates on buffers to disable prefix overriding | see variable doc | |-------------------------------------------------+--------------------------------------------------------+------------------------|
** About language pattern | Variable | Description | Default | |-----------------------+--------------------------------------------+--------------------------| | ~sis-english-pattern~ | Pattern to identify a character as English | ~[a-zA-Z]~ | | ~sis-other-pattern~ | Pattern to identify a character as other | ~\cc~ , see [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html][emacs manual]] | | ~sis-blank-pattern~ | Pattern to identify a character as blank | ~[:blank:]~ | |-----------------------+--------------------------------------------+--------------------------|
** About /context mode/ | Variable | Description | Default | |-------------------------------+------------------------------------------------+------------------| | ~sis-context-detectors~ | Detectors to detect the context | see variable doc | | ~sis-context-fixed~ | Context is fixed to a specific language | ~nil~ | | ~sis-context-aggressive-line~ | Aggressively detect context across blank lines | ~t~ | | ~sis-context-hooks~ | Hooks trigger the context following | see variable doc | | ~sis-context-triggers~ | Commands trigger the context following | see variable doc | |-------------------------------+------------------------------------------------+------------------|
** About /inline mode/
| Face Name | Description | Default | |---------------------------------------+------------------------------------------------------------+---------| | ~sis-inline-face~ | Face for the inline region overlay | | | ~sis-inline-not-max-point~ | Insert new line when the whole buffer ends with the region | ~t~ | | ~sis-inline-tighten-head-rule~ | Rule to delete the head spaces | ~'one~ | | ~sis-inline-tighten-tail-rule~ | Rule to delete the tail spaces | ~'one~ | | ~sis-inline-single-space-close~ | 1 space to close the region, default is 2 spaces/return | ~nil~ | | ~sis-inline-with-english~ | enable the ~inline english~ region feature | ~t~ | | ~sis-inline-with-other~ | enable the ~inline other language~ region feature | ~nil~ | | ~sis-inline-english-activated-hook~ | Hook to run after inline english region activated | ~nil~ | | ~sis-inline-english-deactivated-hook~ | Hook to run after inline english region deactivated | ~nil~ | | ~sis-inline-other-activated-hook~ | Hook to run after inline other language region activated | ~nil~ | | ~sis-inline-other-deactivated-hook~ | Hook to run after inline other language region deactivated | ~nil~ | |---------------------------------------+------------------------------------------------------------+---------|
** Inform the package of the input source change
** Auto set /other/ input source for /org capture/ buffer
(add-hook 'org-capture-mode-hook #'sis-set-other)
** Customize my own context detector Customize ~sis-context-detectors~ like the following codes:
(add-to-list 'sis-context-detectors (lambda (&rest _) 'other))
** Auto set input source in /minibuffer/ of a specific command. Customize ~sis-respect-minibuffer-triggers~.
Here is an example to automatically switch to /other/ input resource in /minibuffer/ of command:
(add-to-list 'sis-respect-minibuffer-triggers (cons 'org-roam-node-find (lambda () 'other)))