Newer
Older
* COMMENT -*- mode: org -*-
#+Date: 2019-10-08
#+STARTUP: content
* notes :entry:
** 2019-04-01 zero-framework.el a Chinese IM framework in emacs; FSM :doc:
title was: how to write a modern im for emacs.
cd ~/lisp/elisp/zero/
- DONE can I implement it as a minor mode? yes.
- DONE can I use panel to show candidates? yes.
- zero minor mode FSM
implemented in zero-framework.el
| Imp | state | action | next state | trigger action |
|-----+------------------+-----------------------------------------------------+------------------+---------------------------------------------------------------------------------------------------------|
| Y | IM_OFF | M-x zero-on or zero-toggle | IM_WAITING_INPUT | turn on minor mode |
| Y | IM_WAITING_INPUT | type M-x zero-off or zero-toggle | IM_OFF | turn off minor mode |
| Y | IM_WAITING_INPUT | type character that can start a sequence | IM_PREEDITING | update preedit str, show candidate list |
| Y | IM_WAITING_INPUT | type character that can not start a sequence | IM_WAITING_INPUT | insert character (full-width aware) |
| Y | IM_WAITING_INPUT | type [,.?!\] | IM_WAITING_INPUT | insert Chinese punctuation character (full-width aware) |
| Y | IM_PREEDITING | type character (that is not SPC, digit keys) | IM_PREEDITING | update preedit str, update and show candidate list |
| Y | IM_PREEDITING | type RET | IM_WAITING_INPUT | commit preedit str (full-width aware), hide candidate list, reset preedit str |
| Y | IM_PREEDITING | type SPC | IM_WAITING_INPUT | commit first candidate or preedit str (full-width aware), reset preedit str |
| Y | IM_PREEDITING | type digit keys | IM_WAITING_INPUT | commit nth candidate if it exists, otherwise, append to preedit str |
| | IM_PREEDITING | type C-g | IM_WAITING_INPUT | reset IM (reset preedit str, hide candidate list) |
| Y | IM_PREEDITING | type M-x zero-off or zero-toggle | IM_OFF | reset IM, turn off minor mode |
| Y | IM_PREEDITING | type <backspace>, when preedit str is longer than 1 | IM_PREEDITING | update preedit str, update and show candidate list |
| Y | IM_PREEDITING | type <backspace>, when preedit str is length 1 | IM_WAITING_INPUT | reset IM |
| Y | IM_PREEDITING | focus in | IM_PREEDITING | show candidat list |
| Y | IM_PREEDITING | focus out | IM_PREEDITING | hide panel |
| Y | IM_PREEDITING | type [,.?!\] | IM_WAITING_INPUT | commit first candidate or preedit str (full-width aware), insert Chinese punctuation (full-width aware) |
| Y | IM_PREEDITING | type -/= | IM_PREEDITING | candiate page up/down |
| | | | | |
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
in IM_OFF state, zero should not do any preedit try nor do punctuation
translate.
- DONE make zero-quickdial IM work in emacs.
see ~/lisp/elisp/zero/zero-quickdial.el
- DONE make zero-table IM work in emacs. with zero-panel.
see ~/lisp/elisp/zero/zero-table.el
- during development, press F8 to byte-compile and load the current el file.
this will also look for errors in the file.
press F9 to run ert tests.
- TODOs
- whenever a command moves point, IM should probably reset()
I can't remap every possible key/function.
- I need hook for buffer/window focus in/out.
currently, when user switch to another buffer, the panel will still show.
user can click mouse in another emacs window.
whenever focus is moved outside current buffer, I need a hook to run
zero-focus-out.
how to reproduce the problem
=============================
open emacs, split, top window show buffer with file t3, bottom window show
buffer with file t4.
in t3 buffer, press F1 to toggle zero on. type "a", candidate list will
show. now press C-x o to switch to t4 buffer. candidate list didn't go
away. because I can't find a hook for it.
the mouse case:
=================
open emacs, split, top window show buffer with file t3, bottom window show
buffer with file t4.
in t3 buffer, press F1 to toggle zero on. type "a", candidate list will
show. now click mouse on t4 buffer. candidate list didn't go away. because
I can't find a hook for it.
- how to check whether string contains character?
without converting char to string.
(zero-table-can-start-sequence) can use this.
* later :entry:
* current :entry:
**
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
** 2019-10-09 release zero-el on melpa
melpa/CONTRIBUTING.org at master · melpa/melpa · GitHub
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org
Making your package ready for inclusion
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org#making-your-package-ready-for-inclusion
Packaging Basics - GNU Emacs Lisp Reference Manual
https://www.gnu.org/software/emacs/manual/html_node/elisp/Packaging-Basics.html#Packaging-Basics
name: zero
version: 1.2.2
brief: a Chinese input method framework
long: zero is a Chinese input method framework for Emacs, implemented
as an Emacs minor mode. A zero-pinyin input method is included with zero
distribution.
dependencies: s
progress:
Preparing a pull request to MELPA
https://github.com/melpa/melpa/blob/master/CONTRIBUTING.org#preparing-a-pull-request-to-melpa
- problems
- should I create two pkg, one for zero-framework and one for zero-pinyin?
does melpa require two repo for this?
- minimum s version?
I only use s-contains-p s-join.
checked github
tag 1.2.0 already include these functions.
https://github.com/magnars/s.el/blob/1.2.0/s.el
- TODO Note that there is no way to control the order in which files are
byte-compiled.
- how to add autoload magic comments?
https://www.gnu.org/software/emacs/manual/html_node/elisp/Autoload.html
A magic autoload comment (often called an autoload cookie) consists of
‘;;;###autoload’, on a line by itself, just before the real definition of
the function in its autoloadable source file.
add this for some user commands.
zero-set-im
zero-set-default-im
zero-on
zero-toggle
- run package-lint
- Prefix function names with #’ (i.e., the special form function) instead of
just ’ (i.e., the special form quote) to tell the compiler this is a
function reference. E.g., (seq-filter #'evenp list).
I don't think this is necessary in my code.
-
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
** 2019-10-08 support full-width characters and symbols.
全角 半角
- feature requests
- when zero-mode is on, and in full-width mode
- commit English character and symbol should commit full-width character
if there is a full-width character. This should happen before checking
punctuation mapping. if a map is found, punctuation mapping is ignored.
- type letters should still go into preedit str, only commit full-width
char when user press RET.
- when zero-mode is on, and in half-width mode (the default)
- do what it does now. punctuation mapping is checked.
- implementation
- Block Halfwidth and Fullwidth Forms – Codepoints
https://codepoints.net/halfwidth_and_fullwidth_forms
- how to support full width character and symbol in zero?
update fsm table.
add a zero-full-width-mode variable
add default binding shift+space, M-x zero-toggle-full-width-mode
use modeline LIGHTER to show full/half width mode.
when in full-width mode, show ZeroF.
FSM table:
move from gtk-im-module-zero operational file.
- updated FSM.
so it's only a few changes.
- when insert character that can't start a sequence, insert char should be
full-width aware.
zero-self-insert-command
DONE zero-commit-preedit-str
DONE zero-convert-punctuation
- when commit preedit str, insert should be full-width aware.
- when insert Chinese punctuation character, insert should be full-width aware.
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
- problems
- where is the GB standard file?
- docs
GB/T 15834―2011 标点符号用法 电子版
http://people.ubuntu.com/~happyaron/l10n/GB(T)15834-2011.html
doesn't have much about full width vs half width.
- indeed double quotation mark is different from fullwidth quotation mark.
LEFT DOUBLE QUOTATION MARK “”
FULLWIDTH QUOTATION MARK ""
- search U+FF02
U+FF02 FULLWIDTH QUOTATION MARK – Codepoints
https://codepoints.net/U+FF02
Block Halfwidth and Fullwidth Forms – Codepoints
https://codepoints.net/halfwidth_and_fullwidth_forms
- why bind S-SPC key in zero-mode-map didn't work.
global-set-key does work.
shift-space is always translated to space in minor mode?
shift is not registered as key prefix.
I will just use another key binding for this command.
try M-space. nope.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Keymaps-and-Minor-Modes.html#Keymaps-and-Minor-Modes
Minor modes may bind commands to key sequences consisting of C-c followed
by a punctuation character. However, sequences consisting of C-c followed
by one of {}<>:;, or a control character or digit, are reserved for major
modes. Also, C-c letter is reserved for users. See Key Binding
Conventions.
try use C-c , , and C-c , .
how to add C-c , as prefix key and add binding for those two commands?
it works.
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
- elisp how to convert unicode hex to char?
1. Non-ASCII Characters
https://ftp.gnu.org/old-gnu/Manuals/elisp-manual-21-2.8/html_chapter/elisp_33.html#SEC541
FF01 to FF65 only 65 chars. I will just type it.
"\uff01" !
char to code point:
(split-char ?\)(unicode 0 255 1)
# FF01
(split-char ?\!)(unicode 0 255 1)
(insert (make-char 'unicode 0 255 1))
(split-char ?\!)(ascii 33)
# FF5A
(split-char ?\z)(unicode 0 255 90)
(insert (make-char 'unicode 0 255 90))
(split-char ?\z)(ascii 122)
# FF65
(split-char ?\・)(unicode 0 255 101)
(insert (make-char 'unicode 0 255 101))
ascii [33, 122]
map to
unicode 0 255 [1, 101].
then pick a few others if they are of importance.
- commit preedit str in full-width mode didn't work.
it still commit half-width str.
is zero-commit-preedit-str called at all? there is no debug message.
that is for commit preedit-str when there is no candidate.
when I press RET, the code is in zero-return.
- type = will insert both full-width char and half-width char.
fixed.