关于 meow-edit 与 pyim (或是部分其他输入方式) 冲突的解决方案

最近在使用 meow-edit 与 pyim (一种 Emacs 内置的拼音输入法),遇到了以下问题:

当 meow-edit 退出插入模式 (insert-state) 的时候,pyim 并不能自动退出 (废话),因此在 normal-state 下需要手动退出才能输入键盘命令。

于是我研究了一会儿 meow 的 hooks 以及 insert-method 相关 file,最终得以解决了这个问题——在 meow-edit 退出 insert-state 时,当前输入方式自动被关闭,而再次进入 insert-state 时重新打开输入方式;以下是相关代码 :

(defvar-local the-late-input-method nil)
(use-package
  :dfines the-late-input-method
  :hook
  (meow-insert-enter . (lambda ()
                         (activate-input-method the-late-input-method)))
  (meow-insert-exit . (lambda ()
                        (setq the-late-input-method current-input-method)
                        (deactivate-input-method))))
;; 并非 use-package 的完整代码,仅相关代码

如果并非使用 use-package 则如下:

(defvar-local the-late-input-method nil)
(add-hook 'meow-insert-enter-hook
          (lambda ()
            (activate-insert-method the-late-input-method)))
(add-hook 'meow-insert-exit-hook
          (lambda ()
            (setq the-late-input-method current-input-method)
            (deactivate-input-method)))
2 个赞

也可以在 pyim端实现,pyim 自带探针功能,可以根据环境自动切换输入法状态,不过需要自己写探针函数

1 个赞