mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 08:37:57 +01:00
add support for :set all and :set all& to list and reset all options
This commit is contained in:
@@ -915,6 +915,7 @@ function Commands() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 1 2 3 4 5 6
|
||||||
var matches = args.match(/^\s*(no|inv)?([a-z]+)([?&!])?(([+-])?=(.*))?/);
|
var matches = args.match(/^\s*(no|inv)?([a-z]+)([?&!])?(([+-])?=(.*))?/);
|
||||||
if (!matches)
|
if (!matches)
|
||||||
{
|
{
|
||||||
@@ -923,26 +924,36 @@ function Commands() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var no = false;
|
var no = false;
|
||||||
if (matches[1] == 'no')
|
if (matches[1] == "no")
|
||||||
no = true;
|
no = true;
|
||||||
|
|
||||||
var opt = matches[2];
|
var opt = matches[2];
|
||||||
|
|
||||||
|
var all = false;
|
||||||
|
if (opt == "all")
|
||||||
|
all = true;
|
||||||
|
|
||||||
var option = vimperator.options.get(opt);
|
var option = vimperator.options.get(opt);
|
||||||
if (!option)
|
if (!option && !all)
|
||||||
{
|
{
|
||||||
vimperator.echoerr("E518: Unknown option: " + opt);
|
vimperator.echoerr("E518: Unknown option: " + opt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var get = false;
|
var get = false;
|
||||||
if (matches[3] == "?" || (option.type != 'boolean' && matches[4] === undefined))
|
if (all || matches[3] == "?" || (option.type != "boolean" && matches[4] === undefined))
|
||||||
get = true;
|
get = true;
|
||||||
|
|
||||||
var reset = false;
|
var reset = false;
|
||||||
if (matches[3] == "&")
|
if (matches[3] == "&")
|
||||||
reset = true;
|
reset = true;
|
||||||
|
|
||||||
var invert = false;
|
var invert = false;
|
||||||
if (matches[1] == 'inv' || matches[3] == "!")
|
if (matches[1] == "inv" || matches[3] == "!")
|
||||||
invert = true;
|
invert = true;
|
||||||
|
|
||||||
var oper = matches[5];
|
var oper = matches[5];
|
||||||
|
|
||||||
var val = matches[6];
|
var val = matches[6];
|
||||||
if (val === undefined)
|
if (val === undefined)
|
||||||
val = "";
|
val = "";
|
||||||
@@ -950,17 +961,32 @@ function Commands() //{{{
|
|||||||
// reset a variable to its default value
|
// reset a variable to its default value
|
||||||
// TODO: remove the value from about:config instead of setting it to the current default value
|
// TODO: remove the value from about:config instead of setting it to the current default value
|
||||||
if (reset)
|
if (reset)
|
||||||
|
{
|
||||||
|
if (all)
|
||||||
|
{
|
||||||
|
for (let opt in vimperator.options)
|
||||||
|
opt.value = opt.default_value;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
option.value = option.default_value;
|
option.value = option.default_value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// read access
|
// read access
|
||||||
else if (get)
|
else if (get)
|
||||||
{
|
{
|
||||||
if (option.type == 'boolean')
|
if (all)
|
||||||
|
{
|
||||||
|
vimperator.options.list();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (option.type == "boolean")
|
||||||
vimperator.echo((option.value ? " " : "no") + option.name);
|
vimperator.echo((option.value ? " " : "no") + option.name);
|
||||||
else
|
else
|
||||||
vimperator.echo(" " + option.name + "=" + option.value);
|
vimperator.echo(" " + option.name + "=" + option.value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// write access
|
// write access
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1023,7 +1049,8 @@ function Commands() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
usage: ["se[t][!]", "se[t] {option}?", "se[t] [no]{option}", "se[t] {option}[+-]={value}", "se[t] {option}! | inv{option}", "se[t] {option}&"],
|
usage: ["se[t][!]", "se[t] {option}?", "se[t] [no]{option}", "se[t] {option}[+-]={value}", "se[t] {option}! | inv{option}", "se[t] {option}&"],
|
||||||
short_help: "Set an option", help: "Permanently change an option. In contrast to Vim options are stored throughout sessions.<br/>" +
|
short_help: "Set an option",
|
||||||
|
help: "Permanently change an option. In contrast to Vim options are stored throughout sessions.<br/>" +
|
||||||
"<code class=\"command\">:set</code> without an argument opens <code>about:config</code> in a new tab to change advanced Firefox options.<br/>" +
|
"<code class=\"command\">:set</code> without an argument opens <code>about:config</code> in a new tab to change advanced Firefox options.<br/>" +
|
||||||
"<code class=\"command\">:set!</code> opens the GUI preference panel from Firefox in a new tab.<br/>" +
|
"<code class=\"command\">:set!</code> opens the GUI preference panel from Firefox in a new tab.<br/>" +
|
||||||
"There are three types of options: boolean, number and string. " +
|
"There are three types of options: boolean, number and string. " +
|
||||||
@@ -1032,7 +1059,8 @@ function Commands() //{{{
|
|||||||
"<code class=\"command\">:set option!</code> and <code class=\"command\">:set invoption</code> invert the value of a boolean option.<br/>" +
|
"<code class=\"command\">:set option!</code> and <code class=\"command\">:set invoption</code> invert the value of a boolean option.<br/>" +
|
||||||
"<code class=\"command\">:set option?</code> or <code class=\"command\">:set option</code>(for string and list options) shows the current value of an option.<br/>" +
|
"<code class=\"command\">:set option?</code> or <code class=\"command\">:set option</code>(for string and list options) shows the current value of an option.<br/>" +
|
||||||
"<code class=\"command\">:set option&</code> resets an option to its default value.<br/>" +
|
"<code class=\"command\">:set option&</code> resets an option to its default value.<br/>" +
|
||||||
"<code class=\"command\">:set option+={value}</code> and <code class=\"command\">:set option-={value}</code> will add/subtract {value} to a number option and append/remove {value} to a string option.<br/>",
|
"<code class=\"command\">:set option+={value}</code> and <code class=\"command\">:set option-={value}</code> will add/subtract {value} to a number option and append/remove {value} to a string option.<br/>" +
|
||||||
|
"<code class=\"command\">:set all</code> will show the current value of all options and <code class=\"command\">:set all&</code> will reset all options to their default values.<br/>",
|
||||||
completer: function(filter) { return vimperator.completion.get_options_completions(filter); }
|
completer: function(filter) { return vimperator.completion.get_options_completions(filter); }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -271,6 +271,34 @@ function Options() //{{{
|
|||||||
storePreference('dom.popup_allowed_events', popup_allowed_events);
|
storePreference('dom.popup_allowed_events', popup_allowed_events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.list = function()
|
||||||
|
{
|
||||||
|
// TODO: columns like Vim?
|
||||||
|
var list = "<table style=\"white-space: nowrap;\">" +
|
||||||
|
"<tr align=\"left\" style=\"color: magenta\"><th>--- Options ---</th></tr>";
|
||||||
|
var name, value;
|
||||||
|
|
||||||
|
for (var i = 0; i < options.length; i++)
|
||||||
|
{
|
||||||
|
name = options[i].name;
|
||||||
|
value = options[i].value;
|
||||||
|
|
||||||
|
if (options[i].type == "boolean")
|
||||||
|
{
|
||||||
|
name = value ? " " + name : "no" + name;
|
||||||
|
list += "<tr><td>" + name + "</td></tr>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list += "<tr><td>" + " " + name + "=" + value + "</td></tr>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list += "</table>";
|
||||||
|
|
||||||
|
vimperator.commandline.echo(list, true);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: separate Preferences from Options? Would these utility functions
|
// TODO: separate Preferences from Options? Would these utility functions
|
||||||
// be better placed in the 'core' vimperator namespace somewhere?
|
// be better placed in the 'core' vimperator namespace somewhere?
|
||||||
Options.setPref = function(name, value)
|
Options.setPref = function(name, value)
|
||||||
|
|||||||
Reference in New Issue
Block a user