File: keys.c

package info (click to toggle)
barnowl 1.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 5,472 kB
  • sloc: ansic: 36,670; perl: 20,938; sh: 1,598; makefile: 181
file content (362 lines) | stat: -rw-r--r-- 15,801 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
136
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
164
165
166
167
168
169
170
171
172
173
174
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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#include "owl.h"

#define BIND_CMD(kpress, command, desc) \
         owl_keymap_create_binding(km, kpress, command, NULL, desc)

#define BIND_FNV(kpress, fn, desc) \
         owl_keymap_create_binding(km, kpress, NULL, fn, desc)


/* sets up the default keymaps */
void owl_keys_setup_keymaps(owl_keyhandler *kh) {
  owl_keymap *km, *km_global, *km_editwin, *km_mainwin,
    *km_ew_multi, *km_ew_onel, *km_viewwin;

  
  /****************************************************************/
  /*************************** GLOBAL *****************************/
  /****************************************************************/

  km_global = km = owl_keyhandler_create_and_add_keymap(kh, "global",
       "System-wide default key bindings", 
       owl_keys_default_invalid, NULL, NULL);
  BIND_CMD("C-z",      "message Use :suspend to suspend.", "");

  /****************************************************************/
  /***************************** EDIT *****************************/
  /****************************************************************/

  km_editwin = km = owl_keyhandler_create_and_add_keymap(kh, "edit",
       "Text editing and command window", 
       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
  owl_keymap_set_parent(km_editwin, km_global);
  /*
  BIND_CMD("F1",          "help",            "");
  BIND_CMD("HELP",        "help",            "");
  BIND_CMD("M-[ 2 8 ~",   "help",            "");
  */

  BIND_CMD("C-c",         "edit:cancel", "");
  BIND_CMD("C-g",         "edit:cancel", "");

  BIND_CMD("M-f",         "edit:move-next-word", "");
  BIND_CMD("M-O 3 C",     "edit:move-next-word", "");
  BIND_CMD("M-RIGHT",     "edit:move-next-word", "");
  BIND_CMD("M-[ 1 ; 3 D", "edit:move-next-word", "");
  BIND_CMD("M-b",         "edit:move-prev-word", "");
  BIND_CMD("M-O 3 D",     "edit:move-prev-word", "");
  BIND_CMD("M-LEFT",      "edit:move-prev-word", "");
  BIND_CMD("M-[ 1 ; 3 C", "edit:move-next-word", "");

  BIND_CMD("LEFT",        "edit:move-left", "");
  BIND_CMD("M-[ D",       "edit:move-left", "");
  BIND_CMD("C-b",         "edit:move-left", "");
  BIND_CMD("RIGHT",       "edit:move-right", "");
  BIND_CMD("M-[ C",       "edit:move-right", "");
  BIND_CMD("C-f",         "edit:move-right", "");

  BIND_CMD("M-<",         "edit:move-to-buffer-start", "");
  BIND_CMD("HOME",        "edit:move-to-buffer-start", "");
  BIND_CMD("M->",         "edit:move-to-buffer-end", "");
  BIND_CMD("END",         "edit:move-to-buffer-end", "");

  BIND_CMD("C-a",         "edit:move-to-line-start", "");
  BIND_CMD("C-e",         "edit:move-to-line-end", "");

  BIND_CMD("M-BACKSPACE", "edit:delete-prev-word", "");
  BIND_CMD("M-DELETE",    "edit:delete-prev-word", "");
  BIND_CMD("M-d",         "edit:delete-next-word", "");
  BIND_CMD("M-DC",        "edit:delete-next-word", "");
  BIND_CMD("M-[ 3 ; 3 ~", "edit:delete-next-word", "");

  BIND_CMD("C-h",         "edit:delete-prev-char", "");
  BIND_CMD("BACKSPACE",   "edit:delete-prev-char", "");
  BIND_CMD("DELETE",      "edit:delete-prev-char", "");
  BIND_CMD("C-d",         "edit:delete-next-char", "");
  BIND_CMD("DC",          "edit:delete-next-char", "");

  BIND_CMD("C-k",         "edit:delete-to-line-end", "");

  BIND_CMD("C-t",         "edit:transpose-chars", "");

  BIND_CMD("M-q",         "edit:fill-paragraph", "");

  BIND_CMD("C-@",         "edit:set-mark", "");
  BIND_CMD("C-x C-x",     "edit:exchange-point-and-mark", "");

  BIND_CMD("M-w",         "edit:copy-region-as-kill", "");
  BIND_CMD("C-w",         "edit:kill-region", "");
  BIND_CMD("C-y",         "edit:yank", "");

  BIND_CMD("C-l",         "( edit:recenter ; redisplay )", "");


  /****************************************************************/
  /**************************** EDITMULTI *************************/
  /****************************************************************/

  km_ew_multi = km = owl_keyhandler_create_and_add_keymap(kh, "editmulti",
       "Multi-line text editing", 
       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
  owl_keymap_set_parent(km_ew_multi, km_editwin);

  BIND_CMD("UP",      "edit:move-up-line", "");
  BIND_CMD("M-[ A",   "edit:move-up-line", "");
  BIND_CMD("C-p",     "edit:move-up-line", "");
  BIND_CMD("DOWN",    "edit:move-down-line", "");
  BIND_CMD("M-[ B",   "edit:move-down-line", "");
  BIND_CMD("C-n",     "edit:move-down-line", "");

  BIND_CMD("M-}",     "edit:forward-paragraph", "");
  BIND_CMD("M-{",     "edit:backward-paragraph", "");

  /* This would be nice, but interferes with C-c to cancel */
  /*BIND_CMD("C-c C-c", "edit:done", "sends the zephyr");*/

  BIND_CMD("M-p",         "edit:history-prev", "");
  BIND_CMD("M-n",         "edit:history-next", "");

  /* note that changing "disable-ctrl-d" to "on" will change this to 
   * edit:delete-next-char */
  BIND_CMD("C-d",     "edit:done-or-delete", "sends the zephyr if at the end of the message");


  /****************************************************************/
  /**************************** EDITLINE **************************/
  /****************************************************************/

  km_ew_onel = km = owl_keyhandler_create_and_add_keymap(kh, "editline",
       "Single-line text editing", 
       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
  owl_keymap_set_parent(km_ew_onel, km_editwin);

  BIND_CMD("C-u",         "edit:delete-all", "Clears the entire line");

  BIND_CMD("UP",          "edit:history-prev", "");
  BIND_CMD("M-[ A",       "edit:history-prev", "");
  BIND_CMD("C-p",         "edit:history-prev", "");
  BIND_CMD("M-p",         "edit:history-prev", "");

  BIND_CMD("DOWN",        "edit:history-next", "");
  BIND_CMD("M-[ B",       "edit:history-next", "");
  BIND_CMD("C-n",         "edit:history-next", "");
  BIND_CMD("M-n",         "edit:history-next", "");

  BIND_CMD("LF",          "editline:done", "executes the command");
  BIND_CMD("CR",          "editline:done", "executes the command");

  
  /****************************************************************/
  /**************************** EDITRESPONSE **********************/
  /****************************************************************/

  km_ew_onel = km = owl_keyhandler_create_and_add_keymap(kh, "editresponse",
       "Single-line response to question", 
       owl_keys_editwin_default, NULL, owl_keys_editwin_postalways);
  owl_keymap_set_parent(km_ew_onel, km_editwin);

  BIND_CMD("C-u",         "edit:delete-all", "Clears the entire line");

  BIND_CMD("LF",          "editresponse:done", "executes the command");
  BIND_CMD("CR",          "editresponse:done", "executes the command");


  /****************************************************************/
  /**************************** POPLESS ***************************/
  /****************************************************************/

  km_viewwin = km = owl_keyhandler_create_and_add_keymap(kh, "popless",
       "Pop-up window (eg, help)", 
       owl_keys_default_invalid, NULL, owl_keys_popless_postalways);
  owl_keymap_set_parent(km_viewwin, km_global);

  BIND_CMD("SPACE",       "popless:scroll-down-page", "");
  BIND_CMD("NPAGE",       "popless:scroll-down-page", "");
  BIND_CMD("M-n",         "popless:scroll-down-page", "");
  BIND_CMD("C-v",         "popless:scroll-down-page", "");

  BIND_CMD("b",           "popless:scroll-up-page", "");
  BIND_CMD("PPAGE",       "popless:scroll-up-page", "");
  BIND_CMD("M-p",         "popless:scroll-up-page", "");
  BIND_CMD("M-v",         "popless:scroll-up-page", "");

  BIND_CMD("CR",          "popless:scroll-down-line", "");
  BIND_CMD("LF",          "popless:scroll-down-line", "");
  BIND_CMD("DOWN",        "popless:scroll-down-line", "");
  BIND_CMD("M-[ B",       "popless:scroll-down-line", "");
  BIND_CMD("C-n",         "popless:scroll-down-line", "");

  BIND_CMD("UP",          "popless:scroll-up-line", "");
  BIND_CMD("M-[ A",       "popless:scroll-up-line", "");
  BIND_CMD("C-h",         "popless:scroll-up-line", "");
  BIND_CMD("C-p",         "popless:scroll-up-line", "");
  BIND_CMD("DELETE",      "popless:scroll-up-line", "");
  BIND_CMD("BACKSPACE",   "popless:scroll-up-line", "");
  BIND_CMD("DC",          "popless:scroll-up-line", "");

  BIND_CMD("RIGHT",       "popless:scroll-right 10", "scrolls right");
  BIND_CMD("M-[ C",       "popless:scroll-right 10", "scrolls right");
  BIND_CMD("LEFT",        "popless:scroll-left  10", "scrolls left");
  BIND_CMD("M-[ D",       "popless:scroll-left  10", "scrolls left");

  BIND_CMD("HOME",        "popless:scroll-to-top", "");
  BIND_CMD("<",           "popless:scroll-to-top", "");
  BIND_CMD("M-<",         "popless:scroll-to-top", "");

  BIND_CMD("END",         "popless:scroll-to-bottom", "");
  BIND_CMD(">",           "popless:scroll-to-bottom", "");
  BIND_CMD("M->",         "popless:scroll-to-bottom", "");

  BIND_CMD("q",           "popless:quit", "");
  BIND_CMD("C-c",         "popless:quit", "");
  BIND_CMD("C-g",         "popless:quit", "");

  /* Don't bind popless:start-command for now, as most commands make
   * no sense. */
#if 0
  BIND_CMD(":",           "popless:start-command",  "start a new command");
  BIND_CMD("M-x",         "popless:start-command",  "start a new command");
#endif

  BIND_CMD("/",   "popless:start-search", "start a search command");
  BIND_CMD("?",   "popless:start-search -r", "start a reverse search command");
  BIND_CMD("n",   "popless:search", "find next occurrence of search");
  BIND_CMD("N",   "popless:search -r", "find previous occurrence of search");

  BIND_CMD("C-l",         "redisplay", "");


  /****************************************************************/
  /***************************** RECV *****************************/
  /****************************************************************/

  km_mainwin = km = owl_keyhandler_create_and_add_keymap(kh, "recv",
	"Main window / message list",
        owl_keys_default_invalid, owl_keys_recwin_prealways, NULL);
  owl_keymap_set_parent(km_mainwin, km_global);
  BIND_CMD("C-x C-c", "start-command quit", "");
  BIND_CMD("F1",      "help",           "");
  BIND_CMD("h",       "help",           "");
  BIND_CMD("HELP",    "help",           "");
  BIND_CMD("M-[ 2 8 ~",   "help",       "");

  BIND_CMD(":",       "start-command",  "start a new command");
  BIND_CMD("M-x",     "start-command",  "start a new command");

  BIND_CMD("x",       "expunge",        "");
  BIND_CMD("u",       "undelete",       "");
  BIND_CMD("M-u",     "undelete view",  "undelete all messages in view");
  BIND_CMD("d",       "delete",         "mark message for deletion");
  BIND_CMD("M-D",     "delete view",    "mark all messages in view for deletion");
  BIND_CMD("C-x k",   "smartzpunt -i",  "zpunt current <class,instance>");

  BIND_CMD("X",   "( expunge ; view --home )", "expunge deletions and switch to home view");

  BIND_CMD("v",   "start-command view ", "start a view command");
  BIND_CMD("V",   "view --home",      "change to the home view ('all' by default)");
  BIND_CMD("!",   "view -r",          "invert the current view filter");
  BIND_CMD("M-n", "smartnarrow",      "narrow to a view based on the current message");
  BIND_CMD("M-N", "smartnarrow -i",   "narrow to a view based on the current message, and consider instance pair");
  BIND_CMD("M-m", "smartnarrow -r",   "like M-n but with 'narrow-related' temporarily flipped.");
  BIND_CMD("M-M", "smartnarrow -ri",  "like M-N but with 'narrow-related' temporarily flipped.");
  BIND_CMD("M-p", "view personal", "");
  
  BIND_CMD("/",   "start-command search ", "start a search command");
  BIND_CMD("?",   "start-command search -r ", "start a reverse search command");

  BIND_CMD("HOME",   "recv:setshift 0","move the display all the way left");
  BIND_CMD("LEFT",   "recv:shiftleft", "");
  BIND_CMD("M-[ D",  "recv:shiftleft", "");
  BIND_CMD("RIGHT",  "recv:shiftright","");
  BIND_CMD("M-[ C",  "recv:shiftright","");
  BIND_CMD("DOWN",   "recv:next",      "");
  BIND_CMD("C-n",    "recv:next",      "");
  BIND_CMD("M-[ B",  "recv:next",      "");
  BIND_CMD("M-C-n",  "recv:next --smart-filter", "move to next message matching the current one"); 
  BIND_CMD("UP",     "recv:prev",      "");
  BIND_CMD("M-[ A",  "recv:prev",      "");
  BIND_CMD("n",      "recv:next-notdel", "");
  BIND_CMD("p",      "recv:prev-notdel", "");
  BIND_CMD("C-p",    "recv:prev",        "");
  BIND_CMD("M-C-p",  "recv:prev --smart-filter", "move to previous message matching the current one");
  BIND_CMD("P",      "recv:next-personal", "");
  BIND_CMD("M-P",    "recv:prev-personal", "");
  BIND_CMD("M-<",    "recv:first",     "");
  BIND_CMD("<",      "recv:first",     "");
  BIND_CMD("M->",    "recv:last",      "");
  BIND_CMD(">",      "recv:last",      "");
  BIND_CMD("C-v",    "recv:pagedown",  "");
  BIND_CMD("NPAGE",  "recv:pagedown",  "");
  BIND_CMD("M-v",    "recv:pageup",    "");
  BIND_CMD("PPAGE",  "recv:pageup",    "");
  BIND_CMD("C-@",    "recv:mark",      "");
  BIND_CMD("C-x C-x",    "recv:swapmark",  "");

  BIND_CMD("SPACE",     "recv:scroll  10", "scroll message down a page");
  BIND_CMD("CR",        "recv:scroll   1", "scroll message down a line");
  BIND_CMD("LF",        "recv:scroll   1", "scroll message down a line");
  BIND_CMD("C-h"  ,     "recv:scroll  -1", "scroll message up a line");
  BIND_CMD("DELETE",    "recv:scroll  -1", "scroll message up a line");
  BIND_CMD("BACKSPACE", "recv:scroll  -1", "scroll message up a line");
  BIND_CMD("DC",        "recv:scroll  -1", "scroll message up a line");
  BIND_CMD("b",         "recv:scroll -10", "scroll message up a page");

  BIND_CMD("C-l",       "redisplay",       "");

  BIND_CMD("i",   "info",             "");
  BIND_CMD("l",   "blist",            "");
  BIND_CMD("B",   "alist",            "");
  BIND_CMD("M",   "pop-message",      "");
  BIND_CMD("T",   "delete trash",     "mark all 'trash' messages for deletion");

  BIND_CMD("o",   "toggle-oneline", "");

  BIND_CMD("A",   "away toggle",     "toggles away message on and off");

  BIND_CMD("z",   "start-command zwrite ", "start a zwrite command");
  BIND_CMD("a",   "start-command aimwrite ", "start an aimwrite command");
  BIND_CMD("r",   "reply",            "reply to the current message");
  BIND_CMD("R",   "reply sender",     "reply to sender of the current message");
  BIND_CMD("C-r", "reply -e",         "reply to the current message, but allow editing of recipient");
  BIND_CMD("M-r", "reply -e",         "reply to the current message, but allow editing of recipient");
  BIND_CMD("M-R", "reply -e sender",  "reply to sender of the current message, but allow editing of recipient");

  BIND_CMD("W",   "start-command webzephyr ", "start a webzephyr command");

  BIND_CMD("C-c",  "",                "no effect in this mode");
  BIND_CMD("C-g",  "",                "no effect in this mode");
}


/****************************************************************/
/********************* Support Functions ************************/
/****************************************************************/

void owl_keys_recwin_prealways(owl_input j) {
  /* Clear the message line on subsequent key presses */
  owl_function_makemsg("");
}

void owl_keys_editwin_default(owl_input j) {
  owl_editwin *e;
  if (NULL != (e=owl_global_current_typwin(&g))) {
       owl_editwin_process_char(e, j);
  }
}

void owl_keys_editwin_postalways(owl_input j) {
  owl_editwin *e;
  if (NULL != (e=owl_global_current_typwin(&g))) {
    owl_editwin_post_process_char(e, j);
  }
}

void owl_keys_popless_postalways(owl_input j) {
}

void owl_keys_default_invalid(owl_input j) {
  if (j.ch==ERR) return;
  if (j.ch==410) return;
  owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g));
}