tkeys_command_config.h - ledit - Text editor (WIP) | |
git clone git://lumidify.org/ledit.git (fast, but not encrypted) | |
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow) | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
tkeys_command_config.h (10354B) | |
--- | |
1 /* | |
2 * These are the keys used by special commands that require a special key | |
3 * handler. This includes keys used to edit the line entry at the bottom | |
4 * and keys used for confirmation (e.g. when substituting). | |
5 */ | |
6 | |
7 static int substitute_yes(ledit_view *view, char *key_text, size_t len); | |
8 static int substitute_yes_all(ledit_view *view, char *key_text, size_t l… | |
9 static int substitute_no(ledit_view *view, char *key_text, size_t len); | |
10 static int substitute_no_all(ledit_view *view, char *key_text, size_t le… | |
11 static int edit_insert_text(ledit_view *view, char *key_text, size_t len… | |
12 static int edit_cursor_left(ledit_view *view, char *key_text, size_t len… | |
13 static int edit_cursor_right(ledit_view *view, char *key_text, size_t le… | |
14 static int edit_cursor_to_end(ledit_view *view, char *key_text, size_t l… | |
15 static int edit_cursor_to_beginning(ledit_view *view, char *key_text, si… | |
16 static int edit_backspace(ledit_view *view, char *key_text, size_t len); | |
17 static int edit_delete(ledit_view *view, char *key_text, size_t len); | |
18 static int edit_submit(ledit_view *view, char *key_text, size_t len); | |
19 static int edit_prevcommand(ledit_view *view, char *key_text, size_t len… | |
20 static int edit_nextcommand(ledit_view *view, char *key_text, size_t len… | |
21 static int edit_prevsearch(ledit_view *view, char *key_text, size_t len); | |
22 static int edit_nextsearch(ledit_view *view, char *key_text, size_t len); | |
23 static int editsearch_submit(ledit_view *view, char *key_text, size_t le… | |
24 static int editsearchb_submit(ledit_view *view, char *key_text, size_t l… | |
25 static int edit_discard(ledit_view *view, char *key_text, size_t len); | |
26 | |
27 struct key { | |
28 char *text; /* for keys that corr… | |
29 unsigned int mods; /* modifier mask */ | |
30 KeySym keysym; /* for other keys, e.… | |
31 enum ledit_command_type type; /* substitute, etc. */ | |
32 int (*func)(ledit_view *, char *, size_t); /* callback function … | |
33 }; | |
34 | |
35 /* "" means catch-all, i.e. all keys with text are given to that callbac… | |
36 static struct key keys_en[] = { | |
37 {"y", 0, 0, CMD_SUBSTITUTE, &substitute_yes}, | |
38 {"Y", 0, 0, CMD_SUBSTITUTE, &substitute_yes_all}, | |
39 {"n", 0, 0, CMD_SUBSTITUTE, &substitute_no}, | |
40 {"N", 0, 0, CMD_SUBSTITUTE, &substitute_no_all}, | |
41 {NULL, XK_ANY_MOD, XK_Return, CMD_EDIT, &edit_submit}, | |
42 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCH, &editsearch_submit… | |
43 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCHB, &editsearchb_subm… | |
44 {NULL, 0, XK_Left, CMD_EDIT, &edit_cursor_left}, | |
45 {NULL, 0, XK_Left, CMD_EDITSEARCH, &edit_cursor_left}, | |
46 {NULL, 0, XK_Left, CMD_EDITSEARCHB, &edit_cursor_left}, | |
47 {NULL, 0, XK_Right, CMD_EDIT, &edit_cursor_right}, | |
48 {NULL, 0, XK_Right, CMD_EDITSEARCH, &edit_cursor_right}, | |
49 {NULL, 0, XK_Right, CMD_EDITSEARCHB, &edit_cursor_right}, | |
50 {NULL, 0, XK_Up, CMD_EDIT, &edit_prevcommand}, | |
51 {NULL, 0, XK_Up, CMD_EDITSEARCH, &edit_prevsearch}, | |
52 {NULL, 0, XK_Up, CMD_EDITSEARCHB, &edit_prevsearch}, | |
53 {NULL, 0, XK_Down, CMD_EDIT, &edit_nextcommand}, | |
54 {NULL, 0, XK_Down, CMD_EDITSEARCH, &edit_nextsearch}, | |
55 {NULL, 0, XK_Down, CMD_EDITSEARCHB, &edit_nextsearch}, | |
56 {NULL, 0, XK_BackSpace, CMD_EDIT, &edit_backspace}, | |
57 {NULL, 0, XK_BackSpace, CMD_EDITSEARCH, &edit_backspace}, | |
58 {NULL, 0, XK_BackSpace, CMD_EDITSEARCHB, &edit_backspace}, | |
59 {NULL, 0, XK_Delete, CMD_EDIT, &edit_delete}, | |
60 {NULL, 0, XK_Delete, CMD_EDITSEARCH, &edit_delete}, | |
61 {NULL, 0, XK_Delete, CMD_EDITSEARCHB, &edit_delete}, | |
62 {NULL, 0, XK_End, CMD_EDIT, &edit_cursor_to_end}, | |
63 {NULL, 0, XK_End, CMD_EDITSEARCH, &edit_cursor_to_end}, | |
64 {NULL, 0, XK_End, CMD_EDITSEARCHB, &edit_cursor_to_end}, | |
65 {NULL, 0, XK_Home, CMD_EDIT, &edit_cursor_to_beginning}, | |
66 {NULL, 0, XK_Home, CMD_EDITSEARCH, &edit_cursor_to_beginning}, | |
67 {NULL, 0, XK_Home, CMD_EDITSEARCHB, &edit_cursor_to_beginning}, | |
68 {NULL, 0, XK_Escape, CMD_EDIT, &edit_discard}, | |
69 {NULL, 0, XK_Escape, CMD_EDITSEARCH, &edit_discard}, | |
70 {NULL, 0, XK_Escape, CMD_EDITSEARCHB, &edit_discard}, | |
71 {"", 0, 0, CMD_EDIT, &edit_insert_text}, | |
72 {"", 0, 0, CMD_EDITSEARCH, &edit_insert_text}, | |
73 {"", 0, 0, CMD_EDITSEARCHB, &edit_insert_text} | |
74 }; | |
75 | |
76 static struct key keys_de[] = { | |
77 {"z", 0, 0, CMD_SUBSTITUTE, &substitute_yes}, | |
78 {"Z", 0, 0, CMD_SUBSTITUTE, &substitute_yes_all}, | |
79 {"n", 0, 0, CMD_SUBSTITUTE, &substitute_no}, | |
80 {"N", 0, 0, CMD_SUBSTITUTE, &substitute_no_all}, | |
81 {NULL, XK_ANY_MOD, XK_Return, CMD_EDIT, &edit_submit}, | |
82 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCH, &editsearch_submit… | |
83 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCHB, &editsearchb_subm… | |
84 {NULL, 0, XK_Left, CMD_EDIT, &edit_cursor_left}, | |
85 {NULL, 0, XK_Left, CMD_EDITSEARCH, &edit_cursor_left}, | |
86 {NULL, 0, XK_Left, CMD_EDITSEARCHB, &edit_cursor_left}, | |
87 {NULL, 0, XK_Right, CMD_EDIT, &edit_cursor_right}, | |
88 {NULL, 0, XK_Right, CMD_EDITSEARCH, &edit_cursor_right}, | |
89 {NULL, 0, XK_Right, CMD_EDITSEARCHB, &edit_cursor_right}, | |
90 {NULL, 0, XK_Up, CMD_EDIT, &edit_prevcommand}, | |
91 {NULL, 0, XK_Up, CMD_EDITSEARCH, &edit_prevsearch}, | |
92 {NULL, 0, XK_Up, CMD_EDITSEARCHB, &edit_prevsearch}, | |
93 {NULL, 0, XK_Down, CMD_EDIT, &edit_nextcommand}, | |
94 {NULL, 0, XK_Down, CMD_EDITSEARCH, &edit_nextsearch}, | |
95 {NULL, 0, XK_Down, CMD_EDITSEARCHB, &edit_nextsearch}, | |
96 {NULL, 0, XK_BackSpace, CMD_EDIT, &edit_backspace}, | |
97 {NULL, 0, XK_BackSpace, CMD_EDITSEARCH, &edit_backspace}, | |
98 {NULL, 0, XK_BackSpace, CMD_EDITSEARCHB, &edit_backspace}, | |
99 {NULL, 0, XK_Delete, CMD_EDIT, &edit_delete}, | |
100 {NULL, 0, XK_Delete, CMD_EDITSEARCH, &edit_delete}, | |
101 {NULL, 0, XK_Delete, CMD_EDITSEARCHB, &edit_delete}, | |
102 {NULL, 0, XK_End, CMD_EDIT, &edit_cursor_to_end}, | |
103 {NULL, 0, XK_End, CMD_EDITSEARCH, &edit_cursor_to_end}, | |
104 {NULL, 0, XK_End, CMD_EDITSEARCHB, &edit_cursor_to_end}, | |
105 {NULL, 0, XK_Home, CMD_EDIT, &edit_cursor_to_beginning}, | |
106 {NULL, 0, XK_Home, CMD_EDITSEARCH, &edit_cursor_to_beginning}, | |
107 {NULL, 0, XK_Home, CMD_EDITSEARCHB, &edit_cursor_to_beginning}, | |
108 {NULL, 0, XK_Escape, CMD_EDIT, &edit_discard}, | |
109 {NULL, 0, XK_Escape, CMD_EDITSEARCH, &edit_discard}, | |
110 {NULL, 0, XK_Escape, CMD_EDITSEARCHB, &edit_discard}, | |
111 {"", 0, 0, CMD_EDIT, &edit_insert_text}, | |
112 {"", 0, 0, CMD_EDITSEARCH, &edit_insert_text}, | |
113 {"", 0, 0, CMD_EDITSEARCHB, &edit_insert_text} | |
114 }; | |
115 | |
116 static struct key keys_ur[] = { | |
117 {"ے", 0, 0, CMD_SUBSTITUTE, &substitute_yes}, | |
118 {"َ", 0, 0, CMD_SUBSTITUTE, &substitute_yes_all}, | |
119 {"ن", 0, 0, CMD_SUBSTITUTE, &substitute_no}, | |
120 {"ں", 0, 0, CMD_SUBSTITUTE, &substitute_no_all}, | |
121 {NULL, XK_ANY_MOD, XK_Return, CMD_EDIT, &edit_submit}, | |
122 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCH, &editsearch_submit… | |
123 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCHB, &editsearchb_subm… | |
124 {NULL, 0, XK_Left, CMD_EDIT, &edit_cursor_left}, | |
125 {NULL, 0, XK_Left, CMD_EDITSEARCH, &edit_cursor_left}, | |
126 {NULL, 0, XK_Left, CMD_EDITSEARCHB, &edit_cursor_left}, | |
127 {NULL, 0, XK_Right, CMD_EDIT, &edit_cursor_right}, | |
128 {NULL, 0, XK_Right, CMD_EDITSEARCH, &edit_cursor_right}, | |
129 {NULL, 0, XK_Right, CMD_EDITSEARCHB, &edit_cursor_right}, | |
130 {NULL, 0, XK_Up, CMD_EDIT, &edit_prevcommand}, | |
131 {NULL, 0, XK_Up, CMD_EDITSEARCH, &edit_prevsearch}, | |
132 {NULL, 0, XK_Up, CMD_EDITSEARCHB, &edit_prevsearch}, | |
133 {NULL, 0, XK_Down, CMD_EDIT, &edit_nextcommand}, | |
134 {NULL, 0, XK_Down, CMD_EDITSEARCH, &edit_nextsearch}, | |
135 {NULL, 0, XK_Down, CMD_EDITSEARCHB, &edit_nextsearch}, | |
136 {NULL, 0, XK_BackSpace, CMD_EDIT, &edit_backspace}, | |
137 {NULL, 0, XK_BackSpace, CMD_EDITSEARCH, &edit_backspace}, | |
138 {NULL, 0, XK_BackSpace, CMD_EDITSEARCHB, &edit_backspace}, | |
139 {NULL, 0, XK_Delete, CMD_EDIT, &edit_delete}, | |
140 {NULL, 0, XK_Delete, CMD_EDITSEARCH, &edit_delete}, | |
141 {NULL, 0, XK_Delete, CMD_EDITSEARCHB, &edit_delete}, | |
142 {NULL, 0, XK_End, CMD_EDIT, &edit_cursor_to_end}, | |
143 {NULL, 0, XK_End, CMD_EDITSEARCH, &edit_cursor_to_end}, | |
144 {NULL, 0, XK_End, CMD_EDITSEARCHB, &edit_cursor_to_end}, | |
145 {NULL, 0, XK_Home, CMD_EDIT, &edit_cursor_to_beginning}, | |
146 {NULL, 0, XK_Home, CMD_EDITSEARCH, &edit_cursor_to_beginning}, | |
147 {NULL, 0, XK_Home, CMD_EDITSEARCHB, &edit_cursor_to_beginning}, | |
148 {NULL, 0, XK_Escape, CMD_EDIT, &edit_discard}, | |
149 {NULL, 0, XK_Escape, CMD_EDITSEARCH, &edit_discard}, | |
150 {NULL, 0, XK_Escape, CMD_EDITSEARCHB, &edit_discard}, | |
151 {"", 0, 0, CMD_EDIT, &edit_insert_text}, | |
152 {"", 0, 0, CMD_EDITSEARCH, &edit_insert_text}, | |
153 {"", 0, 0, CMD_EDITSEARCHB, &edit_insert_text} | |
154 }; | |
155 | |
156 static struct key keys_hi[] = { | |
157 {"य", 0, 0, CMD_SUBSTITUTE, &substitute_yes}, | |
158 {"ञ", 0, 0, CMD_SUBSTITUTE, &substitute_yes_all}, | |
159 {"न", 0, 0, CMD_SUBSTITUTE, &substitute_no}, | |
160 {"ण", 0, 0, CMD_SUBSTITUTE, &substitute_no_all}, | |
161 {NULL, XK_ANY_MOD, XK_Return, CMD_EDIT, &edit_submit}, | |
162 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCH, &editsearch_submit… | |
163 {NULL, XK_ANY_MOD, XK_Return, CMD_EDITSEARCHB, &editsearchb_subm… | |
164 {NULL, 0, XK_Left, CMD_EDIT, &edit_cursor_left}, | |
165 {NULL, 0, XK_Left, CMD_EDITSEARCH, &edit_cursor_left}, | |
166 {NULL, 0, XK_Left, CMD_EDITSEARCHB, &edit_cursor_left}, | |
167 {NULL, 0, XK_Right, CMD_EDIT, &edit_cursor_right}, | |
168 {NULL, 0, XK_Right, CMD_EDITSEARCH, &edit_cursor_right}, | |
169 {NULL, 0, XK_Right, CMD_EDITSEARCHB, &edit_cursor_right}, | |
170 {NULL, 0, XK_Up, CMD_EDIT, &edit_prevcommand}, | |
171 {NULL, 0, XK_Up, CMD_EDITSEARCH, &edit_prevsearch}, | |
172 {NULL, 0, XK_Up, CMD_EDITSEARCHB, &edit_prevsearch}, | |
173 {NULL, 0, XK_Down, CMD_EDIT, &edit_nextcommand}, | |
174 {NULL, 0, XK_Down, CMD_EDITSEARCH, &edit_nextsearch}, | |
175 {NULL, 0, XK_Down, CMD_EDITSEARCHB, &edit_nextsearch}, | |
176 {NULL, 0, XK_BackSpace, CMD_EDIT, &edit_backspace}, | |
177 {NULL, 0, XK_BackSpace, CMD_EDITSEARCH, &edit_backspace}, | |
178 {NULL, 0, XK_BackSpace, CMD_EDITSEARCHB, &edit_backspace}, | |
179 {NULL, 0, XK_Delete, CMD_EDIT, &edit_delete}, | |
180 {NULL, 0, XK_Delete, CMD_EDITSEARCH, &edit_delete}, | |
181 {NULL, 0, XK_Delete, CMD_EDITSEARCHB, &edit_delete}, | |
182 {NULL, 0, XK_End, CMD_EDIT, &edit_cursor_to_end}, | |
183 {NULL, 0, XK_End, CMD_EDITSEARCH, &edit_cursor_to_end}, | |
184 {NULL, 0, XK_End, CMD_EDITSEARCHB, &edit_cursor_to_end}, | |
185 {NULL, 0, XK_Home, CMD_EDIT, &edit_cursor_to_beginning}, | |
186 {NULL, 0, XK_Home, CMD_EDITSEARCH, &edit_cursor_to_beginning}, | |
187 {NULL, 0, XK_Home, CMD_EDITSEARCHB, &edit_cursor_to_beginning}, | |
188 {NULL, 0, XK_Escape, CMD_EDIT, &edit_discard}, | |
189 {NULL, 0, XK_Escape, CMD_EDITSEARCH, &edit_discard}, | |
190 {NULL, 0, XK_Escape, CMD_EDITSEARCHB, &edit_discard}, | |
191 {"", 0, 0, CMD_EDIT, &edit_insert_text}, | |
192 {"", 0, 0, CMD_EDITSEARCH, &edit_insert_text}, | |
193 {"", 0, 0, CMD_EDITSEARCHB, &edit_insert_text} | |
194 }; | |
195 | |
196 GEN_KEY_ARRAY(struct key, keys_en, keys_de, keys_hi, keys_ur); |