emacs 渐进学习记录, 阅读陈斌配置文件 init-chinese.el

关于在Emacs的Evil模式中定制输入法切换,兼顾与evil-escape-mode的协同工作的函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 my-toggle-input-method


;; {{ make IME compatible with evil-mode
(defun my-toggle-input-method ()
  "When input method is on, goto `evil-insert-state'."
  (interactive)

  ;; load IME when needed, less memory footprint
  (when my-toggle-ime-init-function
    (funcall my-toggle-ime-init-function))

  ;; some guys don't use evil-mode at all
  (cond
   ((and (boundp 'evil-mode) evil-mode)
    ;; evil-mode
    (cond
     ((eq evil-state 'insert)
      (toggle-input-method))
     (t
      (evil-insert-state)
      (unless current-input-method
        (toggle-input-method))))
    (cond
     (current-input-method
      ;; evil-escape and pyim may conflict
      ;; @see https://github.com/redguardtoo/emacs.d/issues/629
      (evil-escape-mode -1)
      (message "IME on!"))
     (t
      (evil-escape-mode 1)
      (message "IME off!"))))
   (t
    ;; NOT evil-mode
    (toggle-input-method))))

使用 (and (boundp 'evil-mode) evil-mode) 确认在 evil-mode 中, 再根据不同的 evil 状态采取不同的 toggle 行为。在 toggle 之后,根据输入法状态开关 evil-escape-mode 并提示输入法的开关。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值