mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-22 06:35:44 +01:00
Add -append options to :hi and :sty. Fix some bugs (no, I don't know which bugs)
This commit is contained in:
@@ -41,7 +41,11 @@ function Command(specs, description, action, extraInfo) //{{{
|
||||
// 'abc', 'abcdef'
|
||||
function parseSpecs(specs)
|
||||
{
|
||||
let shortNames = longNames = names = [];
|
||||
// Whoever wrote the following should be ashamed. :(
|
||||
// let shortNames = longNames = names = [];
|
||||
let names = [];
|
||||
let longNames = [];
|
||||
let shortNames = [];
|
||||
|
||||
for (let [,spec] in Iterator(specs))
|
||||
{
|
||||
@@ -247,14 +251,11 @@ function Commands() //{{{
|
||||
if (!command)
|
||||
return false;
|
||||
|
||||
for (let i = 0; i < exCommands.length; i++)
|
||||
if (exCommands.some(function (c) c.name == command.name))
|
||||
{
|
||||
if (exCommands[i].name == command.name)
|
||||
{
|
||||
// never replace for now
|
||||
liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1);
|
||||
return false;
|
||||
}
|
||||
// never replace for now
|
||||
liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
exCommands.push(command);
|
||||
|
||||
@@ -82,26 +82,22 @@ const liberator = (function () //{{{
|
||||
{
|
||||
setter: function (value)
|
||||
{
|
||||
var guioptions = config.guioptions || {};
|
||||
|
||||
for (let option in guioptions)
|
||||
for (let [opt, ids] in Iterator(config.guioptions || {}))
|
||||
{
|
||||
if (option in guioptions)
|
||||
ids.forEach(function (id)
|
||||
{
|
||||
guioptions[option].forEach(function (elem) {
|
||||
try
|
||||
{
|
||||
document.getElementById(elem).collapsed = (value.indexOf(option.toString()) < 0);
|
||||
}
|
||||
catch (e) {}
|
||||
});
|
||||
}
|
||||
try
|
||||
{
|
||||
document.getElementById(id).collapsed = (value.indexOf(opt) < 0);
|
||||
}
|
||||
catch (e) {}
|
||||
});
|
||||
}
|
||||
let classes = tabopts.filter(function (o) value.indexOf(o[0]) == -1)
|
||||
.map(function (a) a[3])
|
||||
if (!classes.length)
|
||||
{
|
||||
storage.styles.removeSheet("taboptions", null, null, null, true);
|
||||
styles.removeSheet("taboptions", null, null, null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -652,7 +648,7 @@ const liberator = (function () //{{{
|
||||
message = util.objectToString(message);
|
||||
else
|
||||
message += "\n";
|
||||
dump(config.name.toLowerCase() + ": " + message);
|
||||
dump(("config" in modules && config.name.toLowerCase()) + ": " + message);
|
||||
},
|
||||
|
||||
dumpStack: function (msg)
|
||||
|
||||
@@ -170,7 +170,7 @@ function Mappings() //{{{
|
||||
{
|
||||
flags: Mappings.flags.COUNT,
|
||||
rhs: rhs,
|
||||
noremap: noremap,
|
||||
noremap: !!noremap,
|
||||
silent: "<silent>" in args
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,22 +86,24 @@ function Highlights(name, store, serial)
|
||||
Highlight.defaultValue("value", function () this.default);
|
||||
Highlight.prototype.toString = function () [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join(", ");
|
||||
|
||||
this.__iterator__ = function () (v for ([k,v] in Iterator(highlight)));
|
||||
function keys() [k for ([k, v] in Iterator(highlight))].sort();
|
||||
this.__iterator__ = function () (highlight[v] for ([k,v] in Iterator(keys())));
|
||||
|
||||
this.get = function (k) highlight[k];
|
||||
this.set = function (key, newStyle, force)
|
||||
this.set = function (key, newStyle, force, append)
|
||||
{
|
||||
let [, class, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/);
|
||||
|
||||
if (!(class in highlight))
|
||||
return "Unknown highlight keyword";
|
||||
|
||||
let style = highlight[key] || new Highlight(key);
|
||||
styles.removeSheet(style.selector, null, null, null, true);
|
||||
|
||||
if (append)
|
||||
newStyle = (style.value || "").replace(/;?\s*$/, "; " + newStyle);
|
||||
if (/^\s*$/.test(newStyle))
|
||||
newStyle = null;
|
||||
|
||||
let style = highlight[key] || new Highlight(key);
|
||||
styles.removeSheet(style.selector, null, null, true);
|
||||
|
||||
if (newStyle == null)
|
||||
{
|
||||
if (style.default == null)
|
||||
@@ -175,7 +177,7 @@ function Styles(name, store, serial)
|
||||
|
||||
let sheet = sheets.filter(function (s) s.sites.join(",") == filter && s.css == css)[0];
|
||||
if (!sheet)
|
||||
sheet = new Sheet(name, filter.split(","), css, null);
|
||||
sheet = new Sheet(name, filter.split(",").filter(function (s) s), css, null);
|
||||
|
||||
if (sheet.ref == null) // Not registered yet
|
||||
{
|
||||
@@ -204,7 +206,7 @@ function Styles(name, store, serial)
|
||||
let names = system ? systemNames : userNames;
|
||||
|
||||
// Grossly inefficient.
|
||||
let matches = [k for ([k, v] in sheets)];
|
||||
let matches = [k for ([k, v] in Iterator(sheets))];
|
||||
if (index)
|
||||
matches = String(index).split(",").filter(function (i) i in sheets);
|
||||
if (name)
|
||||
@@ -213,8 +215,8 @@ function Styles(name, store, serial)
|
||||
matches = matches.filter(function (i) sheets[i].css == css);
|
||||
if (filter)
|
||||
matches = matches.filter(function (i) sheets[i].sites.indexOf(filter) >= 0);
|
||||
return matches;
|
||||
},
|
||||
return matches.map(function (i) [i, sheets[i]]);
|
||||
};
|
||||
|
||||
this.removeSheet = function (name, filter, css, index, system)
|
||||
{
|
||||
@@ -233,9 +235,8 @@ function Styles(name, store, serial)
|
||||
if (matches.length == 0)
|
||||
return;
|
||||
|
||||
for (let [,i] in Iterator(matches.reverse()))
|
||||
for (let [,[i, sheet]] in Iterator(matches.reverse()))
|
||||
{
|
||||
let sheet = sheets[i];
|
||||
if (name)
|
||||
{
|
||||
sheet.ref.splice(sheet.ref.indexOf(name));
|
||||
@@ -247,6 +248,7 @@ function Styles(name, store, serial)
|
||||
this.unregisterSheet(cssUri(wrapCSS(sheet)));
|
||||
}
|
||||
// Filter out the given site, and re-add if there are any left
|
||||
// This could have unintended consequences
|
||||
if (filter)
|
||||
{
|
||||
let sites = sheet.sites.filter(function (f) f != filter);
|
||||
@@ -381,6 +383,15 @@ liberator.registerObserver("load_commands", function ()
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("-append" in args)
|
||||
{
|
||||
let sheet = styles.findSheets(name, null, null, null, false)[0];
|
||||
if (sheet)
|
||||
{
|
||||
filter = sheet[1].sites.concat(filter).join(",");
|
||||
css = sheet[1].css.replace(/;?\s*$/, "; " + css);
|
||||
}
|
||||
}
|
||||
let err = styles.addSheet(name, filter, css, false, special);
|
||||
if (err)
|
||||
liberator.echoerr(err);
|
||||
@@ -402,7 +413,8 @@ liberator.registerObserver("load_commands", function ()
|
||||
bang: true,
|
||||
hereDoc: true,
|
||||
literal: true,
|
||||
options: [[["-name", "-n"], commands.OPTION_STRING]],
|
||||
options: [[["-name", "-n"], commands.OPTION_STRING],
|
||||
[["-append", "-a"], commands.OPTION_NOARG]],
|
||||
serial: function () [
|
||||
{
|
||||
command: this.name,
|
||||
@@ -437,6 +449,7 @@ liberator.registerObserver("load_commands", function ()
|
||||
function (args, special)
|
||||
{
|
||||
let style = <![CDATA[
|
||||
;
|
||||
display: inline-block !important;
|
||||
position: static !important;
|
||||
width: 3em !important; min-width: 3em !important; max-width: 3em !important;
|
||||
@@ -458,7 +471,7 @@ liberator.registerObserver("load_commands", function ()
|
||||
commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||
return;
|
||||
}
|
||||
let error = highlight.set(key, css, special);
|
||||
let error = highlight.set(key, css, special, "-append" in args);
|
||||
if (error)
|
||||
liberator.echoerr(error);
|
||||
},
|
||||
@@ -472,6 +485,7 @@ liberator.registerObserver("load_commands", function ()
|
||||
bang: true,
|
||||
hereDoc: true,
|
||||
literal: true,
|
||||
options: [[["-append", "-a"], commands.OPTION_NOARG]],
|
||||
serial: function () [
|
||||
{
|
||||
command: this.name,
|
||||
|
||||
@@ -494,11 +494,11 @@ function Struct()
|
||||
ConStructor.defaultValue = function (key, val)
|
||||
{
|
||||
let i = args.indexOf(key);
|
||||
let _i = "_" + i;
|
||||
ConStructor.prototype.__defineGetter__(i, val);
|
||||
ConStructor.prototype.__defineSetter__(i, function (val) {
|
||||
this.__defineGetter__(i, function () this[_i]);
|
||||
this[_i] = val;
|
||||
let value = val;
|
||||
this.__defineGetter__(i, function () value);
|
||||
this.__defineSetter__(i, function (val) { value = val });
|
||||
});
|
||||
};
|
||||
return self.constructor = ConStructor;
|
||||
|
||||
Reference in New Issue
Block a user