mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-30 04:22:28 +01:00
Add :feedkeys (perhaps to replace :normal?)
This commit is contained in:
@@ -685,7 +685,7 @@ const Dactyl = Module("dactyl", {
|
||||
* @param {XMLList} extraHelp Extra help text beyond the description.
|
||||
* @returns {string}
|
||||
*/
|
||||
generateHelp: function generateHelp(obj, extraHelp, str) {
|
||||
generateHelp: function generateHelp(obj, extraHelp, str, specOnly) {
|
||||
default xml namespace = "";
|
||||
|
||||
let link, tag, spec;
|
||||
@@ -696,6 +696,7 @@ const Dactyl = Module("dactyl", {
|
||||
tag = spec = function (cmd) <>:{cmd}</>;
|
||||
link = function (cmd) <ex>:{cmd}</ex>;
|
||||
args = obj.parseArgs("", CompletionContext(str || ""));
|
||||
spec = function (cmd) cmd + (obj.bang ? <oa>!</oa> : <></>);
|
||||
}
|
||||
else if (obj instanceof Map && obj.count) {
|
||||
spec = function (map) <><oa>count</oa>{map}</>;
|
||||
@@ -715,10 +716,16 @@ const Dactyl = Module("dactyl", {
|
||||
</>;
|
||||
|
||||
let res = <res>
|
||||
<dt>{link(obj.name)}</dt> <dd>{obj.description ? obj.description.replace(/\.$/, "") : ""}</dd>
|
||||
<dt>{link(obj.name)}</dt> <dd>{obj.description ? obj.description.replace(/\.$/, "") : ""}</dd></res>;
|
||||
if (!specOnly) {
|
||||
res.* += <>
|
||||
<item>
|
||||
<tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags>
|
||||
<spec>{spec((obj.specs || obj.names)[0])}</spec>{
|
||||
<spec>{
|
||||
spec(template.highlightRegexp((obj.specs || obj.names)[0],
|
||||
/\[(.*?)\]/g,
|
||||
function (m, n0) <oa>{n0}</oa>))
|
||||
}</spec>{
|
||||
!obj.type ? "" : <>
|
||||
<type>{obj.type}</type>
|
||||
<default>{obj.stringDefaultValue}</default></>}
|
||||
@@ -727,32 +734,33 @@ const Dactyl = Module("dactyl", {
|
||||
extraHelp ? br + extraHelp : "" }{
|
||||
!(extraHelp || obj.description) ? br + <p>Sorry, no help available.</p> : "" }
|
||||
</description>
|
||||
</item></res>;
|
||||
</item></>;
|
||||
|
||||
function add(ary) {
|
||||
res.item.description.* += br +
|
||||
let (br = br + <> </>)
|
||||
<><dl>{ br + template.map(ary, function ([a, b]) <><dt>{a}</dt> <dd>{b}</dd></>, br) }
|
||||
</dl>
|
||||
</>;
|
||||
function add(ary) {
|
||||
res.item.description.* += br +
|
||||
let (br = br + <> </>)
|
||||
<><dl>{ br + template.map(ary, function ([a, b]) <><dt>{a}</dt> <dd>{b}</dd></>, br) }
|
||||
</dl>
|
||||
</>;
|
||||
}
|
||||
|
||||
if (obj.completer)
|
||||
add(completion._runCompleter(obj.completer, "", null, args).items
|
||||
.map(function (i) [i.text, i.description]));
|
||||
|
||||
if (obj.options && obj.options.some(function (o) o.description))
|
||||
add(obj.options.filter(function (o) o.description)
|
||||
.map(function (o) [
|
||||
o.names[0],
|
||||
<>{o.description}{
|
||||
o.names.length == 1 ? "" :
|
||||
<> (short name: {
|
||||
template.map(o.names.slice(1), function (n) <em>{n}</em>, <>, </>)
|
||||
})</>
|
||||
}</>
|
||||
]));
|
||||
}
|
||||
|
||||
if (obj.completer)
|
||||
add(completion._runCompleter(obj.completer, "", null, args).items
|
||||
.map(function (i) [i.text, i.description]));
|
||||
|
||||
if (obj.options && obj.options.some(function (o) o.description))
|
||||
add(obj.options.filter(function (o) o.description)
|
||||
.map(function (o) [
|
||||
o.names[0],
|
||||
<>{o.description}{
|
||||
o.names.length == 1 ? "" :
|
||||
<> (short name: {
|
||||
template.map(o.names.slice(1), function (n) <em>{n}</em>, <>, </>)
|
||||
})</>
|
||||
}</>
|
||||
]));
|
||||
return res.*.toXMLString().replace(/^ {12}|[ \t]+$/gm, "");
|
||||
return res.*.toXMLString().replace(/^ {12}|[ \t]+$/gm, "").replace(/^.*\n|\n.*$/g, "") + "\n";
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1764,9 +1772,9 @@ const Dactyl = Module("dactyl", {
|
||||
|
||||
commands.add(["norm[al]"],
|
||||
"Execute Normal mode commands",
|
||||
function (args) { events.feedkeys(args[0] || "", args.bang, false, modes.NORMAL); },
|
||||
function (args) { events.feedkeys(args[0], args.bang, false, modes.NORMAL); },
|
||||
{
|
||||
argCount: "+",
|
||||
argCount: "1",
|
||||
bang: true,
|
||||
literal: 0
|
||||
});
|
||||
|
||||
@@ -419,15 +419,12 @@ const Mappings = Module("mappings", {
|
||||
names: ["-javascript", "-js", "-j"],
|
||||
description: "Execute this mapping as JavaScript rather than keys"
|
||||
},
|
||||
{
|
||||
update({}, modeFlag, {
|
||||
names: ["-modes", "-mode", "-m"],
|
||||
type: CommandOption.LIST,
|
||||
description: "Create this mapping in the given modes",
|
||||
default: mapmodes || ["n", "v"],
|
||||
validator: function (list) !list || list.every(findMode),
|
||||
completer: function () [[array.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.disp]
|
||||
for (mode in values(modes.all))],
|
||||
},
|
||||
}),
|
||||
{
|
||||
names: ["-nopersist", "-n"],
|
||||
description: "Do not save this mapping to an auto-generated RC file"
|
||||
@@ -501,10 +498,20 @@ const Mappings = Module("mappings", {
|
||||
});
|
||||
}
|
||||
|
||||
let modeFlag = {
|
||||
names: ["-mode", "-m"],
|
||||
type: CommandOption.STRING,
|
||||
validator: function (value) Array.concat(value).every(findMode),
|
||||
completer: function () [[array.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.disp]
|
||||
for (mode in values(modes.all))],
|
||||
};
|
||||
|
||||
function findMode(name) {
|
||||
for (let mode in values(modes.all))
|
||||
if (name == mode || name == mode.char || String.toLowerCase(name).replace(/-/g, "_") == mode.name.toLowerCase())
|
||||
return mode.mask;
|
||||
if (name)
|
||||
for (let mode in values(modes.all))
|
||||
if (name == mode || name == mode.char
|
||||
|| String.toLowerCase(name).replace(/-/g, "_") == mode.name.toLowerCase())
|
||||
return mode.mask;
|
||||
return null;
|
||||
}
|
||||
function uniqueModes(modes) {
|
||||
@@ -514,6 +521,20 @@ const Mappings = Module("mappings", {
|
||||
return array.uniq(modes.filter(function (m) chars.indexOf(m.char) < 0).concat(chars));
|
||||
}
|
||||
|
||||
commands.add(["feedkeys", "fk"],
|
||||
"Fake key events",
|
||||
function (args) { events.feedkeys(args[0] || "", args.bang, false, findMode(args["-mode"])); },
|
||||
{
|
||||
argCount: "1",
|
||||
bang: true,
|
||||
literal: 0,
|
||||
options: [
|
||||
update({}, modeFlag, {
|
||||
description: "The in which to feed the keys"
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
addMapCommands("", [modes.NORMAL, modes.VISUAL], "");
|
||||
|
||||
let args = {
|
||||
@@ -540,15 +561,10 @@ const Mappings = Module("mappings", {
|
||||
name: ["listk[eys]", "lk"],
|
||||
description: "List all mappings along with their short descriptions",
|
||||
options: [
|
||||
{
|
||||
names: ["-mode", "-m"],
|
||||
type: CommandOption.STRING,
|
||||
description: "The mode for which to list mappings",
|
||||
update({}, modeFlag, {
|
||||
default: "n",
|
||||
completer: function () [[array.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.disp]
|
||||
for (mode in values(modes.all))],
|
||||
validator: function (m) findMode(m)
|
||||
}
|
||||
description: "The mode for which to list mappings"
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user