{"id":13570989,"url":"https://github.com/laishulu/emacs-smart-input-source","last_synced_at":"2025-04-04T07:32:37.847Z","repository":{"id":40505977,"uuid":"251196602","full_name":"laishulu/emacs-smart-input-source","owner":"laishulu","description":"Less manual switch for native or OS input source (input method).","archived":false,"fork":false,"pushed_at":"2023-12-11T16:02:30.000Z","size":6710,"stargazers_count":251,"open_issues_count":13,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-05T03:36:58.519Z","etag":null,"topics":["emacs","evil","fcitx","input-method","linux","macos","windows"],"latest_commit_sha":null,"homepage":"","language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laishulu.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-30T03:57:22.000Z","updated_at":"2024-10-27T14:29:24.000Z","dependencies_parsed_at":"2024-01-14T03:50:29.393Z","dependency_job_id":"1b7d5290-60e2-492e-ad96-fbf789ee385c","html_url":"https://github.com/laishulu/emacs-smart-input-source","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laishulu%2Femacs-smart-input-source","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laishulu%2Femacs-smart-input-source/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laishulu%2Femacs-smart-input-source/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laishulu%2Femacs-smart-input-source/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laishulu","download_url":"https://codeload.github.com/laishulu/emacs-smart-input-source/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247139270,"owners_count":20890196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["emacs","evil","fcitx","input-method","linux","macos","windows"],"created_at":"2024-08-01T14:00:57.280Z","updated_at":"2025-04-04T07:32:32.831Z","avatar_url":"https://github.com/laishulu.png","language":"Emacs Lisp","funding_links":[],"categories":["Emacs Lisp"],"sub_categories":[],"readme":"#+TITLE: README\n[[https://melpa.org/#/sis][file:https://melpa.org/packages/sis-badge.svg]]\n\n* About\n~sis~ (smart input source) enables less manual switch for native or OS input\nsource (input method):\n\n- A global mode: ~sis-global-respect-mode~ to respect buffer/mode\n  by proper input source\n  1. Respect start: start Emacs with specified language.\n  2. Respect ~evil~: switch to English when leaving ~evil~ ~insert~ mode.\n  3. Respect ~minibuffer~: switch to English when enter ~minibuffer~.\n  4. Respect prefix key: switch to English for ~C-c~ / ~C-x~ / ~C-h~ and more.\n  5. Respect buffer: recover buffer input source when it regain focus.\n- A buffer local mode: ~sis-context-mode~ to switch input source smarted\n  according to context. It also has a global version ~sis-global-context-mode~\n  to enable the mode for all buffers. When to switch input source according to\n  context can be configured easily by a variable, whose default value\n  indicates when entering evil insert mode.\n- A buffer local mode: ~sis-inline-mode~ to enable the\n  automatically triggering of a temporary overlay to input English/other\n  language and then back to original input source without switching input\n  sources manually. It also has a global version\n  ~sis-global-inline-mode~ to enable the mode for all buffers.\n- A global mode: ~sis-global-cursor-color-mode~ to automatically\n  change cursor color according to current input source.\n\n* Features\n1. Ease the use of OS-native input source, no need to change use experience.\n2. Ease the use of Emacs-native input source, for further compatibility.\n3. Support GUI Emacs, as well as Terminal Emacs.\n4. Easy to install and configure. No further configuration for\n   ~GUI Emacs Mac Port~ with ~Sogou Input~.\n5. Automatically change cursor color according to current input source.\n6. Respect buffer/mode by proper input source:\n   1) Respect start: start Emacs with specified language.\n   2) Respect ~evil~: switch to English when leaving ~evil~ ~insert~ mode.\n   3) Respect ~minibuffer~: switch to English when enter ~minibuffer~.\n   4) Respect prefix key: switch to English for ~C-c~ / ~C-x~ / ~C-h~ and more.\n   5) Respect buffer: recover buffer input source when it regain focus.\n7. Support ~inline English~ and ~inline other language~ region. Features of the\n   inline region (~inline english~ as an example):\n   1) Inserting space around none-English characters triggers the region (two\n      consecutive spaces for ~inline other language~ region).\n   2) In this mode, English will be sticked.\n   3) Region is closed when:\n      a. Cursor leaves the region\n      b. ~Return~ is pressed.\n      c. Two consecutive ~space~ are input (can be configured to one ~space~).\n   4) If the region ends with space, none-English input source will be\n      selected, otherwise English input source is retained.\n   5) After the close of the region, one space (can be configured) in the head\n      and tail respectively (if exists) of the region will be deleted. But if\n      the whole region is blank, the no character will be deleted.\n8. Switch input source according to context:\n   1) Pre-configured for entering evil insert mode.\n   2) For native emacs user, you can configure by easily set a variable.\n9. Input source switching rules are designed carefully, for pure English\n   editing, input source will never be switched to other languages.\n\n* Install\nJust install ~sis~ from ~melpa~.\n\n* Prepare /input source manager (ISM)/\n** Emacs-native input method\nHere uses ~rime~ as an example:\n#+BEGIN_SRC lisp\n(sis-ism-lazyman-config nil \"rime\" 'native)\n#+END_SRC\n\n\n** MacOS\nThe default MacOS input sources are shown in the following.\n#+BEGIN_SRC lisp\n;; Not needed if your input sources are the same with the default values\n(sis-ism-lazyman-config\n \"com.apple.keylayout.US\"\n \"com.sogou.inputmethod.sogou.pinyin\")\n#+END_SRC\n\nNote:\n1. Your English input source *MAY NOT* be the default one. Use command\n   ~sis-get~ in Emacs to get the correct one.\n2. According to your use case, ~EMP~ or ~macism~ should be installed.\n\n*** GUI Emacs Mac Port (EMP)\nEMP is a Emacs distribution enhanced for MacOS. It has builtin native API to\ninteract with MacOS input sources efficiently. EMP can be installed by the\nfollowing commands:\n#+BEGIN_SRC bash\nbrew tap railwaycat/emacsmacport\nbrew install emacs-mac --with-modules --with-rsvg --with-imagemagick --with-natural-title-bar\n#+END_SRC\n\n*** ~macism~\nIf your Emacs is not GUI EMP, the pre-configured ~macism~ should be installed.\n#+BEGIN_SRC bash\nbrew tap laishulu/macism\nbrew install macism\n#+END_SRC\nNote:\n- The first time when you use ~macism SOME_INPUT_SOURCE_ID~ in your app,\n  MacOS will popup a window asking you to grant permission of Accessibility, you\n  can also grant the permission manually following the instructions in [[https://github.com/laishulu/macism/][macism]].\n- On a slow computer, ~macism~ needs sleep time (in micro seconds) longer than\n  default to work with Accessibility. The default can be overwritten by the\n  following codes.\n  #+BEGIN_SRC lisp\n(setq sis-do-set\n      (lambda(source) (start-process \"set-input-source\" nil \"macism\" source \"50000\")))\n  #+END_SRC\n- Don't use ~Alacritty~ for TUI Emacs, because it can't handle deleting\n  as well as ~Option~ and ~Command~ key properly when input method is on. I just\n  recommend ~kitty~ until ~Alacirtty~ fixed those long existing bugs.\n- If you have problems on granting permission of Accessibility for Emacs, see\n  below:\n  #+BEGIN_QUOTE\n  Some Emacs \"distributions\" package together a number of Emacs binaries for\n  various macOS versions in a single folder, and dynamically at runtime chooses\n  the right one for your system. This means that the icon you click to start the\n  program is really a \"placeholder\" that is not Emacs itself, but rather just\n  starts up Emacs. This \"placeholder\" often takes the form of a Ruby script. If\n  this is the case, you'll need to drag the Ruby program on to the list. Ruby\n  comes with macOS by default. You can find the program by opening Finder, and\n  then from the \"Go\" menu choose \"Go to Folder\". Enter \"/usr/bin\" and you'll get\n  that folder opened in Finder. In the folder, you'll find the ruby program that\n  you can drag on to the Accessibility list.\n  #+END_QUOTE\n\n** Microsoft Windows\n*** ~w32~\n~Emacs 28+~ in Windows provide APIs to switch imput method directly without\nemploring external tools. ~sis~ has builtin support for those APIs under the ISM\ntype of ~w32~, which is auto detected and configured. So the follow codes are\nnot required actually.\n#+BEGIN_SRC lisp\n(sis-ism-lazyman-config nil t 'w32)\n#+END_SRC\n\n*** ~im-select~\n[[https://github.com/daipeihust/im-select][im-select]] can be used as a drop-in replacement of ~macism~ in Microsoft Windows.\n#+BEGIN_SRC lisp\n(sis-ism-lazyman-config \"1033\" \"2052\" 'im-select)\n#+END_SRC\n\n1. Even though ~im-select~ supports switching different input languages, it does\n   not support multiple input methods in the same lanuage, thus you should\n   ensure that in each input language there is only one input method, just like\n   the following screenshot.\n   #+CAPTION: Smart input source\n   [[./screenshots/windows-im-select.jpg]]\n2. If you are using ~win~ key as ~super~ key, you may also need [[https://github.com/laishulu/winsuper][winsuper]].\n\n** Linux\n*** ~fcitx~\n#+BEGIN_SRC lisp\n(sis-ism-lazyman-config \"1\" \"2\" 'fcitx)\n#+END_SRC\n\n*** ~fcitx5~\n#+BEGIN_SRC lisp\n(sis-ism-lazyman-config \"1\" \"2\" 'fcitx5)\n#+END_SRC\n\n*** ~ibus~\n#+BEGIN_SRC lisp\n(sis-ism-lazyman-config \"xkb:us::eng\" \"OTHER_INPUT_SOURCE\" 'ibus)\n#+END_SRC\n\n** Internals for configuring ISM\nThe core of the configuring of ISM is the two variables :\n#+BEGIN_SRC lisp\n(setq sis-do-get\n      #'YOUR_DO_GET_INPUT_SOURCE_FUNCTION)\n(setq sis-do-set\n      #'YOUR_DO_SET_INPUT_SOURCE_FUNCTION)\n#+END_SRC\n\nThey are provided for ~EMP~ and ~macism~ by default.\n\nIf you have a ISM ~YOUR_ISM~:\n+ Run ~YOUR_ISM~ will output the current input source\n+ Run ~YOUR_ISM INPUT_SOURCE_ID~ will select ~INPUT_SOURCE_ID~.\n\nThen you can simply use ~YOUR_ISM~ as a drop in replacement for ~macism~:\n#+BEGIN_SRC lisp\n(setq sis-external-ism \"YOUR_ISM\")\n#+END_SRC\n\nYou can configure ISM by yourself, but a convenient command\n~sis-ism-lazyman-config~ is also provided for common ISMs.\n\n* Configure\nThe mode is designed carefully, so it's safe to enable for all buffers even\nits all in English.\n\n#+BEGIN_SRC lisp\n(use-package sis\n  ;; :hook\n  ;; enable the /context/ and /inline region/ mode for specific buffers\n  ;; (((text-mode prog-mode) . sis-context-mode)\n  ;;  ((text-mode prog-mode) . sis-inline-mode))\n\n  :config\n  ;; For MacOS\n  (sis-ism-lazyman-config\n\n   ;; English input source may be: \"ABC\", \"US\" or another one.\n   ;; \"com.apple.keylayout.ABC\"\n   \"com.apple.keylayout.US\"\n\n   ;; Other language input source: \"rime\", \"sogou\" or another one.\n   ;; \"im.rime.inputmethod.Squirrel.Rime\"\n   \"com.sogou.inputmethod.sogou.pinyin\")\n\n  ;; enable the /cursor color/ mode\n  (sis-global-cursor-color-mode t)\n  ;; enable the /respect/ mode\n  (sis-global-respect-mode t)\n  ;; enable the /context/ mode for all buffers\n  (sis-global-context-mode t)\n  ;; enable the /inline english/ mode for all buffers\n  (sis-global-inline-mode t)\n  )\n#+END_SRC\n\nTips:\n1. For ~spacemacs~, if it works in the ~hybrid~ mode, some of the ~evil~ related\n   features may not work. Change to ~vim~ mode instead.\n\n**  About /inline english mode/\n\nFor example final result ~中文 some english text 中文~,\njust input ~中文\u003cspc\u003esome english text\u003cspc\u003e\u003cRET\u003e中文~, and no need to switch\nISM manually.\n\n* Variables and commands\n** About input source\n| Variable                   | Description                                        | Default                              |\n|----------------------------+----------------------------------------------------+--------------------------------------|\n| ~sis-english-source~       | Input source for English                           | ~com.apple.keylayout.US~             |\n| ~sis-other-source~         | Input source for other language                    | ~com.sogou.inputmethod.sogou.pinyin~ |\n| ~sis-external-ism~         | External input resource manager                    | ~macism~                             |\n| ~sis-do-get~               | Function to get the current input source           | determined from the environment      |\n| ~sis-do-set~               | Function to set the input source                   | determined from the environment      |\n| ~sis-change-hook~          | Hook to run after input source changes             | ~nil~                                |\n| ~sis-auto-refresh-seconds~ | Idle interval to auto refresh input source from OS | ~0.2~, ~nil~ to disable              |\n|----------------------------+----------------------------------------------------+--------------------------------------|\n\nNote:\n- To save energy, actual interval to refresh input source from OS in a long idle\n  period is increased automatically.\n\n| Command Name             | Description                                                |\n|--------------------------+------------------------------------------------------------|\n| ~sis-ism-lazyman-config~ | Configure input source manager                             |\n| ~sis-get~                | Get the input source                                       |\n| ~sis-set-english~        | Set the input source to English                            |\n| ~sis-set-other~          | Set the input source to other language                     |\n| ~sis-switch~             | Switch the input source between English and other language |\n|--------------------------+------------------------------------------------------------|\n\n** About /cursor color mode/\n| Variable                   | Description                                 | Default                  |\n|----------------------------+---------------------------------------------+--------------------------|\n| ~sis-default-cursor-color~ | Default cursor color, also used for English | ~nil~ (from envrionment) |\n| ~sis-other-cursor-color~   | Cursor color for other input source         | ~green~                  |\n|----------------------------+---------------------------------------------+--------------------------|\n\n** About /respect mode/\n| Variable                                        | Description                                            | Default                |\n|-------------------------------------------------+--------------------------------------------------------+------------------------|\n| ~sis-respect-start~                             | Switch to specific input source when mode enabled      | ~'english~             |\n| ~sis-respect-evil-normal-escape~                | esc to English even in evil normal state               | ~t~                    |\n| ~sis-respect-prefix-and-buffer~                 | Handle prefix key and buffer                           | ~t~                    |\n| ~sis-respect-go-english-triggers~               | Additional trigger to save input source and go English | ~t~                    |\n| ~sis-respect-restore-triggers~                  | Additional trigger to restore input source             | ~nil~                  |\n| ~sis-respect-minibuffer-triggers~               | Commands trigger to set input source in minibuffer     | see variable doc       |\n| ~sis-prefix-override-keys~                      | Prefix keys to be respected                            | ~'(\"C-c\" \"C-x\" \"C-h\")~ |\n| ~sis-prefix-override-recap-triggers~            | Functions trigger the recap of the prefix override     | see variable doc       |\n| ~sis-prefix-override-buffer-disable-predicates~ | Predicates on buffers to disable prefix overriding     | see variable doc       |\n|-------------------------------------------------+--------------------------------------------------------+------------------------|\n\n** About language pattern\n| Variable              | Description                                | Default                  |\n|-----------------------+--------------------------------------------+--------------------------|\n| ~sis-english-pattern~ | Pattern to identify a character as English | ~[a-zA-Z]~               |\n| ~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]] |\n| ~sis-blank-pattern~   | Pattern to identify a character as blank   | ~[:blank:]~              |\n|-----------------------+--------------------------------------------+--------------------------|\n\n** About /context mode/\n| Variable                      | Description                                    | Default          |\n|-------------------------------+------------------------------------------------+------------------|\n| ~sis-context-detectors~       | Detectors to detect the context                | see variable doc |\n| ~sis-context-fixed~           | Context is fixed to a specific language        | ~nil~            |\n| ~sis-context-aggressive-line~ | Aggressively detect context across blank lines | ~t~              |\n| ~sis-context-hooks~           | Hooks trigger the context following            | see variable doc |\n| ~sis-context-triggers~        | Commands trigger the context following         | see variable doc |\n|-------------------------------+------------------------------------------------+------------------|\n\n** About /inline mode/\n\n| Face Name                             | Description                                                | Default |\n|---------------------------------------+------------------------------------------------------------+---------|\n| ~sis-inline-face~                     | Face for the inline region overlay                         |         |\n| ~sis-inline-not-max-point~            | Insert new line when the whole buffer ends with the region | ~t~     |\n| ~sis-inline-tighten-head-rule~        | Rule to delete the head spaces                             | ~'one~  |\n| ~sis-inline-tighten-tail-rule~        | Rule to delete the tail spaces                             | ~'one~  |\n| ~sis-inline-single-space-close~       | 1 space to close the region, default is 2 spaces/return    | ~nil~   |\n| ~sis-inline-with-english~             | enable the ~inline english~ region feature                 | ~t~     |\n| ~sis-inline-with-other~               | enable the ~inline other language~ region feature          | ~nil~   |\n| ~sis-inline-english-activated-hook~   | Hook to run after inline english region activated          | ~nil~   |\n| ~sis-inline-english-deactivated-hook~ | Hook to run after inline english region deactivated        | ~nil~   |\n| ~sis-inline-other-activated-hook~     | Hook to run after inline other language region activated   | ~nil~   |\n| ~sis-inline-other-deactivated-hook~   | Hook to run after inline other language region deactivated | ~nil~   |\n|---------------------------------------+------------------------------------------------------------+---------|\n\n* How to\n**  Get the input source id\nAfter /input source manager/ is configured, you can get your /current\ninput source id/ by the command ~sis-get~.\n\n**  Inform the package of the input source change\n1. If your input source is switched from ~sis~, then everything\n   should be OK naturally. And your ~sis-auto-refresh-seconds~\n   can even be set to ~nil~.\n2. If your input source is switched from OS, to detect the switch timely,\n   ~sis-auto-refresh-seconds~ should not be too large.\n3. To save energy, if the input source is switched from OS during a long idle\n   period of Emacs, the package won't be aware in time. Then you can manually\n   inform the package by doing anything in Emacs to exit the long idle period,\n   or invoke the command ~sis-get~ directly.\n\n** Auto set /other/ input source for /org capture/ buffer\n#+begin_src elisp\n(add-hook 'org-capture-mode-hook #'sis-set-other)\n#+end_src\n\n** Customize my own context detector\nCustomize ~sis-context-detectors~ like the following codes:\n#+begin_src elisp\n(add-to-list 'sis-context-detectors\n             (lambda (\u0026rest _)\n               'other))\n#+end_src\n** Auto set input source in /minibuffer/ of a specific command.\nCustomize ~sis-respect-minibuffer-triggers~.\n\nHere is an example to automatically switch to /other/ input resource in\n/minibuffer/ of command:\n#+begin_src elisp\n(add-to-list 'sis-respect-minibuffer-triggers\n             (cons 'org-roam-node-find (lambda () 'other)))\n#+end_src\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaishulu%2Femacs-smart-input-source","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaishulu%2Femacs-smart-input-source","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaishulu%2Femacs-smart-input-source/lists"}