mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 23:47:57 +01:00
Make 'extendedhinttags' a regexmap.
--HG-- extra : rebase_source : 1058b785925fd37bd73019b36da91e551e0f9206
This commit is contained in:
@@ -42,31 +42,30 @@ const Hints = Module("hints", {
|
||||
|
||||
const Mode = Hints.Mode;
|
||||
Mode.defaultValue("tags", function () function () options["hinttags"]);
|
||||
function extended() options["extendedhinttags"];
|
||||
function images() util.makeXPath(["img"]);
|
||||
Mode.prototype.__defineGetter__("xpath", function ()
|
||||
options.get("extendedhinttags").getKey(this.name, this.tags()));
|
||||
|
||||
this._hintModes = {
|
||||
";": Mode("Focus hint", function (elem) buffer.focusElement(elem), extended),
|
||||
"?": Mode("Show information for hint", function (elem) buffer.showElementInfo(elem), extended),
|
||||
s: Mode("Save hint", function (elem) buffer.saveLink(elem, true)),
|
||||
a: Mode("Save hint with prompt", function (elem) buffer.saveLink(elem, false)),
|
||||
f: Mode("Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () ["body"]),
|
||||
o: Mode("Follow hint", function (elem) buffer.followLink(elem, dactyl.CURRENT_TAB)),
|
||||
t: Mode("Follow hint in a new tab", function (elem) buffer.followLink(elem, dactyl.NEW_TAB)),
|
||||
b: Mode("Follow hint in a background tab", function (elem) buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB)),
|
||||
w: Mode("Follow hint in a new window", function (elem) buffer.followLink(elem, dactyl.NEW_WINDOW), extended),
|
||||
F: Mode("Open multiple hints in tabs", function (elem) { buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB); hints.show("F"); }),
|
||||
O: Mode("Generate an ':open URL' using hint", function (elem, loc) commandline.open(":", "open " + loc, modes.EX)),
|
||||
T: Mode("Generate a ':tabopen URL' using hint", function (elem, loc) commandline.open(":", "tabopen " + loc, modes.EX)),
|
||||
W: Mode("Generate a ':winopen URL' using hint", function (elem, loc) commandline.open(":", "winopen " + loc, modes.EX)),
|
||||
v: Mode("View hint source", function (elem, loc) buffer.viewSource(loc, false), extended),
|
||||
V: Mode("View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true), extended),
|
||||
y: Mode("Yank hint location", function (elem, loc) dactyl.clipboardWrite(loc, true)),
|
||||
Y: Mode("Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", true), extended),
|
||||
c: Mode("Open context menu", function (elem) buffer.openContextMenu(elem), extended),
|
||||
i: Mode("Show image", function (elem) dactyl.open(elem.src), images),
|
||||
I: Mode("Show image in a new tab", function (elem) dactyl.open(elem.src, dactyl.NEW_TAB), images)
|
||||
};
|
||||
this._hintModes = {};
|
||||
this.addMode(";", "Focus hint", function (elem) buffer.focusElement(elem));
|
||||
this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem));
|
||||
this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, true));
|
||||
this.addMode("a", "Save hint with prompt", function (elem) buffer.saveLink(elem, false));
|
||||
this.addMode("f", "Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () ["body"]);
|
||||
this.addMode("o", "Follow hint", function (elem) buffer.followLink(elem, dactyl.CURRENT_TAB));
|
||||
this.addMode("t", "Follow hint in a new tab", function (elem) buffer.followLink(elem, dactyl.NEW_TAB));
|
||||
this.addMode("b", "Follow hint in a background tab", function (elem) buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB));
|
||||
this.addMode("w", "Follow hint in a new window", function (elem) buffer.followLink(elem, dactyl.NEW_WINDOW));
|
||||
this.addMode("F", "Open multiple hints in tabs", function (elem) { buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB); hints.show("F"); });
|
||||
this.addMode("O", "Generate an ':open URL' using hint", function (elem, loc) commandline.open(":", "open " + loc, modes.EX));
|
||||
this.addMode("T", "Generate a ':tabopen URL' using hint", function (elem, loc) commandline.open(":", "tabopen " + loc, modes.EX));
|
||||
this.addMode("W", "Generate a ':winopen URL' using hint", function (elem, loc) commandline.open(":", "winopen " + loc, modes.EX));
|
||||
this.addMode("v", "View hint source", function (elem, loc) buffer.viewSource(loc, false));
|
||||
this.addMode("V", "View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true));
|
||||
this.addMode("y", "Yank hint location", function (elem, loc) dactyl.clipboardWrite(loc, true));
|
||||
this.addMode("Y", "Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", true));
|
||||
this.addMode("c", "Open context menu", function (elem) buffer.openContextMenu(elem));
|
||||
this.addMode("i", "Show image", function (elem) dactyl.open(elem.src));
|
||||
this.addMode("I", "Show image in a new tab", function (elem) dactyl.open(elem.src, dactyl.NEW_TAB));
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -260,7 +259,7 @@ const Hints = Module("hints", {
|
||||
|
||||
let baseNodeAbsolute = util.xmlToDom(<span highlight="Hint"/>, doc);
|
||||
|
||||
let res = util.evaluateXPath(this._hintMode.tags(), doc, null, true);
|
||||
let res = util.evaluateXPath(this._hintMode.xpath, doc, null, true);
|
||||
|
||||
let fragment = util.xmlToDom(<div highlight="hints"/>, doc);
|
||||
let start = this._pageHints.length;
|
||||
@@ -722,7 +721,7 @@ const Hints = Module("hints", {
|
||||
* @optional
|
||||
*/
|
||||
addMode: function (mode, prompt, action, tags) {
|
||||
this._hintModes[mode] = Hints.Mode.apply(Hints.Mode, Array.slice(arguments, 1));
|
||||
this._hintModes[mode] = Hints.Mode.apply(Hints.Mode, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1014,7 +1013,7 @@ const Hints = Module("hints", {
|
||||
return -1;
|
||||
},
|
||||
|
||||
Mode: Struct("prompt", "action", "tags")
|
||||
Mode: Struct("name", "prompt", "action", "tags")
|
||||
}, {
|
||||
mappings: function () {
|
||||
var myModes = config.browserModes;
|
||||
@@ -1069,7 +1068,7 @@ const Hints = Module("hints", {
|
||||
|
||||
options.add(["extendedhinttags", "eht"],
|
||||
"XPath string of hintable elements activated by ';'",
|
||||
"string", DEFAULT_HINTTAGS,
|
||||
"regexmap", "[iI]:" + Option.quote(util.makeXPath(["img"])),
|
||||
{ validator: checkXPath });
|
||||
|
||||
options.add(["hinttags", "ht"],
|
||||
|
||||
@@ -372,15 +372,15 @@ const Option = Class("Option", {
|
||||
*/
|
||||
SCOPE_BOTH: 3,
|
||||
|
||||
parseRegex: function (val, result) {
|
||||
let [, bang, val] = /^(!?)(.*)/.exec(val);
|
||||
let re = RegExp(val);
|
||||
parseRegex: function (value, result) {
|
||||
let [, bang, val] = /^(!?)(.*)/.exec(value);
|
||||
let re = RegExp(Option.dequote(val));
|
||||
re.bang = bang;
|
||||
re.result = arguments.length == 2 ? result : !bang;
|
||||
re.toString = function () Option.unparseRegex(this);
|
||||
return re;
|
||||
},
|
||||
unparseRegex: function (re) re.bang + Option.quote(re.source.replace(/\\(.)/g, function (m, n1) n1 == "/" ? n1 : m)) +
|
||||
unparseRegex: function (re) re.bang + Option.quote(re.source.replace(/\\(.)/g, function (m, n1) n1 == "/" ? n1 : m), /^!|:/) +
|
||||
(typeof re.result == "string" ? ":" + Option.quote(re.result) : ""),
|
||||
|
||||
getKey: {
|
||||
@@ -399,7 +399,7 @@ const Option = Class("Option", {
|
||||
joinValues: {
|
||||
charlist: function (vals) Commands.quote(vals.join("")),
|
||||
stringlist: function (vals) vals.map(Option.quote).join(","),
|
||||
stringmap: function (vals) [Option.quote(k) + ":" + Option.quote(v) for ([k, v] in Iterator(vals))].join(","),
|
||||
stringmap: function (vals) [Option.quote(k, /:/) + ":" + Option.quote(v) for ([k, v] in Iterator(vals))].join(","),
|
||||
regexlist: function (vals) vals.join(","),
|
||||
get regexmap() this.regexlist
|
||||
},
|
||||
@@ -409,11 +409,20 @@ const Option = Class("Option", {
|
||||
boolean: function (value) Option.dequote(value) == "true" || value == true ? true : false,
|
||||
charlist: function (value) Array.slice(Option.dequote(value)),
|
||||
stringlist: function (value) (value === "") ? [] : Option.splitList(value),
|
||||
stringmap: function (value) array(util.split(v, /:/g, 2) for (v in values(Option.splitList(value)))).toObject(),
|
||||
regexlist: function (value) (value === "") ? [] : Option.splitList(value).map(Option.parseRegex),
|
||||
regexmap: function (value) Option.splitList(value)
|
||||
.map(function (v) util.split(v, /:/g, 2))
|
||||
.map(function ([k, v]) v != null ? Option.parseRegex(k, v) : Option.parseRegex(".?", k))
|
||||
regexlist: function (value) (value === "") ? [] : Option.splitList(value, true).map(Option.parseRegex),
|
||||
stringmap: function (value) array.toObject(
|
||||
Option.splitList(value, true).map(function (v) {
|
||||
let [count, key, quote] = Commands.parseArg(v, /:/);
|
||||
return [key, Option.dequote(v.substr(count + 1))]
|
||||
})),
|
||||
regexmap: function (value)
|
||||
Option.splitList(value, true).map(function (v) {
|
||||
let [count, re, quote] = Commands.parseArg(v, /:/, true);
|
||||
v = Option.dequote(v.substr(count + 1));
|
||||
if (count === v.length)
|
||||
[v, re] = [re, ".?"];
|
||||
return Option.parseRegex(re, v);
|
||||
})
|
||||
},
|
||||
|
||||
dequote: function (value) {
|
||||
@@ -422,20 +431,20 @@ const Option = Class("Option", {
|
||||
Option._splitAt = 0;
|
||||
return arg;
|
||||
},
|
||||
splitList: function (value) {
|
||||
splitList: function (value, keepQuotes) {
|
||||
let res = [];
|
||||
Option._splitAt = 0;
|
||||
do {
|
||||
if (count !== undefined)
|
||||
Option._splitAt += count + 1;
|
||||
var [count, arg, quote] = Commands.parseArg(value, /,/);
|
||||
var [count, arg, quote] = Commands.parseArg(value, /,/, keepQuotes);
|
||||
Option._quote = quote; // FIXME
|
||||
res.push(arg);
|
||||
value = value.slice(count + 1);
|
||||
} while (value.length);
|
||||
return res;
|
||||
},
|
||||
quote: function quote(str) Commands.quoteArg[/[\s|"'\\,]|^$/.test(str) ? "'" : ""](str),
|
||||
quote: function quote(str, re) Commands.quoteArg[/[\s|"'\\,]|^$/.test(str) || re && re.test && re.test(str) ? "'" : ""](str, re),
|
||||
|
||||
ops: {
|
||||
boolean: function (operator, values, scope, invert) {
|
||||
|
||||
@@ -116,17 +116,11 @@
|
||||
<li tag=";I"><em>I</em> to open an image in a new tab.</li>
|
||||
</ul>
|
||||
|
||||
<!-- TODO: These are completely arbitrary and need to be
|
||||
- changed before release. Hopefully they will be...
|
||||
-->
|
||||
<p>
|
||||
Of the previous modes, the value of the <o>hinttags</o>
|
||||
option is used to choose the highlighted elements for
|
||||
the modes, <k>;;</k>, <k>;?</k>, <k>;w</k>, <k>;v</k>,
|
||||
<k>;V</k>, <k>;Y</k> and <k>;c</k>. The value of
|
||||
<o>extendedhinttags</o> is used to choose the elements
|
||||
for, <k>;s</k>, <k>;a</k>, <k>;o</k>, <k>;t</k>,
|
||||
<k>;b</k>, <k>;O</k>, <k>;T</k>, <k>;W</k>, <k>;y</k>,
|
||||
option is used to choose the highlighted elements,
|
||||
unless an override can be found in
|
||||
<o>extendedhinttags</o>.
|
||||
</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
@@ -51,10 +51,11 @@
|
||||
<dd>
|
||||
A comma-separated list of regular expressions. Expressions may be
|
||||
prefixed with a <em>!</em>, in which case the match will be negated. A
|
||||
literal <em>!</em> at the begining of the expression may be matched with
|
||||
<em>[!]</em>. Generally, the first matching regular expression is
|
||||
used. Any comma appearing within single or double quotes, or prefixed
|
||||
with a <em>\</em>, will not be treated as an item separator.
|
||||
literal <em>!</em> at the begining of the expression may be matched
|
||||
with <em>[!]</em> or by placing the regular expression in quotes.
|
||||
Generally, the first matching regular expression is used. Any comma
|
||||
appearing within single or double quotes, or prefixed with a
|
||||
<em>\</em>, will not be treated as an item separator.
|
||||
</dd>
|
||||
|
||||
<dt/><dd tag="regexmap"/>
|
||||
@@ -559,10 +560,14 @@
|
||||
<tags>'eht' 'extendedhinttags'</tags>
|
||||
<spec>'extendedhinttags' 'eht'</spec>
|
||||
<strut/>
|
||||
<type>string</type>
|
||||
<default>&hinttags;</default>
|
||||
<type>regexmap</type>
|
||||
<default>[iI]:'//img | //xhtml:img'</default>
|
||||
<description>
|
||||
<p>The XPath string of hintable elements activated by <k>;</k>.</p>
|
||||
<p>
|
||||
Defines specialized XPath expressions for arbitrary
|
||||
<t>extended-hints</t> modes. If no matches are found, the value of
|
||||
<o>hinttags</o> is used.
|
||||
</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
@@ -756,7 +761,12 @@
|
||||
<type>string</type>
|
||||
<default>&hinttags;</default>
|
||||
<description>
|
||||
<p>XPath string of hintable elements activated by <k>f</k> and <k>F</k></p>
|
||||
<p>
|
||||
The XPath string used to select for
|
||||
<link topic="hints">hinting</link>. Can be overridden for
|
||||
individual <t>extended-hints</t> modes with the
|
||||
<o>extendedhinttags</o> option.
|
||||
</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
operators, and = sign may no longer be quoted. This will break
|
||||
certain automatically-generated configuration files.
|
||||
See :help stringlist
|
||||
* IMPORTANT: 'extendedhinttags' is now a regexmap rather than a
|
||||
string.
|
||||
* Added 'altwildmode' and <A-Tab> commandline key binding.
|
||||
* Added 'autocomplete' option for specifying which completion
|
||||
groups should be auto-completed.
|
||||
|
||||
@@ -34,8 +34,6 @@ BUGS:
|
||||
|
||||
FEATURES:
|
||||
9 Add quoting help tag
|
||||
9 Fix the arbitrary distinction between 'hinttags' and
|
||||
'extendedhinttags'
|
||||
9 Support multiple bookmarks, -keyword, -tags in :delbmarks
|
||||
8 Document Caret and Visual modes.
|
||||
8 finish :help TODOs
|
||||
|
||||
Reference in New Issue
Block a user