Debian: Ignore command-in-menu-file-and-desktop-file lintian warning
[conkeror.git] / modules / mode.js
blob397843294aae300ddfdde7c784381d5c843685dd
1 /**
2  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 require("interactive.js");
10 define_keywords("$doc");
11 function define_global_mode (name, enable, disable) {
12     keywords(arguments, $doc = null);
13     var hyphen_name = name.replace(/_/g,"-");
14     var state = name + "_enabled";
15     this[state] = false;
16     var enable_hook_name = hyphen_name + "-enable-hook";
17     var disable_hook_name = hyphen_name + "-disable-hook";
18     define_hook(enable_hook_name);
19     define_hook(disable_hook_name);
20     var func = function (arg) {
21         var curstate = conkeror[state];
22         var newstate = (arg == null) ? !curstate : (arg > 0);
23         if (curstate == newstate)
24             return;
25         conkeror[state] = newstate;
26         if (newstate) {
27             enable();
28             conkeror[enable_hook_name].run();
29         } else {
30             disable();
31             conkeror[disable_hook_name].run();
32         }
33     };
34     this[name] = func;
35     interactive(hyphen_name, arguments.$doc, function (I) {
36         var arg = I.P;
37         func(arg && univ_arg_to_number(arg));
38         I.minibuffer.message(hyphen_name + (conkeror[state] ? " enabled" : " disabled"));
39     });
41 ignore_function_for_get_caller_source_code_reference("define_global_mode");
43 provide("mode");