[分享] 切换输入法时自动更换光标颜色

用这个最新的版本,我之前一直用。

(im-start-daemon) 哪个版本反应会有点延迟。

image

QQ 群友分享的配置

;; 激活时
(defvar ime-cursor-insert '(bar "DarkOrange")
    "Default cursor color if using an input method.")
(defvar ime-cursor-visual '(hollow "DarkOrange")
    "Default cursor color if using an input method.")
(defvar ime-cursor-normal '(box "DarkOrange")
    "Default cursor color if using an input method.")
;; 不激活时
(defvar default-cursor-insert '(bar "CornflowerBlue")
    "Default text cursor color.")
(defvar default-cursor-visual '(hollow "CornflowerBlue")
    "Default text cursor color.")
(defvar default-cursor-normal '(box "CornflowerBlue")
    "Default text cursor color.")
;; 定义函数
(defun input-method-change-cursor-activate()
  "Set cursor to show that input-method is activated."
  (interactive)
  (setq evil-normal-state-cursor ime-cursor-normal)
  (setq evil-visual-state-cursor ime-cursor-visual)
  (setq evil-insert-state-cursor ime-cursor-insert)
  (evil-refresh-cursor))
(defun input-method-change-cursor-deactivate()
  "Set cursor to show that input-method is deactivated."
  (interactive)
  (setq evil-normal-state-cursor default-cursor-normal)
  (setq evil-visual-state-cursor default-cursor-visual)
  (setq evil-insert-state-cursor default-cursor-insert)
  (evil-refresh-cursor))
;(defun input-method-change-cursor-auto()
;    "Auto set cursor to show whether input-method is activated or not."
;    (interactive)
;  (if rime-mode (input-method-change-cursor-activate) (input-method-change-cursor-deactivate)))
;; Hook
;(add-hook 'post-command-hook #'input-method-change-cursor-auto)
(add-hook 'input-method-activate-hook #'input-method-change-cursor-activate)
(add-hook 'input-method-deactivate-hook #'input-method-change-cursor-deactivate)

避免了加入 post-command-hook 每个 command 都会运行的开销