source: keys.c @ ddf1835

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since ddf1835 was ddf1835, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Bind the weird sequences that M-LEFT and M-RIGHT seem to actually emit. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 14.5 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5#define BIND_CMD(kpress, command, desc) \
6         owl_keymap_create_binding(km, kpress, command, NULL, desc);
7
8#define BIND_FNV(kpress, fn, desc) \
9         owl_keymap_create_binding(km, kpress, NULL, fn, desc);
10
11
12/* sets up the default keymaps */
13void owl_keys_setup_keymaps(owl_keyhandler *kh) {
14  owl_keymap *km, *km_global, *km_editwin, *km_mainwin,
15    *km_ew_multi, *km_ew_onel, *km_viewwin;
16
17 
18  /****************************************************************/
19  /*************************** GLOBAL *****************************/
20  /****************************************************************/
21
22  km_global = km = owl_keyhandler_create_and_add_keymap(kh, "global",
23       "System-wide default key bindings", 
24       owl_keys_default_invalid, NULL, NULL);
25  BIND_CMD("C-z",      "suspend",            "Suspend owl");
26
27  /****************************************************************/
28  /***************************** EDIT *****************************/
29  /****************************************************************/
30
31  km_editwin = km = owl_keyhandler_create_and_add_keymap(kh, "edit",
32       "Text editing and command window", 
33       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
34  owl_keymap_set_submap(km_editwin, km_global);
35  /*
36  BIND_CMD("F1",          "help",            "");
37  BIND_CMD("HELP",        "help",            "");
38  BIND_CMD("M-[ 2 8 ~",   "help",            "");
39  */
40
41  BIND_CMD("C-c",         "edit:cancel", "");
42  BIND_CMD("C-g",         "edit:cancel", "");
43
44  BIND_CMD("M-f",         "edit:move-next-word", "");
45  BIND_CMD("M-O 3 C",     "edit:move-next-word", "");
46  BIND_CMD("M-RIGHT",     "edit:move-next-word", "");
47  BIND_CMD("M-[ 1 ; 3 D", "edit:move-next-word", "");
48  BIND_CMD("M-b",         "edit:move-prev-word", "");
49  BIND_CMD("M-O 3 D",     "edit:move-prev-word", "");
50  BIND_CMD("M-LEFT",      "edit:move-prev-word", "");
51  BIND_CMD("M-[ 1 ; 3 C", "edit:move-next-word", "");
52
53  BIND_CMD("LEFT",        "edit:move-left", "");
54  BIND_CMD("M-[ D",       "edit:move-left", "");
55  BIND_CMD("C-b",         "edit:move-left", "");
56  BIND_CMD("RIGHT",       "edit:move-right", "");
57  BIND_CMD("M-[ C",       "edit:move-right", "");
58  BIND_CMD("C-f",         "edit:move-right", "");
59
60  BIND_CMD("M-<",         "edit:move-to-buffer-start", "");
61  BIND_CMD("HOME",        "edit:move-to-buffer-start", "");
62  BIND_CMD("M->",         "edit:move-to-buffer-end", "");
63  BIND_CMD("END",         "edit:move-to-buffer-end", "");
64
65  BIND_CMD("C-a",         "edit:move-to-line-start", "");
66  BIND_CMD("C-e",         "edit:move-to-line-end", "");
67
68  BIND_CMD("M-BACKSPACE", "edit:delete-prev-word", "");
69  BIND_CMD("M-DELETE",    "edit:delete-prev-word", "");
70  BIND_CMD("M-d",         "edit:delete-next-word", "");
71  BIND_CMD("M-DC",        "edit:delete-next-word", "");
72  BIND_CMD("M-[ 3 ; 3 ~", "edit:delete-next-word", "");
73
74  BIND_CMD("C-h",         "edit:delete-prev-char", "");
75  BIND_CMD("BACKSPACE",   "edit:delete-prev-char", "");
76  BIND_CMD("DELETE",      "edit:delete-prev-char", "");
77  BIND_CMD("C-d",         "edit:delete-next-char", "");
78  BIND_CMD("DC",          "edit:delete-next-char", "");
79
80  BIND_CMD("C-k",         "edit:delete-to-line-end", "");
81
82  BIND_CMD("C-t",         "edit:transpose-chars", "");
83
84  BIND_CMD("M-q",         "edit:fill-paragraph", "");
85
86  BIND_CMD("C-l",         "( edit:recenter ; redisplay )", "");
87
88
89  /****************************************************************/
90  /**************************** EDITMULTI *************************/
91  /****************************************************************/
92
93  km_ew_multi = km = owl_keyhandler_create_and_add_keymap(kh, "editmulti",
94       "Multi-line text editing", 
95       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
96  owl_keymap_set_submap(km_ew_multi, km_editwin);
97
98  BIND_CMD("UP",      "editmulti:move-up-line", "");
99  BIND_CMD("M-[ A",   "editmulti:move-up-line", "");
100  BIND_CMD("C-p",     "editmulti:move-up-line", "");
101  BIND_CMD("DOWN",    "editmulti:move-down-line", "");
102  BIND_CMD("M-[ B",   "editmulti:move-down-line", "");
103  BIND_CMD("C-n",     "editmulti:move-down-line", "");
104
105  /* This would be nice, but interferes with C-c to cancel */
106  /*BIND_CMD("C-c C-c", "editmulti:done", "sends the zephyr");*/
107
108  BIND_CMD("M-p",         "edit:history-prev", "");
109  BIND_CMD("M-n",         "edit:history-next", "");
110
111  /* note that changing "disable-ctrl-d" to "on" will change this to
112   * edit:delete-next-char */
113  BIND_CMD("C-d",     "editmulti:done-or-delete", "sends the zephyr if at the end of the message");
114
115
116  /****************************************************************/
117  /**************************** EDITLINE **************************/
118  /****************************************************************/
119
120  km_ew_onel = km = owl_keyhandler_create_and_add_keymap(kh, "editline",
121       "Single-line text editing", 
122       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
123  owl_keymap_set_submap(km_ew_onel, km_editwin);
124
125  BIND_CMD("C-u",         "edit:delete-all", "Clears the entire line");
126
127  BIND_CMD("UP",          "edit:history-prev", "");
128  BIND_CMD("M-[ A",       "edit:history-prev", "");
129  BIND_CMD("C-p",         "edit:history-prev", "");
130  BIND_CMD("M-p",         "edit:history-prev", "");
131
132  BIND_CMD("DOWN",        "edit:history-next", "");
133  BIND_CMD("M-[ B",       "edit:history-next", "");
134  BIND_CMD("C-n",         "edit:history-next", "");
135  BIND_CMD("M-n",         "edit:history-next", "");
136
137  BIND_CMD("LF",          "editline:done", "executes the command");
138  BIND_CMD("CR",          "editline:done", "executes the command");
139
140 
141  /****************************************************************/
142  /**************************** EDITRESPONSE **********************/
143  /****************************************************************/
144
145  km_ew_onel = km = owl_keyhandler_create_and_add_keymap(kh, "editresponse",
146       "Single-line response to question", 
147       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
148  owl_keymap_set_submap(km_ew_onel, km_editwin);
149
150  BIND_CMD("C-u",         "edit:delete-all", "Clears the entire line");
151
152  BIND_CMD("LF",          "editresponse:done", "executes the command");
153  BIND_CMD("CR",          "editresponse:done", "executes the command");
154
155
156  /****************************************************************/
157  /**************************** POPLESS ***************************/
158  /****************************************************************/
159
160  km_viewwin = km = owl_keyhandler_create_and_add_keymap(kh, "popless",
161       "Pop-up window (eg, help)", 
162       owl_keys_default_invalid, NULL, owl_keys_popless_postalways);
163  owl_keymap_set_submap(km_viewwin, km_global);
164
165  BIND_CMD("SPACE",       "popless:scroll-down-page", "");
166  BIND_CMD("NPAGE",       "popless:scroll-down-page", "");
167  BIND_CMD("M-n",         "popless:scroll-down-page", "");
168
169  BIND_CMD("b",           "popless:scroll-up-page", "");
170  BIND_CMD("PPAGE",       "popless:scroll-up-page", "")
171  BIND_CMD("M-p",         "popless:scroll-up-page", "");
172
173  BIND_CMD("CR",          "popless:scroll-down-line", "");
174  BIND_CMD("LF",          "popless:scroll-down-line", "");
175  BIND_CMD("DOWN",        "popless:scroll-down-line", "");
176  BIND_CMD("M-[ B",       "popless:scroll-down-line", "");
177  BIND_CMD("C-n",         "popless:scroll-down-line", "");
178
179  BIND_CMD("UP",          "popless:scroll-up-line", "");
180  BIND_CMD("M-[ A",       "popless:scroll-up-line", "");
181  BIND_CMD("C-h",         "popless:scroll-up-line", "");
182  BIND_CMD("C-p",         "popless:scroll-up-line", "");
183  BIND_CMD("DELETE",      "popless:scroll-up-line", "");
184  BIND_CMD("BACKSPACE",   "popless:scroll-up-line", "");
185  BIND_CMD("DC",          "popless:scroll-up-line", "");
186
187  BIND_CMD("RIGHT",       "popless:scroll-right 10", "scrolls right");
188  BIND_CMD("M-[ C",       "popless:scroll-right 10", "scrolls right");
189  BIND_CMD("LEFT",        "popless:scroll-left  10", "scrolls left");
190  BIND_CMD("M-[ D",       "popless:scroll-left  10", "scrolls left");
191
192  BIND_CMD("HOME",        "popless:scroll-to-top", "");
193  BIND_CMD("<",           "popless:scroll-to-top", "");
194  BIND_CMD("M-<",         "popless:scroll-to-top", "");
195
196  BIND_CMD("END",         "popless:scroll-to-bottom", "");
197  BIND_CMD(">",           "popless:scroll-to-bottom", "");
198  BIND_CMD("M->",         "popless:scroll-to-bottom", "");
199
200  BIND_CMD("q",           "popless:quit", "");
201  BIND_CMD("C-c",         "popless:quit", "");
202  BIND_CMD("C-g",         "popless:quit", "");
203
204  BIND_CMD("C-l",         "redisplay", "");
205
206
207  /****************************************************************/
208  /***************************** RECV *****************************/
209  /****************************************************************/
210
211  km_mainwin = km = owl_keyhandler_create_and_add_keymap(kh, "recv",
212        "Main window / message list",
213        owl_keys_default_invalid, owl_keys_recwin_prealways, NULL);
214  owl_keymap_set_submap(km_mainwin, km_global);
215  BIND_CMD("C-x C-c", "start-command quit", "");
216  BIND_CMD("F1",      "help",           "");
217  BIND_CMD("h",       "help",           "");
218  BIND_CMD("HELP",    "help",           "");
219  BIND_CMD("M-[ 2 8 ~",   "help",       "");
220
221  BIND_CMD(":",       "start-command",  "start a new command");
222  BIND_CMD("M-x",     "start-command",  "start a new command");
223
224  BIND_CMD("x",       "expunge",        "");
225  BIND_CMD("u",       "undelete",       "");
226  BIND_CMD("M-u",     "undelete view",  "undelete all messages in view");
227  BIND_CMD("d",       "delete",         "mark message for deletion");
228  BIND_CMD("M-D",     "delete view",    "mark all messages in view for deletion");
229  BIND_CMD("C-x k",   "smartzpunt -i",  "zpunt current <class,instance>");
230
231  BIND_CMD("X",   "( expunge ; view --home )", "expunge deletions and switch to home view");
232
233  BIND_CMD("v",   "start-command view ", "start a view command");
234  BIND_CMD("V",   "view --home",      "change to the home view ('all' by default)");
235  BIND_CMD("!",   "view -r",          "invert the current view filter");
236  BIND_CMD("M-n", "smartnarrow",      "narrow to a view based on the current message");
237  BIND_CMD("M-N", "smartnarrow -i",   "narrow to a view based on the current message, and consider instance pair");
238  BIND_CMD("M-p", "view personal", "");
239 
240  BIND_CMD("/",   "start-command search ", "start a search command");
241  BIND_CMD("?",   "start-command search -r ", "start a reverse search command");
242
243  BIND_CMD("LEFT",   "recv:shiftleft", "");
244  BIND_CMD("M-[ D",  "recv:shiftleft", "");
245  BIND_CMD("RIGHT",  "recv:shiftright","");
246  BIND_CMD("M-[ C",  "recv:shiftright","");
247  BIND_CMD("DOWN",   "recv:next",      "");
248  BIND_CMD("C-n",    "recv:next",      "");
249  BIND_CMD("M-[ B",  "recv:next",      "");
250  BIND_CMD("M-C-n",  "recv:next --smart-filter", "move to next message matching the current one"); 
251  BIND_CMD("UP",     "recv:prev",      "");
252  BIND_CMD("M-[ A",  "recv:prev",      "");
253  BIND_CMD("n",      "recv:next-notdel", "");
254  BIND_CMD("p",      "recv:prev-notdel", "");
255  BIND_CMD("C-p",    "recv:prev",        "");
256  BIND_CMD("M-C-p",  "recv:prev --smart-filter", "move to previous message matching the current one");
257  BIND_CMD("P",      "recv:next-personal", "");
258  BIND_CMD("M-P",    "recv:prev-personal", "");
259  BIND_CMD("M-<",    "recv:first",     "");
260  BIND_CMD("<",      "recv:first",     "");
261  BIND_CMD("M->",    "recv:last",      "");
262  BIND_CMD(">",      "recv:last",      "");
263  BIND_CMD("C-v",    "recv:pagedown",  "");
264  BIND_CMD("NPAGE",  "recv:pagedown",  "");
265  BIND_CMD("M-v",    "recv:pageup",    "");
266  BIND_CMD("PPAGE",  "recv:pageup",    "");
267  BIND_CMD("C-@",    "recv:mark",      "");
268  BIND_CMD("C-x C-x",    "recv:swapmark",  "");
269
270  BIND_CMD("SPACE",     "recv:scroll  10", "scroll message down a page");
271  BIND_CMD("CR",        "recv:scroll   1", "scroll message down a line");
272  BIND_CMD("LF",        "recv:scroll   1", "scroll message down a line");
273  BIND_CMD("C-h"  ,     "recv:scroll  -1", "scroll message up a line");
274  BIND_CMD("DELETE",    "recv:scroll  -1", "scroll message up a line");
275  BIND_CMD("BACKSPACE", "recv:scroll  -1", "scroll message up a line");
276  BIND_CMD("DC",        "recv:scroll  -1", "scroll message up a line");
277  BIND_CMD("b",         "recv:scroll -10", "scroll message up a page");
278
279  BIND_CMD("C-l",       "redisplay",       "");
280
281  BIND_CMD("i",   "info",             "");
282  BIND_CMD("l",   "blist",            "");
283  BIND_CMD("B",   "alist",            "");
284  BIND_CMD("M",   "pop-message",      "");
285  BIND_CMD("T",   "delete trash",     "mark all 'trash' messages for deletion");
286
287  BIND_CMD("o",   "toggle-oneline", "");
288
289  BIND_CMD("A",   "away toggle",     "toggles away message on and off");
290
291  BIND_CMD("z",   "start-command zwrite ", "start a zwrite command");
292  BIND_CMD("a",   "start-command aimwrite ", "start an aimwrite command");
293  BIND_CMD("r",   "reply",            "reply to the current message");
294  BIND_CMD("R",   "reply sender",     "reply to sender of the current message");
295  BIND_CMD("C-r", "reply -e",         "reply to the current message, but allow editing of recipient");
296  BIND_CMD("M-r", "reply -e",         "reply to the current message, but allow editing of recipient");
297  BIND_CMD("M-R", "reply -e sender",  "reply to sender of the current message, but allow editing of recipient");
298
299  BIND_CMD("W",   "start-command webzephyr ", "start a webzephyr command");
300
301  BIND_CMD("C-c",  "",                "no effect in this mode");
302  BIND_CMD("C-g",  "",                "no effect in this mode");
303
304
305  /**********************/
306
307  owl_function_activate_keymap("recv");
308
309}
310
311
312/****************************************************************/
313/********************* Support Functions ************************/
314/****************************************************************/
315
316void owl_keys_recwin_prealways(owl_input j) {
317  /* Clear the message line on subsequent key presses */
318  owl_function_makemsg("");
319}
320
321void owl_keys_editwin_default(owl_input j) {
322  owl_editwin *e;
323  if (NULL != (e=owl_global_get_typwin(&g))) {
324       owl_editwin_process_char(e, j);
325  }
326}
327
328void owl_keys_editwin_postalways(owl_input j) {
329  owl_editwin *e;
330  if (NULL != (e=owl_global_get_typwin(&g))) {
331    owl_editwin_post_process_char(e, j);
332  }
333  owl_global_set_needrefresh(&g);
334}
335
336void owl_keys_popless_postalways(owl_input j) {
337  owl_viewwin *v = owl_global_get_viewwin(&g);
338  owl_popwin *pw = owl_global_get_popwin(&g);
339
340  if (pw && owl_popwin_is_active(pw) && v) {
341    owl_viewwin_redisplay(v, 1);
342  } 
343}
344
345void owl_keys_default_invalid(owl_input j) {
346  if (j.ch==ERR) return;
347  if (j.ch==410) return;
348  owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g));
349}
350
Note: See TracBrowser for help on using the repository browser.