-
Notifications
You must be signed in to change notification settings - Fork 0
/
im-cursor-chg.el
50 lines (40 loc) · 1.46 KB
/
im-cursor-chg.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;; im-cursor-chg.el --- Change cursor color for input method -*- lexical-binding: t; -*-
;; Inspired by code from cursor-chg
;; URL: https://github.com/emacsmirror/cursor-chg/blob/master/cursor-chg.el
;;; Commentary:
;;
;; To turn on the cursor color change by default,
;; put the following in your Emacs init file.
;;
;; (require 'im-cursor-chg)
;; (cursor-chg-mode 1)
;;
;;; Code:
(require 'rime nil t)
(defvar im-cursor-color "Orange"
"The color for input method.")
(defvar im-default-cursor-color (frame-parameter nil 'cursor-color)
"The default cursor color.")
(defun im--chinese-p ()
"Check if the current input state is Chinese."
(if (featurep 'rime)
(and (rime--should-enable-p)
(not (rime--should-inline-ascii-p))
current-input-method)
current-input-method))
(defun im-change-cursor-color ()
"Set cursor color depending on input method."
(interactive)
(set-cursor-color (if (im--chinese-p)
im-cursor-color
im-default-cursor-color)))
(define-minor-mode cursor-chg-mode
"Toggle changing cursor color.
With numeric ARG, turn cursor changing on if ARG is positive.
When this mode is on, `im-change-cursor-color' control cursor changing."
:init-value nil :global t :group 'frames
(if cursor-chg-mode
(add-hook 'post-command-hook 'im-change-cursor-color)
(remove-hook 'post-command-hook 'im-change-cursor-color)))
(provide 'im-cursor-chg)
;;; im-cursor-chg.el ends here