File: universal-argument.js

package info (click to toggle)
conkeror 0.9.2%2Bgit100804-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,680 kB
  • ctags: 1,182
  • sloc: sh: 547; ansic: 272; xml: 107; makefile: 79
file content (56 lines) | stat: -rw-r--r-- 1,788 bytes parent folder | download
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
/**
 * (C) Copyright 2004-2007 Shawn Betts
 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
 * (C) Copyright 2008 John Foerch
 *
 * Use, modification, and distribution are subject to the terms specified in the
 * COPYING file.
**/

in_module(null);

define_keymap("universal_argument_keymap");

interactive("universal-argument",
    "Begin a numeric argument for the following command.",
    function (I) {
        if (I.prefix_argument) {
            if (typeof I.prefix_argument == "object") // must be array
                I.prefix_argument = [I.prefix_argument[0] * 4];
        } else
            I.prefix_argument = [4];
        I.overlay_keymap = universal_argument_keymap;
    },
    $prefix = true);

interactive("universal-digit",
    "Part of the numeric argument for the next command.",
    function (I) {
        var digit = I.event.charCode - 48;
        if (I.prefix_argument == null)
            I.prefix_argument = digit;
        else if (typeof I.prefix_argument == "object") { // array
            if (I.prefix_argument[0] < 0)
                I.prefix_argument = -digit;
            else
                I.prefix_argument = digit;
        }
        else if (I.prefix_argument < 0)
            I.prefix_argument = I.prefix_argument * 10 - digit;
        else
            I.prefix_argument = I.prefix_argument * 10 + digit;
    },
    $prefix = true);

interactive("universal-negate",
    "Part of the numeric argument for the next command.  "+
    "This command negates the numeric argument.",
    function universal_negate (I) {
        if (typeof I.prefix_argument == "object")
            I.prefix_argument[0] = 0 - I.prefix_argument[0];
        else
            I.prefix_argument = 0 - I.prefix_argument;
    },
    $prefix = true);

provide("universal-argument");