1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 23:37:58 +01:00

Make 'extendedhinttags' a regexmap.

--HG--
extra : rebase_source : 1058b785925fd37bd73019b36da91e551e0f9206
This commit is contained in:
Kris Maglione
2010-09-25 14:57:12 -04:00
parent 6eb58f63c3
commit 4a2c703854
6 changed files with 72 additions and 60 deletions

View File

@@ -42,31 +42,30 @@ const Hints = Module("hints", {
const Mode = Hints.Mode; const Mode = Hints.Mode;
Mode.defaultValue("tags", function () function () options["hinttags"]); Mode.defaultValue("tags", function () function () options["hinttags"]);
function extended() options["extendedhinttags"]; Mode.prototype.__defineGetter__("xpath", function ()
function images() util.makeXPath(["img"]); options.get("extendedhinttags").getKey(this.name, this.tags()));
this._hintModes = { this._hintModes = {};
";": Mode("Focus hint", function (elem) buffer.focusElement(elem), extended), this.addMode(";", "Focus hint", function (elem) buffer.focusElement(elem));
"?": Mode("Show information for hint", function (elem) buffer.showElementInfo(elem), extended), this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem));
s: Mode("Save hint", function (elem) buffer.saveLink(elem, true)), this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, true));
a: Mode("Save hint with prompt", function (elem) buffer.saveLink(elem, false)), this.addMode("a", "Save hint with prompt", function (elem) buffer.saveLink(elem, false));
f: Mode("Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () ["body"]), this.addMode("f", "Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () ["body"]);
o: Mode("Follow hint", function (elem) buffer.followLink(elem, dactyl.CURRENT_TAB)), this.addMode("o", "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)), this.addMode("t", "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)), this.addMode("b", "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), this.addMode("w", "Follow hint in a new window", function (elem) buffer.followLink(elem, dactyl.NEW_WINDOW));
F: Mode("Open multiple hints in tabs", function (elem) { buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB); hints.show("F"); }), this.addMode("F", "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)), this.addMode("O", "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)), this.addMode("T", "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)), this.addMode("W", "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), this.addMode("v", "View hint source", function (elem, loc) buffer.viewSource(loc, false));
V: Mode("View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true), extended), this.addMode("V", "View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true));
y: Mode("Yank hint location", function (elem, loc) dactyl.clipboardWrite(loc, true)), this.addMode("y", "Yank hint location", function (elem, loc) dactyl.clipboardWrite(loc, true));
Y: Mode("Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", true), extended), this.addMode("Y", "Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", true));
c: Mode("Open context menu", function (elem) buffer.openContextMenu(elem), extended), this.addMode("c", "Open context menu", function (elem) buffer.openContextMenu(elem));
i: Mode("Show image", function (elem) dactyl.open(elem.src), images), this.addMode("i", "Show image", function (elem) dactyl.open(elem.src));
I: Mode("Show image in a new tab", function (elem) dactyl.open(elem.src, dactyl.NEW_TAB), images) 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 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 fragment = util.xmlToDom(<div highlight="hints"/>, doc);
let start = this._pageHints.length; let start = this._pageHints.length;
@@ -722,7 +721,7 @@ const Hints = Module("hints", {
* @optional * @optional
*/ */
addMode: function (mode, prompt, action, tags) { 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; return -1;
}, },
Mode: Struct("prompt", "action", "tags") Mode: Struct("name", "prompt", "action", "tags")
}, { }, {
mappings: function () { mappings: function () {
var myModes = config.browserModes; var myModes = config.browserModes;
@@ -1069,7 +1068,7 @@ const Hints = Module("hints", {
options.add(["extendedhinttags", "eht"], options.add(["extendedhinttags", "eht"],
"XPath string of hintable elements activated by ';'", "XPath string of hintable elements activated by ';'",
"string", DEFAULT_HINTTAGS, "regexmap", "[iI]:" + Option.quote(util.makeXPath(["img"])),
{ validator: checkXPath }); { validator: checkXPath });
options.add(["hinttags", "ht"], options.add(["hinttags", "ht"],

View File

@@ -372,15 +372,15 @@ const Option = Class("Option", {
*/ */
SCOPE_BOTH: 3, SCOPE_BOTH: 3,
parseRegex: function (val, result) { parseRegex: function (value, result) {
let [, bang, val] = /^(!?)(.*)/.exec(val); let [, bang, val] = /^(!?)(.*)/.exec(value);
let re = RegExp(val); let re = RegExp(Option.dequote(val));
re.bang = bang; re.bang = bang;
re.result = arguments.length == 2 ? result : !bang; re.result = arguments.length == 2 ? result : !bang;
re.toString = function () Option.unparseRegex(this); re.toString = function () Option.unparseRegex(this);
return re; 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) : ""), (typeof re.result == "string" ? ":" + Option.quote(re.result) : ""),
getKey: { getKey: {
@@ -399,7 +399,7 @@ const Option = Class("Option", {
joinValues: { joinValues: {
charlist: function (vals) Commands.quote(vals.join("")), charlist: function (vals) Commands.quote(vals.join("")),
stringlist: function (vals) vals.map(Option.quote).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(","), regexlist: function (vals) vals.join(","),
get regexmap() this.regexlist get regexmap() this.regexlist
}, },
@@ -409,11 +409,20 @@ const Option = Class("Option", {
boolean: function (value) Option.dequote(value) == "true" || value == true ? true : false, boolean: function (value) Option.dequote(value) == "true" || value == true ? true : false,
charlist: function (value) Array.slice(Option.dequote(value)), charlist: function (value) Array.slice(Option.dequote(value)),
stringlist: function (value) (value === "") ? [] : Option.splitList(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, true).map(Option.parseRegex),
regexlist: function (value) (value === "") ? [] : Option.splitList(value).map(Option.parseRegex), stringmap: function (value) array.toObject(
regexmap: function (value) Option.splitList(value) Option.splitList(value, true).map(function (v) {
.map(function (v) util.split(v, /:/g, 2)) let [count, key, quote] = Commands.parseArg(v, /:/);
.map(function ([k, v]) v != null ? Option.parseRegex(k, v) : Option.parseRegex(".?", k)) 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) { dequote: function (value) {
@@ -422,20 +431,20 @@ const Option = Class("Option", {
Option._splitAt = 0; Option._splitAt = 0;
return arg; return arg;
}, },
splitList: function (value) { splitList: function (value, keepQuotes) {
let res = []; let res = [];
Option._splitAt = 0; Option._splitAt = 0;
do { do {
if (count !== undefined) if (count !== undefined)
Option._splitAt += count + 1; Option._splitAt += count + 1;
var [count, arg, quote] = Commands.parseArg(value, /,/); var [count, arg, quote] = Commands.parseArg(value, /,/, keepQuotes);
Option._quote = quote; // FIXME Option._quote = quote; // FIXME
res.push(arg); res.push(arg);
value = value.slice(count + 1); value = value.slice(count + 1);
} while (value.length); } while (value.length);
return res; 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: { ops: {
boolean: function (operator, values, scope, invert) { boolean: function (operator, values, scope, invert) {

View File

@@ -116,17 +116,11 @@
<li tag=";I"><em>I</em> to open an image in a new tab.</li> <li tag=";I"><em>I</em> to open an image in a new tab.</li>
</ul> </ul>
<!-- TODO: These are completely arbitrary and need to be
- changed before release. Hopefully they will be...
-->
<p> <p>
Of the previous modes, the value of the <o>hinttags</o> Of the previous modes, the value of the <o>hinttags</o>
option is used to choose the highlighted elements for option is used to choose the highlighted elements,
the modes, <k>;;</k>, <k>;?</k>, <k>;w</k>, <k>;v</k>, unless an override can be found in
<k>;V</k>, <k>;Y</k> and <k>;c</k>. The value of <o>extendedhinttags</o>.
<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>,
</p> </p>
</description> </description>
</item> </item>

View File

@@ -51,10 +51,11 @@
<dd> <dd>
A comma-separated list of regular expressions. Expressions may be A comma-separated list of regular expressions. Expressions may be
prefixed with a <em>!</em>, in which case the match will be negated. A 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 literal <em>!</em> at the begining of the expression may be matched
<em>[!]</em>. Generally, the first matching regular expression is with <em>[!]</em> or by placing the regular expression in quotes.
used. Any comma appearing within single or double quotes, or prefixed Generally, the first matching regular expression is used. Any comma
with a <em>\</em>, will not be treated as an item separator. appearing within single or double quotes, or prefixed with a
<em>\</em>, will not be treated as an item separator.
</dd> </dd>
<dt/><dd tag="regexmap"/> <dt/><dd tag="regexmap"/>
@@ -559,10 +560,14 @@
<tags>'eht' 'extendedhinttags'</tags> <tags>'eht' 'extendedhinttags'</tags>
<spec>'extendedhinttags' 'eht'</spec> <spec>'extendedhinttags' 'eht'</spec>
<strut/> <strut/>
<type>string</type> <type>regexmap</type>
<default>&hinttags;</default> <default>[iI]:'//img | //xhtml:img'</default>
<description> <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> </description>
</item> </item>
@@ -756,7 +761,12 @@
<type>string</type> <type>string</type>
<default>&hinttags;</default> <default>&hinttags;</default>
<description> <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> </description>
</item> </item>

View File

@@ -32,6 +32,8 @@
operators, and = sign may no longer be quoted. This will break operators, and = sign may no longer be quoted. This will break
certain automatically-generated configuration files. certain automatically-generated configuration files.
See :help stringlist See :help stringlist
* IMPORTANT: 'extendedhinttags' is now a regexmap rather than a
string.
* Added 'altwildmode' and <A-Tab> commandline key binding. * Added 'altwildmode' and <A-Tab> commandline key binding.
* Added 'autocomplete' option for specifying which completion * Added 'autocomplete' option for specifying which completion
groups should be auto-completed. groups should be auto-completed.

View File

@@ -34,8 +34,6 @@ BUGS:
FEATURES: FEATURES:
9 Add quoting help tag 9 Add quoting help tag
9 Fix the arbitrary distinction between 'hinttags' and
'extendedhinttags'
9 Support multiple bookmarks, -keyword, -tags in :delbmarks 9 Support multiple bookmarks, -keyword, -tags in :delbmarks
8 Document Caret and Visual modes. 8 Document Caret and Visual modes.
8 finish :help TODOs 8 finish :help TODOs