Make it easier to remove mode_line_adder functions from hooks
[conkeror.git] / modules / universal-argument.js
blob4ee5c8ba42ac647742f0c656b43bc52cf2a8c8af
1 /**
2  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
3  * (C) Copyright 2008 John Foerch
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 define_keymap("universal_argument_keymap");
11 interactive (
12     "universal-argument",
13     "Begin a numeric argument for the following command.",
14     function (ctx)
15     {
16         if (ctx.prefix_argument) {
17             if (typeof(ctx.prefix_argument) == "object") // must be array
18                 ctx.prefix_argument = [ctx.prefix_argument[0] * 4];
19         } else
20             ctx.prefix_argument = [4];
21         ctx.overlay_keymap = universal_argument_keymap;
22     },
23     $prefix = true);
25 interactive (
26     "universal-digit",
27     "Part of the numeric argument for the next command.",
28     function (ctx)
29     {
30         var digit = ctx.event.charCode - 48;
31         if (ctx.prefix_argument == null)
32             ctx.prefix_argument = digit;
33         else if (typeof(ctx.prefix_argument) == "object") { // array
34             if (ctx.prefix_argument[0] < 0)
35                 ctx.prefix_argument = -digit;
36             else
37                 ctx.prefix_argument = digit;
38         }
39         else if (ctx.prefix_argument < 0)
40             ctx.prefix_argument = ctx.prefix_argument * 10 - digit;
41         else
42             ctx.prefix_argument = ctx.prefix_argument * 10 + digit;
43     },
44     $prefix = true);
46 interactive (
47     "universal-negate",
48     "Part of the numeric argument for the next command.  "+
49         "This command negates the numeric argument.",
50     function universal_negate(ctx)
51     {
52         if (typeof ctx.prefix_argument == "object")
53             ctx.prefix_argument[0] = 0 - ctx.prefix_argument[0];
54         else
55             ctx.prefix_argument = 0 - ctx.prefix_argument;
56     },
57     $prefix = true);