source: keys.c @ 7d4fbcd

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