source: keys.c @ fa00c5c

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