/
init-input.el
163 lines (154 loc) · 6.54 KB
/
init-input.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;; -*- lexical-binding: t; -*-
;; ;; 为 rime 的提示框做准备
;; (use-package posframe)
;;
;; ;; emacs rime 输入法前端
;; (use-package rime
;; :custom
;; (default-input-method "rime")
;; :config
;; (setq rime-user-data-dir (no-littering-expand-etc-file-name "rime/"))
;; (setq rime-show-candidate 'posframe) ; 设置候选框展示风格
;; (setq rime-disable-predicates
;; '(rime-predicate-after-alphabet-char-p ; 在英文字符串之后(必须为以字母开头的英文字符串)
;; rime-predicate-prog-in-code-p ; 在 prog-mode 和 conf-mode 中除了注释和引号内字符串之外的区域
;; rime-predicate-space-after-cc-p ; 在中文字符且有空格之后
;; rime-predicate-current-uppercase-letter-p ; 将要输入的为大写字母时
;; rime-predicate-tex-math-or-command-p ; 在 (La)TeX 数学环境中或者输入 (La)TeX 命令时
;; rime-predicate-punctuation-line-begin-p ; 在行首要输入符号时
;; ;; rime-predicate-after-ascii-char-p ; 任意英文字符后
;; ))
;; :hook
;; (after-init . toggle-input-method)
;; (kill-emacs . rime-lib-finalize) ; hack,修正 rime 的关闭问题
;; )
;;
;; 在 emacs 状态下不使用搜狗输入法,进而使用 emacs 内的 rime 输入法
;; (defvar input-toggle nil "Toggle variable for input method, when nil means English, true means Chinese.")
;;
;; (defun fcitx2en ()
;; "Change to the English input."
;; (let ((input-status (process-lines "fcitx-remote")))
;; (when (= (string-to-number (car input-status)) 1) ; input status == 1 时表示搜狗输入法
;; (setq input-toggle nil)
;; (start-process "fcitx-remote-process" nil "fcitx-remote" "-o")
;; (message ""))))
;;
;; (defun fcitx2zh ()
;; "Change to the Chinese input."
;; (let ((input-status (process-lines "fcitx-remote")))
;; (unless (and (not (= (string-to-number (car input-status)) 1)) input-toggle)
;; (start-process "fcitx-remote-process" nil "fcitx-remote" "-c")
;; (setq input-toggle t))))
;;
;; (setq focus-in-hook 'fcitx2en)
;; (setq focus-out-hook 'fcitx2zh)
;; (add-hook 'kill-emacs-hook 'fcitx2zh)
;; 这个方案比 emacs rime 提供的中英文 inline 方便
;; (use-package sis
;; :hook
;; (((text-mode prog-mode) . sis-context-mode)
;; ((text-mode prog-mode) . sis-inline-mode))
;; :config
;; (sis-ism-lazyman-config "1" "2" 'fcitx)
;; ;; enable the /cursor color/ mode
;; (sis-global-cursor-color-mode t)
;; ;; enable the /respect/ mode
;; (sis-global-respect-mode t)
;; ;; enable the /context/ mode for all buffers
;; (sis-global-context-mode t)
;; ;; enable the /inline english/ mode for all buffers
;; (sis-global-inline-mode t)
;; :custom
;; (sis-other-cursor-color "#c3e88d")
;; )
(use-package rime
:straight (rime :type git
:host github
:repo "DogLooksGood/emacs-rime"
:files ("*.el" "Makefile" "lib.c"))
:custom-face
(rime-default-face ((t (:inherit hl-line
:background unspecified :foreground unspecified))))
(rime-preedit-face ((t (:inherit hl-line
:background unspecified
:inverse-video unspecified :underline t))))
:init
(require 'rime)
:config
(setq rime-user-data-dir (no-littering-expand-etc-file-name "rime/"))
;; https://manateelazycat.github.io/2023/04/05/emacs-rime-ice/
;; (setq rime-user-data-dir "~/.local/share/fcitx5/rime/")
(setq rime-disable-predicates
'(
meow-normal-mode-p
meow-motion-mode-p
meow-keypad-mode-p
rime-predicate-after-alphabet-char-p ; 在英文字符串之后(必须为以字母开头的英文字符串)
rime-predicate-prog-in-code-p ; 在 prog-mode 和 conf-mode 中除了注释和引号内字符串之外的区域
rime-predicate-space-after-cc-p ; 在中文字符且有空格之后
rime-predicate-current-uppercase-letter-p ; 将要输入的为大写字母时
;; rime-predicate-tex-math-or-command-p ; 在 (La)TeX 数学环境中或者输入 (La)TeX 命令时
rime-predicate-punctuation-line-begin-p ; 在行首要输入符号时
rime-predicate-after-ascii-char-p ; 任意英文字符后
))
(setq rime-show-candidate 'posframe
rime-show-preedit 'inline
rime-posframe-properties '(:internal-border-width 7))
(defadvice! +rime-do-finalize-after-loading-module (&rest _)
:after #'rime--load-dynamic-module
(add-hook! kill-emacs-hook #'rime-lib-finalize))
:bind
("C-M-\\" . rime-force-enable)
)
;; (use-package key-echo
;; :straight nil
;; :after rime
;; :init
;; (add-to-list 'load-path "~/.emacs.d/site-lisp/key-echo/")
;; (require 'key-echo)
;; (key-echo-enable)
;; (defun key-echo-shift-to-switch-input-method (key)
;; (interactive)
;; (when (string-equal key "Key.shift")
;; (toggle-input-method)
;; ))
;; (setq key-echo-single-key-trigger-func 'key-echo-shift-to-switch-input-method)
;; ;; WORKAROUND: I don't know why I have to add this
;; (key-echo-restart-process)
;; )
;; [sis] automatically switch input source
(use-package sis
:straight t
:hook
(((text-mode prog-mode) . sis-context-mode)
((text-mode prog-mode) . sis-inline-mode)
)
:init
(require 'sis)
;; :custom
;; (sis-other-cursor-color (face-foreground 'error nil t))
:config
;; (add-hook! (+theme-changed-hook server-after-make-frame-hook) :call-immediately
;; (defun +sis-set-other-cursor-color ()
;; (setq sis-other-cursor-color (face-foreground 'error nil t))))
;; Use emacs-rime as default
(sis-ism-lazyman-config nil "rime" 'native)
;; enable the /cursor color/ mode
;; (sis-global-cursor-color-mode t)
;; enable the /respect/ mode
;; (sis-global-respect-mode t)
;; enable the /context/ mode for all buffers
;; (sis-global-context-mode t)
;; enable the /inline english/ mode for all buffers
;; (sis-global-inline-mode t)
;; Context mode
;; (add-hook 'meow-insert-exit-hook #'sis-set-english)
;; (add-to-list 'sis-context-hooks 'meow-insert-enter-hook)
;; 这里的缩进有问题,不要在意
;; (defun +sis-remove-head-space-after-cc-punc (_)
;; (when (or (memq (char-before) '(?, ?。 ?? ?! ?; ?: ?( ?【 ?「 ?“))
;; (bolp))
;; (delete-char 1)))
;; (setq sis-inline-tighten-head-rule #'+sis-remove-head-space-after-cc-punc)
)