bind "C-x left" and "C-x right" to buffer-previous and buffer-next
[conkeror/arlinius.git] / modules / mode.js
blob927abe2faeb33718ef550fc1785fdb5875331770
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 function define_global_mode (name, enable, disable) {
11     var hyphen_name = name.replace("_","-","g");
12     var state = name + "_enabled";
13     this[state] = false;
14     var enable_hook_name = hyphen_name + "-enable-hook";
15     var disable_hook_name = hyphen_name + "-disable-hook";
16     define_hook(enable_hook_name);
17     define_hook(disable_hook_name);
18     var func = function (arg) {
19         var curstate = conkeror[state];
20         var newstate = (arg == null) ? !curstate : (arg > 0);
21         if (curstate == newstate)
22             return;
23         conkeror[state] = newstate;
24         if (newstate) {
25             enable();
26             conkeror[enable_hook_name].run();
27         } else {
28             disable();
29             conkeror[disable_hook_name].run();
30         }
31     };
32     this[name] = func;
33     interactive(hyphen_name, null, function (I) {
34         var arg = I.P;
35         func(arg && univ_arg_to_number(arg));
36         I.minibuffer.message(hyphen_name + (conkeror[state] ? " enabled" : " disabled"));
37     });
39 ignore_function_for_get_caller_source_code_reference("define_global_mode");