Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

利用 input-decode-map 简化 respect-mode 的实现 #73

Open
roife opened this issue Nov 28, 2023 · 0 comments
Open

利用 input-decode-map 简化 respect-mode 的实现 #73

roife opened this issue Nov 28, 2023 · 0 comments

Comments

@roife
Copy link
Contributor

roife commented Nov 28, 2023

目前 respect-mode 的实现中用了 emulation-mode-map-alists 实现,这个实现和 meow/键盘宏等操作存在冲突,我参考 emacs-mac 中的 emacs-auto-ascii-mode,使用了下面的代码,似乎也能达到同样的效果,而且代码更加简单,不知道能否用来重新实现 respect-mode

(defun select-input-source ()
  "Select the most-recently-used ASCII-capable keyboard input source.
Expects to be added to normal hooks."
  (ime-set "com.apple.keylayout.ABC"))

(defun setup-input-source (&optional _prompt)
  "Set up the most-recently-used ASCII-capable keyboard input source.
Expects to be bound to global keymap's prefix keys in
`input-decode-map'."
  (select-input-source)
  (vector last-input-event))

(map-keymap (lambda (event definition)
              (if (and (keymapp definition) (integerp event)
                       (not (eq event ?\e)))
                  (define-key input-decode-map (vector event)
                              'setup-input-source)))
            global-map)
(map-keymap (lambda (event definition)
              (if (and (keymapp definition) (integerp event)
                       (not (eq event ?\e)))
                  (define-key input-decode-map (vector ?\e event)
                              'setup-input-source)))
            esc-map)
(add-hook 'minibuffer-setup-hook 'select-input-source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant