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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
|
// Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
/** @scope modules */
/**
* @instance events
*/
const Events = Module("events", {
requires: ["autocommands"],
init: function () {
const self = this;
this._fullscreen = window.fullScreen;
this._lastFocus = null;
this._currentMacro = "";
this._lastMacro = "";
this._macros = storage.newMap("macros", true, { privateData: true });
// NOTE: the order of ["Esc", "Escape"] or ["Escape", "Esc"]
// matters, so use that string as the first item, that you
// want to refer to within liberator's source code for
// comparisons like if (key == "<Esc>") { ... }
this._keyTable = {
add: ["Plus", "Add"],
back_space: ["BS"],
delete: ["Del"],
escape: ["Esc", "Escape"],
insert: ["Insert", "Ins"],
left_shift: ["LT", "<"],
return: ["Return", "CR", "Enter"],
right_shift: [">"],
space: ["Space", " "],
subtract: ["Minus", "Subtract"]
};
this._code_key = {};
this._key_code = {};
for (let [k, v] in Iterator(KeyEvent))
if (/^DOM_VK_(?![A-Z0-9]$)/.test(k)) {
k = k.substr(7).toLowerCase();
let names = [k.replace(/(^|_)(.)/g, function (m, n1, n2) n2.toUpperCase())
.replace(/^NUMPAD/, "k")];
if (k in this._keyTable)
names = this._keyTable[k];
this._code_key[v] = names[0];
for (let [, name] in Iterator(names))
this._key_code[name.toLowerCase()] = v;
}
// HACK: as Gecko does not include an event for <, we must add this in manually.
if (!("<" in this._key_code)) {
this._key_code["<"] = 60;
this._key_code["lt"] = 60;
this._code_key[60] = "lt";
}
this._input = {
buffer: "", // partial command storage
pendingMotionMap: null, // e.g. "d{motion}" if we wait for a motion of the "d" command
pendingArgMap: null, // pending map storage for commands like m{a-z}
count: -1 // parsed count from the input buffer
};
function onResize(event) {
if (window.fullScreen != this._fullscreen) {
this._fullscreen = window.fullScreen;
liberator.triggerObserver("fullscreen", this._fullscreen);
autocommands.trigger("Fullscreen", { state: this._fullscreen });
}
}
/////////////////////////////////////////////////////////
// track if a popup is open or the menubar is active
this._activeMenubar = false;
window.addEventListener("popupshown", this._enterPopupMode, true);
window.addEventListener("popuphidden", this._exitPopupMode, true);
window.addEventListener("DOMMenuBarActive", this._enterMenuMode, true);
window.addEventListener("DOMMenuBarInactive", this._exitMenuMode, true);
window.addEventListener("resize", onResize, true);
// load all macros
// setTimeout needed since io. is loaded after events.
setTimeout(function () {
try {
let dirs = io.getRuntimeDirectories("macros");
if (dirs.length > 0) {
for (let [, dir] in Iterator(dirs)) {
liberator.echomsg('Searching for "macros/*" in "' + dir.path + '"', 2);
liberator.log("Sourcing macros directory: " + dir.path + "...", 3);
let files = io.readDirectory(dir.path);
for (let file in dir.iterDirectory()) {
if (file.exists() && !file.isDirectory() && file.isReadable() &&
/^[\w_-]+(\.vimp)?$/i.test(file.leafName)) {
let name = file.leafName.replace(/\.vimp$/i, "");
this._macros.set(name, file.read().split("\n")[0]);
liberator.log("Macro " + name + " added: " + this._macros.get(name), 5);
}
}
}
}
else
liberator.log("No user macros directory found", 3);
}
catch (e) {
// thrown if directory does not exist
liberator.log("Error sourcing macros directory: " + e, 9);
}
}, 100);
window.XULBrowserWindow = this.progressListener;
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = this.progressListener;
try {
getBrowser().addProgressListener(this.progressListener, Ci.nsIWebProgress.NOTIFY_ALL);
}
catch (e) {}
function wrapListener(method) {
return function (event) {
try {
self[method](event);
}
catch (e) {
if (e.message == "Interrupted")
liberator.echoerr("Interrupted");
else
liberator.echoerr("Processing " + event.type + " event: " + (e.echoerr || e));
liberator.reportError(e);
}
};
}
window.addEventListener("keypress", wrapListener("onKeyPress"), true);
window.addEventListener("keydown", wrapListener("onKeyUpOrDown"), true);
window.addEventListener("keyup", wrapListener("onKeyUpOrDown"), true);
},
/**
* A destructor called when this module is destroyed.
*/
destroy: function () {
// removeEventListeners() to avoid mem leaks
liberator.dump("TODO: remove all eventlisteners");
try {
getBrowser().removeProgressListener(this.progressListener);
}
catch (e) {}
window.removeEventListener("popupshown", this._enterPopupMode, true);
window.removeEventListener("popuphidden", this._exitPopupMode, true);
window.removeEventListener("DOMMenuBarActive", this._enterMenuMode, true);
window.removeEventListener("DOMMenuBarInactive", this._exitMenuMode, true);
window.removeEventListener("keypress", this.onKeyPress, true);
window.removeEventListener("keydown", this.onKeyDown, true);
},
_enterPopupMode: function (event) {
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "liberator-visualbell")
return;
modes.add(modes.MENU);
},
_exitPopupMode: function () { // gContextMenu is set to NULL, when a context menu is closed
if (window.gContextMenu == null && !this._activeMenubar)
modes.remove(modes.MENU);
},
_enterMenuMode: function () {
this._activeMenubar = true;
modes.add(modes.MENU);
},
_exitMenuMode: function () {
this._activeMenubar = false;
modes.remove(modes.MENU);
},
/**
* @property {boolean} Whether synthetic key events are currently being
* processed.
*/
feedingKeys: false,
wantsModeReset: true, // used in onFocusChange since Firefox is so buggy here
/**
* Initiates the recording of a key event macro.
*
* @param {string} macro The name for the macro.
*/
startRecording: function (macro) {
// TODO: ignore this like Vim?
liberator.assert(/[a-zA-Z0-9]/.test(macro),
"E354: Invalid register name: '" + macro + "'");
modes.isRecording = true;
if (/[A-Z]/.test(macro)) { // uppercase (append)
this._currentMacro = macro.toLowerCase();
if (!this._macros.get(this._currentMacro))
this._macros.set(this._currentMacro, ""); // initialize if it does not yet exist
}
else {
this._currentMacro = macro;
this._macros.set(this._currentMacro, "");
}
},
/**
* Replays a macro.
*
* @param {string} The name of the macro to replay.
* @return {boolean}
*/
playMacro: function (macro) {
let res = false;
if (!/[a-zA-Z0-9@]/.test(macro) && macro.length == 1) {
liberator.echoerr("E354: Invalid register name: '" + macro + "'");
return false;
}
if (macro == "@") { // use lastMacro if it's set
if (!this._lastMacro) {
liberator.echoerr("E748: No previously used register");
return false;
}
}
else {
if (macro.length == 1)
this._lastMacro = macro.toLowerCase(); // XXX: sets last played macro, even if it does not yet exist
else
this._lastMacro = macro; // e.g. long names are case sensitive
}
if (this._macros.get(this._lastMacro)) {
// make sure the page is stopped before starting to play the macro
try {
window.getWebNavigation().stop(nsIWebNavigation.STOP_ALL);
}
catch (e) {}
buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro
modes.isReplaying = true;
res = events.feedkeys(this._macros.get(this._lastMacro), { noremap: true });
modes.isReplaying = false;
}
else {
if (this._lastMacro.length == 1)
// TODO: ignore this like Vim?
liberator.echoerr("Exxx: Register '" + this._lastMacro + "' not set");
else
liberator.echoerr("Exxx: Named macro '" + this._lastMacro + "' not set");
}
return res;
},
/**
* Returns all macros matching <b>filter</b>.
*
* @param {string} filter A regular expression filter string. A null
* filter selects all macros.
*/
getMacros: function (filter) {
if (!filter)
return this._macros;
let re = RegExp(filter);
return ([macro, keys] for ([macro, keys] in this._macros) if (re.test(macro)));
},
/**
* Deletes all macros matching <b>filter</b>.
*
* @param {string} filter A regular expression filter string. A null
* filter deletes all macros.
*/
deleteMacros: function (filter) {
let re = RegExp(filter);
for (let [item, ] in this._macros) {
if (re.test(item) || !filter)
this._macros.remove(item);
}
},
/**
* Pushes keys onto the event queue from liberator. It is similar to
* Vim's feedkeys() method, but cannot cope with 2 partially-fed
* strings, you have to feed one parsable string.
*
* @param {string} keys A string like "2<C-f>" to push onto the event
* queue. If you want "<" to be taken literally, prepend it with a
* "\\".
* @param {boolean} noremap Allow recursive mappings.
* @param {boolean} silent Whether the command should be echoed to the
* command line.
* @returns {boolean}
*/
feedkeys: function (keys, noremap, quiet) {
let doc = window.document;
let view = window.document.defaultView;
let wasFeeding = this.feedingKeys;
this.feedingKeys = true;
this.duringFeed = this.duringFeed || [];
let wasQuiet = commandline.quiet;
if (quiet)
commandline.quiet = quiet;
try {
liberator.threadYield(1, true);
for (let [, evt_obj] in Iterator(events.fromString(keys))) {
let elem = liberator.focus || window.content;
let evt = events.create(doc, "keypress", evt_obj);
if (typeof noremap == "object")
for (let [k, v] in Iterator(noremap))
evt[k] = v;
else
evt.noremap = !!noremap;
evt.isMacro = true;
// A special hack for liberator-specific key names.
if (evt_obj.liberatorString || evt_obj.liberatorShift) {
evt.liberatorString = evt_obj.liberatorString; // for key-less keypress events e.g. <Nop>
evt.liberatorShift = evt_obj.liberatorShift; // for untypable shift keys e.g. <S-1>
events.onKeyPress(evt);
}
else
elem.dispatchEvent(evt);
if (!this.feedingKeys)
break;
// Stop feeding keys if page loading failed.
if (modes.isReplaying && !this.waitForPageLoad())
break;
}
}
finally {
this.feedingKeys = wasFeeding;
if (quiet)
commandline.quiet = wasQuiet;
if (this.duringFeed.length) {
let duringFeed = this.duringFeed;
this.duringFeed = [];
for (let [, evt] in Iterator(duringFeed))
evt.target.dispatchEvent(evt);
}
}
},
/**
* Creates an actual event from a pseudo-event object.
*
* The pseudo-event object (such as may be retrieved from events.fromString)
* should have any properties you want the event to have.
*
* @param {Document} doc The DOM document to associate this event with
* @param {Type} type The type of event (keypress, click, etc.)
* @param {Object} opts The pseudo-event.
*/
create: function (doc, type, opts) {
var DEFAULTS = {
Key: {
type: type,
bubbles: true, cancelable: true,
view: doc.defaultView,
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
keyCode: 0, charCode: 0
},
Mouse: {
type: type,
bubbles: true, cancelable: true,
view: doc.defaultView,
detail: 1,
screenX: 0, screenY: 0,
clientX: 0, clientY: 0,
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
button: 0,
relatedTarget: null
}
};
const TYPES = {
click: "Mouse", mousedown: "Mouse", mouseup: "Mouse",
mouseover: "Mouse", mouseout: "Mouse",
keypress: "Key", keyup: "Key", keydown: "Key"
};
var t = TYPES[type];
var evt = doc.createEvent(t + "Events");
evt["init" + t + "Event"].apply(evt,
[v for ([k, v] in Iterator(util.extend(DEFAULTS[t], opts)))]);
return evt;
},
/**
* Converts a user-input string of keys into a canonical
* representation.
*
* <C-A> maps to <C-a>, <C-S-a> maps to <C-S-A>
* <C- > maps to <C-Space>, <S-a> maps to A
* << maps to <lt><lt>
*
* <S-@> is preserved, as in vim, to allow untypable key-combinations
* in macros.
*
* canonicalKeys(canonicalKeys(x)) == canonicalKeys(x) for all values
* of x.
*
* @param {string} keys Messy form.
* @returns {string} Canonical form.
*/
canonicalKeys: function (keys) {
return events.fromString(keys).map(events.closure.toString).join("");
},
/**
* Converts an event string into an array of pseudo-event objects.
*
* These objects can be used as arguments to events.toString or
* events.create, though they are unlikely to be much use for other
* purposes. They have many of the properties you'd expect to find on a
* real event, but none of the methods.
*
* Also may contain two "special" parameters, .liberatorString and
* .liberatorShift these are set for characters that can never by
* typed, but may appear in mappings, for example <Nop> is passed as
* liberatorString, and liberatorShift is set when a user specifies
* <S-@> where @ is a non-case-changable, non-space character.
*
* @param {string} keys The string to parse.
* @return {Array[Object]}
*/
fromString: function (input) {
let out = [];
let re = RegExp("<.*?>?>|[^<]|<(?!.*>)", "g");
let match;
while (match = re.exec(input)) {
let evt_str = match[0];
let evt_obj = { ctrlKey: false, shiftKey: false, altKey: false, metaKey: false,
keyCode: 0, charCode: 0, type: "keypress" };
if (evt_str.length > 1) { // <.*?>
let [match, modifier, keyname] = evt_str.match(/^<((?:[CSMA]-)*)(.+?)>$/i) || [false, '', ''];
modifier = modifier.toUpperCase();
keyname = keyname.toLowerCase();
if (keyname && !(keyname.length == 1 && modifier.length == 0 || // disallow <> and <a>
!(keyname.length == 1 || this._key_code[keyname] || keyname == "nop" || /mouse$/.test(keyname)))) { // disallow <misteak>
evt_obj.ctrlKey = /C-/.test(modifier);
evt_obj.altKey = /A-/.test(modifier);
evt_obj.shiftKey = /S-/.test(modifier);
evt_obj.metaKey = /M-/.test(modifier);
if (keyname.length == 1) { // normal characters
if (evt_obj.shiftKey) {
keyname = keyname.toUpperCase();
if (keyname == keyname.toLowerCase())
evt_obj.liberatorShift = true;
}
evt_obj.charCode = keyname.charCodeAt(0);
}
else if (keyname == "nop") {
evt_obj.liberatorString = "<Nop>";
}
else if (/mouse$/.test(keyname)) { // mouse events
evt_obj.type = (/2-/.test(modifier) ? "dblclick" : "click");
evt_obj.button = ["leftmouse", "middlemouse", "rightmouse"].indexOf(keyname);
delete evt_obj.keyCode;
delete evt_obj.charCode;
}
else { // spaces, control characters, and <
evt_obj.keyCode = this._key_code[keyname];
evt_obj.charCode = 0;
}
}
else { // an invalid sequence starting with <, treat as a literal
out = out.concat(events.fromString("<lt>" + evt_str.substr(1)));
continue;
}
}
else // a simple key (no <...>)
evt_obj.charCode = evt_str.charCodeAt(0);
// TODO: make a list of characters that need keyCode and charCode somewhere
if (evt_obj.keyCode == 32 || evt_obj.charCode == 32)
evt_obj.charCode = evt_obj.keyCode = 32; // <Space>
if (evt_obj.keyCode == 60 || evt_obj.charCode == 60)
evt_obj.charCode = evt_obj.keyCode = 60; // <lt>
out.push(evt_obj);
}
return out;
},
/**
* Converts the specified event to a string in liberator key-code
* notation. Returns null for an unknown event.
*
* E.g. pressing ctrl+n would result in the string "<C-n>".
*
* @param {Event} event
* @returns {string}
*/
toString: function (event) {
if (!event)
return "[object Mappings]";
if (event.liberatorString)
return event.liberatorString;
let key = null;
let modifier = "";
if (event.ctrlKey)
modifier += "C-";
if (event.altKey)
modifier += "A-";
if (event.metaKey)
modifier += "M-";
if (/^key/.test(event.type)) {
if (event.charCode == 0) {
if (event.shiftKey)
modifier += "S-";
if (event.keyCode in this._code_key)
key = this._code_key[event.keyCode];
}
// [Ctrl-Bug] special handling of mysterious <C-[>, <C-\\>, <C-]>, <C-^>, <C-_> bugs (OS/X)
// (i.e., cntrl codes 27--31)
// ---
// For more information, see:
// [*] Vimp FAQ: http://vimperator.org/trac/wiki/Vimperator/FAQ#WhydoesntC-workforEscMacOSX
// [*] Referenced mailing list msg: http://www.mozdev.org/pipermail/vimperator/2008-May/001548.html
// [*] Mozilla bug 416227: event.charCode in keypress handler has unexpected values on Mac for Ctrl with chars in "[ ] _ \"
// https://bugzilla.mozilla.org/show_bug.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&id=416227
// [*] Mozilla bug 432951: Ctrl+'foo' doesn't seem same charCode as Meta+'foo' on Cocoa
// https://bugzilla.mozilla.org/show_bug.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&id=432951
// ---
//
// The following fixes are only activated if liberator.has("MacUnix").
// Technically, they prevent mappings from <C-Esc> (and
// <C-C-]> if your fancy keyboard permits such things<?>), but
// these <C-control> mappings are probably pathological (<C-Esc>
// certainly is on Windows), and so it is probably
// harmless to remove the has("MacUnix") if desired.
//
else if (liberator.has("MacUnix") && event.ctrlKey && event.charCode >= 27 && event.charCode <= 31) {
if (event.charCode == 27) { // [Ctrl-Bug 1/5] the <C-[> bug
key = "Esc";
modifier = modifier.replace("C-", "");
}
else // [Ctrl-Bug 2,3,4,5/5] the <C-\\>, <C-]>, <C-^>, <C-_> bugs
key = String.fromCharCode(event.charCode + 64);
}
// a normal key like a, b, c, 0, etc.
else if (event.charCode > 0) {
key = String.fromCharCode(event.charCode);
if (key in this._key_code) {
// a named charcode key (<Space> and <lt>) space can be shifted, <lt> must be forced
if ((key.match(/^\s$/) && event.shiftKey) || event.liberatorShift)
modifier += "S-";
key = this._code_key[this._key_code[key]];
}
else {
// a shift modifier is only allowed if the key is alphabetical and used in a C-A-M- mapping in the uppercase,
// or if the shift has been forced for a non-alphabetical character by the user while :map-ping
if ((key != key.toLowerCase() && (event.ctrlKey || event.altKey || event.metaKey)) || event.liberatorShift)
modifier += "S-";
else if (modifier.length == 0)
return key;
}
}
if (key == null)
return;
}
else if (event.type == "click" || event.type == "dblclick") {
if (event.shiftKey)
modifier += "S-";
if (event.type == "dblclick")
modifier += "2-";
// TODO: triple and quadruple click
switch (event.button) {
case 0:
key = "LeftMouse";
break;
case 1:
key = "MiddleMouse";
break;
case 2:
key = "RightMouse";
break;
}
}
if (key == null)
return null;
return "<" + modifier + key + ">";
},
/**
* Whether <b>key</b> is a key code defined to accept/execute input on
* the command line.
*
* @param {string} key The key code to test.
* @returns {boolean}
*/
isAcceptKey: function (key) key == "<Return>" || key == "<C-j>" || key == "<C-m>",
/**
* Whether <b>key</b> is a key code defined to reject/cancel input on
* the command line.
*
* @param {string} key The key code to test.
* @returns {boolean}
*/
isCancelKey: function (key) key == "<Esc>" || key == "<C-[>" || key == "<C-c>",
/**
* Waits for the current buffer to successfully finish loading. Returns
* true for a successful page load otherwise false.
*
* @returns {boolean}
*/
waitForPageLoad: function () {
//liberator.dump("start waiting in loaded state: " + buffer.loaded);
liberator.threadYield(true); // clear queue
if (buffer.loaded == 1)
return true;
const maxWaitTime = 25;
let start = Date.now();
let end = start + (maxWaitTime * 1000); // maximum time to wait - TODO: add option
let now;
while (now = Date.now(), now < end) {
liberator.threadYield();
//if ((now - start) % 1000 < 10)
// liberator.dump("waited: " + (now - start) + " ms");
if (!events.feedingKeys)
return false;
if (buffer.loaded > 0) {
liberator.sleep(250);
break;
}
else
liberator.echo("Waiting for page to load...", commandline.DISALLOW_MULTILINE);
}
modes.show();
// TODO: allow macros to be continued when page does not fully load with an option
let ret = (buffer.loaded == 1);
if (!ret)
liberator.echoerr("Page did not load completely in " + maxWaitTime + " seconds. Macro stopped.");
//liberator.dump("done waiting: " + ret);
// sometimes the input widget had focus when replaying a macro
// maybe this call should be moved somewhere else?
// liberator.focusContent(true);
return ret;
},
// argument "event" is deliberately not used, as i don't seem to have
// access to the real focus target
// Huh? --djk
onFocusChange: function (event) {
// command line has it's own focus change handler
if (liberator.mode == modes.COMMAND_LINE)
return;
function hasHTMLDocument(win) win && win.document && win.document instanceof HTMLDocument
let win = window.document.commandDispatcher.focusedWindow;
let elem = window.document.commandDispatcher.focusedElement;
if (win && win.top == content && liberator.has("tabs"))
tabs.localStore.focusedFrame = win;
try {
if (elem && elem.readOnly)
return;
if ((elem instanceof HTMLInputElement && /^(text|password)$/.test(elem.type)) ||
(elem instanceof HTMLSelectElement)) {
liberator.mode = modes.INSERT;
if (hasHTMLDocument(win))
buffer.lastInputField = elem;
return;
}
if (elem instanceof HTMLEmbedElement || elem instanceof HTMLObjectElement) {
liberator.mode = modes.EMBED;
return;
}
if (elem instanceof HTMLTextAreaElement || (elem && elem.contentEditable == "true")) {
if (options["insertmode"])
modes.set(modes.INSERT);
else if (elem.selectionEnd - elem.selectionStart > 0)
modes.set(modes.VISUAL, modes.TEXTAREA);
else
modes.main = modes.TEXTAREA;
if (hasHTMLDocument(win))
buffer.lastInputField = elem;
return;
}
if (config.focusChange)
return void config.focusChange(win);
let urlbar = document.getElementById("urlbar");
if (elem == null && urlbar && urlbar.inputField == this._lastFocus)
liberator.threadYield(true);
if (liberator.mode & (modes.EMBED | modes.INSERT | modes.TEXTAREA | modes.VISUAL))
modes.reset();
}
finally {
this._lastFocus = elem;
}
},
onSelectionChange: function (event) {
let couldCopy = false;
let controller = document.commandDispatcher.getControllerForCommand("cmd_copy");
if (controller && controller.isCommandEnabled("cmd_copy"))
couldCopy = true;
if (liberator.mode != modes.VISUAL) {
if (couldCopy) {
if ((liberator.mode == modes.TEXTAREA ||
(modes.extended & modes.TEXTAREA))
&& !options["insertmode"])
modes.set(modes.VISUAL, modes.TEXTAREA);
else if (liberator.mode == modes.CARET)
modes.set(modes.VISUAL, modes.CARET);
}
}
// XXX: disabled, as i think automatically starting visual caret mode does more harm than help
// else
// {
// if (!couldCopy && modes.extended & modes.CARET)
// liberator.mode = modes.CARET;
// }
},
/**
* The global escape key handler. This is called in ALL modes.
*/
onEscape: function () {
if (modes.passNextKey)
return;
if (modes.passAllKeys) {
modes.passAllKeys = false;
return;
}
switch (liberator.mode) {
case modes.NORMAL:
// clear any selection made
let selection = window.content.getSelection();
try { // a simple if (selection) does not seem to work
selection.collapseToStart();
}
catch (e) {}
modes.reset();
break;
case modes.VISUAL:
if (modes.extended & modes.TEXTAREA)
liberator.mode = modes.TEXTAREA;
else if (modes.extended & modes.CARET)
liberator.mode = modes.CARET;
break;
case modes.CARET:
// setting this option will trigger an observer which will
// take care of all other details like setting the NORMAL
// mode
options.setPref("accessibility.browsewithcaret", false);
break;
case modes.TEXTAREA:
// TODO: different behaviour for text areas and other input
// fields seems unnecessarily complicated. If the user
// likes Vi-mode then they probably like it for all input
// fields, if not they can enter it explicitly for only
// text areas. The mode name TEXTAREA is confusing and
// would be better replaced with something indicating that
// it's a Vi editing mode. Extended modes really need to be
// displayed too. --djk
function isInputField() {
let elem = liberator.focus;
return ((elem instanceof HTMLInputElement && !/image/.test(elem.type))
|| elem instanceof HTMLIsIndexElement);
}
if (options["insertmode"] || isInputField())
liberator.mode = modes.INSERT;
else
modes.reset();
break;
case modes.INSERT:
if ((modes.extended & modes.TEXTAREA))
liberator.mode = modes.TEXTAREA;
else
modes.reset();
break;
default: // HINTS, CUSTOM or COMMAND_LINE
modes.reset();
break;
}
},
// this keypress handler gets always called first, even if e.g.
// the commandline has focus
onKeyPress: function (event) {
function isEscapeKey(key) key == "<Esc>" || key == "<C-[>";
function killEvent() {
event.preventDefault();
event.stopPropagation();
}
let key = events.toString(event);
if (!key)
return;
if (modes.isRecording) {
if (key == "q") { // TODO: should not be hardcoded
modes.isRecording = false;
liberator.log("Recorded " + this._currentMacro + ": " + this._macros.get(this._currentMacro), 9);
liberator.echomsg("Recorded macro '" + this._currentMacro + "'");
return void killEvent();
}
else if (!mappings.hasMap(liberator.mode, this._input.buffer + key))
this._macros.set(this._currentMacro, this._macros.get(this._currentMacro) + key);
}
if (key == "<C-c>")
liberator.interrupted = true;
// feedingKeys needs to be separate from interrupted so
// we can differentiate between a recorded <C-c>
// interrupting whatever it's started and a real <C-c>
// interrupting our playback.
if (events.feedingKeys && !event.isMacro) {
if (key == "<C-c>") {
events.feedingKeys = false;
if (modes.isReplaying) {
modes.isReplaying = false;
setTimeout(function () { liberator.echomsg("Canceled playback of macro '" + this._lastMacro + "'"); }, 100);
}
}
else
events.duringFeed.push(event);
return void killEvent();
}
try {
let stop = false;
let win = document.commandDispatcher.focusedWindow;
if (win && win.document && win.document.designMode == "on" && !config.isComposeWindow)
stop = true;
// menus have their own command handlers
if (modes.extended & modes.MENU)
stop = true;
// handle Escape-one-key mode (Ctrl-v)
else if (modes.passNextKey && !modes.passAllKeys) {
modes.passNextKey = false;
stop = true;
}
// handle Escape-all-keys mode (Ctrl-q)
else if (modes.passAllKeys) {
if (modes.passNextKey)
modes.passNextKey = false; // and then let flow continue
else if (isEscapeKey(key) || key == "<C-v>")
; // let flow continue to handle these keys to cancel escape-all-keys mode
else
stop = true;
}
if (stop) {
this._input.buffer = "";
return;
}
stop = true; // set to false if we should NOT consume this event but let the host app handle it
// just forward event without checking any mappings when the MOW is open
if (liberator.mode == modes.COMMAND_LINE && (modes.extended & modes.OUTPUT_MULTILINE)) {
commandline.onMultilineOutputEvent(event);
return void killEvent();
}
// XXX: ugly hack for now pass certain keys to the host app as
// they are without beeping also fixes key navigation in combo
// boxes, submitting forms, etc.
// FIXME: breaks iabbr for now --mst
if (key in config.ignoreKeys && (config.ignoreKeys[key] & liberator.mode)) {
this._input.buffer = "";
return;
}
// TODO: handle middle click in content area
if (!isEscapeKey(key)) {
// custom mode...
if (liberator.mode == modes.CUSTOM) {
plugins.onEvent(event);
return void killEvent();
}
// All of these special cases for hint mode are driving
// me insane! -Kris
if (modes.extended & modes.HINTS) {
// under HINT mode, certain keys are redirected to hints.onEvent
if (key == "<Return>" || key == "<Tab>" || key == "<S-Tab>"
|| key == mappings.getMapLeader()
|| (key == "<BS>" && hints.previnput == "number")
|| (/^[0-9]$/.test(key) && !hints.escNumbers)) {
hints.onEvent(event);
this._input.buffer = "";
return void killEvent();
}
// others are left to generate the 'input' event or handled by the host app
return;
}
}
// FIXME (maybe): (is an ESC or C-] here): on HINTS mode, it enters
// into 'if (map && !skipMap) below. With that (or however) it
// triggers the onEscape part, where it resets mode. Here I just
// return true, with the effect that it also gets to there (for
// whatever reason). if that happens to be correct, well..
// XXX: why not just do that as well for HINTS mode actually?
if (liberator.mode == modes.CUSTOM)
return;
let inputStr = this._input.buffer + key;
let countStr = inputStr.match(/^[1-9][0-9]*|/)[0];
let candidateCommand = inputStr.substr(countStr.length);
let map = mappings[event.noremap ? "getDefault" : "get"](liberator.mode, candidateCommand);
let candidates = mappings.getCandidates(liberator.mode, candidateCommand);
if (candidates.length == 0 && !map) {
map = this._input.pendingMap;
this._input.pendingMap = null;
if (map && map.arg)
this._input.pendingArgMap = map;
}
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
if (countStr && !candidateCommand) {
// no count for insert mode mappings
if (!modes.mainMode.count || modes.mainMode.input)
stop = false;
else
this._input.buffer = inputStr;
}
else if (this._input.pendingArgMap) {
this._input.buffer = "";
let map = this._input.pendingArgMap;
this._input.pendingArgMap = null;
if (!isEscapeKey(key)) {
if (modes.isReplaying && !this.waitForPageLoad())
return;
map.execute(null, this._input.count, key);
}
}
// only follow a map if there isn't a longer possible mapping
// (allows you to do :map z yy, when zz is a longer mapping than z)
else if (map && !event.skipmap && candidates.length == 0) {
this._input.pendingMap = null;
this._input.count = parseInt(countStr, 10);
if (isNaN(this._input.count))
this._input.count = -1;
this._input.buffer = "";
if (map.arg) {
this._input.buffer = inputStr;
this._input.pendingArgMap = map;
}
else if (this._input.pendingMotionMap) {
if (!isEscapeKey(key))
this._input.pendingMotionMap.execute(candidateCommand, this._input.count, null);
this._input.pendingMotionMap = null;
}
// no count support for these commands yet
else if (map.motion) {
this._input.pendingMotionMap = map;
}
else {
if (modes.isReplaying && !this.waitForPageLoad())
return void killEvent();
let ret = map.execute(null, this._input.count);
if (map.route && ret)
stop = false;
}
}
else if (mappings.getCandidates(liberator.mode, candidateCommand).length > 0 && !event.skipmap) {
this._input.pendingMap = map;
this._input.buffer += key;
}
else { // if the key is neither a mapping nor the start of one
// the mode checking is necessary so that things like g<esc> do not beep
if (this._input.buffer != "" && !event.skipmap &&
(liberator.mode & (modes.INSERT | modes.COMMAND_LINE | modes.TEXTAREA)))
events.feedkeys(this._input.buffer, { noremap: true, skipmap: true });
this._input.buffer = "";
this._input.pendingArgMap = null;
this._input.pendingMotionMap = null;
this._input.pendingMap = null;
if (!isEscapeKey(key)) {
// allow key to be passed to the host app if we can't handle it
stop = false;
if (liberator.mode == modes.COMMAND_LINE) {
if (!(modes.extended & modes.INPUT_MULTILINE))
commandline.onEvent(event); // reroute event in command line mode
}
else if (!modes.mainMode.input)
liberator.beep();
}
}
if (stop)
killEvent();
}
finally {
let motionMap = (this._input.pendingMotionMap && this._input.pendingMotionMap.names[0]) || "";
statusline.updateInputBuffer(motionMap + this._input.buffer);
}
},
// this is need for sites like msn.com which focus the input field on keydown
onKeyUpOrDown: function (event) {
if (modes.passNextKey ^ modes.passAllKeys || Events.isInputElemFocused())
return;
event.stopPropagation();
},
// TODO: move to buffer.js?
/**
* The liberator document loading progress listener.
*/
progressListener: {
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIWebProgressListener,
Ci.nsIXULBrowserWindow
]),
// XXX: function may later be needed to detect a canceled synchronous openURL()
onStateChange: function (webProgress, request, flags, status) {
// STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also
// receive statechange events for loading images and other parts of the web page
if (flags & (Ci.nsIWebProgressListener.STATE_IS_DOCUMENT | Ci.nsIWebProgressListener.STATE_IS_WINDOW)) {
// This fires when the load event is initiated
// only thrown for the current tab, not when another tab changes
if (flags & Ci.nsIWebProgressListener.STATE_START) {
buffer.loaded = 0;
statusline.updateProgress(0);
autocommands.trigger("PageLoadPre", { url: buffer.URL });
// don't reset mode if a frame of the frameset gets reloaded which
// is not the focused frame
if (document.commandDispatcher.focusedWindow == webProgress.DOMWindow) {
setTimeout(function () { modes.reset(false); },
liberator.mode == modes.HINTS ? 500 : 0);
}
}
else if (flags & Ci.nsIWebProgressListener.STATE_STOP) {
buffer.loaded = (status == 0 ? 1 : 2);
statusline.updateUrl();
}
}
},
// for notifying the user about secure web pages
onSecurityChange: function (webProgress, request, state) {
// TODO: do something useful with STATE_SECURE_MED and STATE_SECURE_LOW
if (state & Ci.nsIWebProgressListener.STATE_IS_INSECURE)
statusline.setClass("insecure");
else if (state & Ci.nsIWebProgressListener.STATE_IS_BROKEN)
statusline.setClass("broken");
else if (state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
statusline.setClass("extended");
else if (state & Ci.nsIWebProgressListener.STATE_SECURE_HIGH)
statusline.setClass("secure");
},
onStatusChange: function (webProgress, request, status, message) {
statusline.updateUrl(message);
},
onProgressChange: function (webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
statusline.updateProgress(curTotalProgress/maxTotalProgress);
},
// happens when the users switches tabs
onLocationChange: function () {
statusline.updateUrl();
statusline.updateProgress();
autocommands.trigger("LocationChange", { url: buffer.URL });
// if this is not delayed we get the position of the old buffer
setTimeout(function () { statusline.updateBufferPosition(); }, 500);
},
// called at the very end of a page load
asyncUpdateUI: function () {
setTimeout(function () { statusline.updateUrl(); }, 100);
},
setOverLink: function (link, b) {
let ssli = options["showstatuslinks"];
if (link && ssli) {
if (ssli == 1)
statusline.updateUrl("Link: " + link);
else if (ssli == 2)
liberator.echo("Link: " + link, commandline.DISALLOW_MULTILINE);
}
if (link == "") {
if (ssli == 1)
statusline.updateUrl();
else if (ssli == 2)
modes.show();
}
},
// nsIXULBrowserWindow stubs
setJSDefaultStatus: function (status) {},
setJSStatus: function (status) {},
// Stub for something else, presumably. Not in any documented
// interface.
onLinkIconAvailable: function () {}
}
}, {
isInputElemFocused: function () {
let elem = liberator.focus;
return ((elem instanceof HTMLInputElement && !/image/.test(elem.type)) ||
elem instanceof HTMLTextAreaElement ||
elem instanceof HTMLIsIndexElement ||
elem instanceof HTMLObjectElement ||
elem instanceof HTMLEmbedElement);
},
}, {
commands: function () {
commands.add(["delmac[ros]"],
"Delete macros",
function (args) {
liberator.assert(!args.bang || !args.string, "E474: Invalid argument");
if (args.bang)
events.deleteMacros();
else if (args.string)
events.deleteMacros(args.string);
else
liberator.echoerr("E471: Argument required");
}, {
bang: true,
completer: function (context) completion.macro(context)
});
commands.add(["macros"],
"List all macros",
function (args) { completion.listCompleter("macro", args[0]); }, {
argCount: "?",
completer: function (context) completion.macro(context)
});
commands.add(["pl[ay]"],
"Replay a recorded macro",
function (args) { events.playMacro(args[0]); }, {
argCount: "1",
completer: function (context) completion.macro(context)
});
},
mappings: function () {
mappings.add(modes.all,
["<Esc>", "<C-[>"], "Focus content",
function () { events.onEscape(); });
// add the ":" mapping in all but insert mode mappings
mappings.add([modes.NORMAL, modes.PLAYER, modes.VISUAL, modes.HINTS, modes.MESSAGE, modes.COMPOSE, modes.CARET, modes.TEXTAREA],
[":"], "Enter command line mode",
function () { commandline.open(":", "", modes.EX); });
// focus events
mappings.add([modes.NORMAL, modes.PLAYER, modes.VISUAL, modes.CARET],
["<Tab>"], "Advance keyboard focus",
function () { document.commandDispatcher.advanceFocus(); });
mappings.add([modes.NORMAL, modes.PLAYER, modes.VISUAL, modes.CARET, modes.INSERT, modes.TEXTAREA],
["<S-Tab>"], "Rewind keyboard focus",
function () { document.commandDispatcher.rewindFocus(); });
mappings.add(modes.all,
["<C-z>"], "Temporarily ignore all " + config.name + " key bindings",
function () { modes.passAllKeys = true; });
mappings.add(modes.all,
["<C-v>"], "Pass through next key",
function () { modes.passNextKey = true; });
mappings.add(modes.all,
["<Nop>"], "Do nothing",
function () { return; });
// macros
mappings.add([modes.NORMAL, modes.PLAYER, modes.MESSAGE],
["q"], "Record a key sequence into a macro",
function (arg) { events.startRecording(arg); },
{ arg: true });
mappings.add([modes.NORMAL, modes.PLAYER, modes.MESSAGE],
["@"], "Play a macro",
function (count, arg) {
if (count < 1) count = 1;
while (count-- && events.playMacro(arg))
;
},
{ arg: true, count: true });
},
tabs: function () {
function triggerLoadAutocmd(name, doc) {
let args = {
url: doc.location.href,
title: doc.title
};
if (liberator.has("tabs")) {
args.tab = tabs.getContentIndex(doc) + 1;
args.doc = "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentDocument";
}
autocommands.trigger(name, args);
}
function onDOMContentLoaded(event) {
let doc = event.originalTarget;
if (doc instanceof HTMLDocument && !doc.defaultView.frameElement)
triggerLoadAutocmd("DOMLoad", doc);
}
// TODO: see what can be moved to onDOMContentLoaded()
function onPageLoad(event) {
if (event.originalTarget instanceof HTMLDocument) {
let doc = event.originalTarget;
// document is part of a frameset
if (doc.defaultView.frameElement) {
// hacky way to get rid of "Transfering data from ..." on sites with frames
// when you click on a link inside a frameset, because asyncUpdateUI
// is not triggered there (Gecko bug?)
setTimeout(function () { statusline.updateUrl(); }, 10);
return;
}
// code which should happen for all (also background) newly loaded tabs goes here:
// mark the buffer as loaded, we can't use buffer.loaded
// since that always refers to the current buffer, while doc can be
// any buffer, even in a background tab
doc.pageIsFullyLoaded = 1;
// code which is only relevant if the page load is the current tab goes here:
if (doc == getBrowser().contentDocument) {
// we want to stay in command mode after a page has loaded
// TODO: move somewhere else, as focusing can already happen earlier than on "load"
if (options["focuscontent"]) {
setTimeout(function () {
let focused = liberator.focus;
if (focused && (focused.value != null) && focused.value.length == 0)
focused.blur();
}, 0);
}
}
else // background tab
liberator.echomsg("Background tab loaded: " + doc.title || doc.location.href, 3);
triggerLoadAutocmd("PageLoad", doc);
}
}
let tabContainer = tabs.getBrowser().mTabContainer;
tabContainer.addEventListener("TabMove", function (event) {
statusline.updateTabCount(true);
}, false);
tabContainer.addEventListener("TabOpen", function (event) {
statusline.updateTabCount(true);
}, false);
tabContainer.addEventListener("TabClose", function (event) {
statusline.updateTabCount(true);
}, false);
tabContainer.addEventListener("TabSelect", function (event) {
// TODO: is all of that necessary?
// I vote no. --Kris
modes.reset();
statusline.updateTabCount(true);
tabs.updateSelectionHistory();
if (options["focuscontent"])
setTimeout(function () { liberator.focusContent(true); }, 10); // just make sure, that no widget has focus
}, false);
tabs.getBrowser().addEventListener("DOMContentLoaded", onDOMContentLoaded, true);
// this adds an event which is is called on each page load, even if the
// page is loaded in a background tab
tabs.getBrowser().addEventListener("load", onPageLoad, true);
// called when the active document is scrolled
tabs.getBrowser().addEventListener("scroll", function (event) {
statusline.updateBufferPosition();
modes.show();
}, null);
},
});
// vim: set fdm=marker sw=4 ts=4 et:
|