1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 23:27:59 +01:00

Add :feedkeys (perhaps to replace :normal?)

This commit is contained in:
Kris Maglione
2010-12-22 19:54:00 -05:00
parent c65758864d
commit 06936c88ea
6 changed files with 127 additions and 81 deletions

View File

@@ -685,7 +685,7 @@ const Dactyl = Module("dactyl", {
* @param {XMLList} extraHelp Extra help text beyond the description. * @param {XMLList} extraHelp Extra help text beyond the description.
* @returns {string} * @returns {string}
*/ */
generateHelp: function generateHelp(obj, extraHelp, str) { generateHelp: function generateHelp(obj, extraHelp, str, specOnly) {
default xml namespace = ""; default xml namespace = "";
let link, tag, spec; let link, tag, spec;
@@ -696,6 +696,7 @@ const Dactyl = Module("dactyl", {
tag = spec = function (cmd) <>:{cmd}</>; tag = spec = function (cmd) <>:{cmd}</>;
link = function (cmd) <ex>:{cmd}</ex>; link = function (cmd) <ex>:{cmd}</ex>;
args = obj.parseArgs("", CompletionContext(str || "")); args = obj.parseArgs("", CompletionContext(str || ""));
spec = function (cmd) cmd + (obj.bang ? <oa>!</oa> : <></>);
} }
else if (obj instanceof Map && obj.count) { else if (obj instanceof Map && obj.count) {
spec = function (map) <><oa>count</oa>{map}</>; spec = function (map) <><oa>count</oa>{map}</>;
@@ -715,10 +716,16 @@ const Dactyl = Module("dactyl", {
</>; </>;
let res = <res> 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> <item>
<tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags> <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 ? "" : <> !obj.type ? "" : <>
<type>{obj.type}</type> <type>{obj.type}</type>
<default>{obj.stringDefaultValue}</default></>} <default>{obj.stringDefaultValue}</default></>}
@@ -727,7 +734,7 @@ const Dactyl = Module("dactyl", {
extraHelp ? br + extraHelp : "" }{ extraHelp ? br + extraHelp : "" }{
!(extraHelp || obj.description) ? br + <p>Sorry, no help available.</p> : "" } !(extraHelp || obj.description) ? br + <p>Sorry, no help available.</p> : "" }
</description> </description>
</item></res>; </item></>;
function add(ary) { function add(ary) {
res.item.description.* += br + res.item.description.* += br +
@@ -752,7 +759,8 @@ const Dactyl = Module("dactyl", {
})</> })</>
}</> }</>
])); ]));
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]"], commands.add(["norm[al]"],
"Execute Normal mode commands", "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, bang: true,
literal: 0 literal: 0
}); });

View File

@@ -419,15 +419,12 @@ const Mappings = Module("mappings", {
names: ["-javascript", "-js", "-j"], names: ["-javascript", "-js", "-j"],
description: "Execute this mapping as JavaScript rather than keys" description: "Execute this mapping as JavaScript rather than keys"
}, },
{ update({}, modeFlag, {
names: ["-modes", "-mode", "-m"], names: ["-modes", "-mode", "-m"],
type: CommandOption.LIST, type: CommandOption.LIST,
description: "Create this mapping in the given modes", description: "Create this mapping in the given modes",
default: mapmodes || ["n", "v"], 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"], names: ["-nopersist", "-n"],
description: "Do not save this mapping to an auto-generated RC file" description: "Do not save this mapping to an auto-generated RC file"
@@ -501,9 +498,19 @@ 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) { function findMode(name) {
if (name)
for (let mode in values(modes.all)) for (let mode in values(modes.all))
if (name == mode || name == mode.char || String.toLowerCase(name).replace(/-/g, "_") == mode.name.toLowerCase()) if (name == mode || name == mode.char
|| String.toLowerCase(name).replace(/-/g, "_") == mode.name.toLowerCase())
return mode.mask; return mode.mask;
return null; return null;
} }
@@ -514,6 +521,20 @@ const Mappings = Module("mappings", {
return array.uniq(modes.filter(function (m) chars.indexOf(m.char) < 0).concat(chars)); 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], ""); addMapCommands("", [modes.NORMAL, modes.VISUAL], "");
let args = { let args = {
@@ -540,15 +561,10 @@ const Mappings = Module("mappings", {
name: ["listk[eys]", "lk"], name: ["listk[eys]", "lk"],
description: "List all mappings along with their short descriptions", description: "List all mappings along with their short descriptions",
options: [ options: [
{ update({}, modeFlag, {
names: ["-mode", "-m"],
type: CommandOption.STRING,
description: "The mode for which to list mappings",
default: "n", default: "n",
completer: function () [[array.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.disp] description: "The mode for which to list mappings"
for (mode in values(modes.all))], })
validator: function (m) findMode(m)
}
] ]
}); });

View File

@@ -255,6 +255,7 @@ This file contains a list of all available commands, mappings and options.
<dt><ex>:extensions</ex></dt> <dd>List all installed extensions</dd> <dt><ex>:extensions</ex></dt> <dd>List all installed extensions</dd>
<dt><ex>:extoptions</ex></dt> <dd>Open an extension's preference dialog</dd> <dt><ex>:extoptions</ex></dt> <dd>Open an extension's preference dialog</dd>
<dt><ex>:extupdate</ex></dt> <dd>Update an extension</dd> <dt><ex>:extupdate</ex></dt> <dd>Update an extension</dd>
<dt><ex>:feedkeys</ex></dt> <dd>Fake key events</dd>
<dt><ex>:finish</ex></dt> <dd>Stop sourcing a script file</dd> <dt><ex>:finish</ex></dt> <dd>Stop sourcing a script file</dd>
<dt><ex>:forward</ex></dt> <dd>Go forward in the browser history</dd> <dt><ex>:forward</ex></dt> <dd>Go forward in the browser history</dd>
<dt><ex>:frameonly</ex></dt> <dd>Show only the current frame's page</dd> <dt><ex>:frameonly</ex></dt> <dd>Show only the current frame's page</dd>

View File

@@ -23,14 +23,26 @@
arguments. These context names may be used to tune the function of arguments. These context names may be used to tune the function of
the completion system via options like <o>autocomplete</o> and the completion system via options like <o>autocomplete</o> and
<o>wildcase</o>. Note that completion must be triggered in order <o>wildcase</o>. Note that completion must be triggered in order
for this command to be effective, so if autocompletion is not for this command to be effective, so if auto-completion is not
active, you'll need to press the <k name="Tab" mode="c"/> key at active, you'll need to press the <k name="Tab" mode="c"/> key at
least once. You should also be aware that this command is only least once. You should also be aware that this command is only
useful from the commandline. useful from the command line.
</p> </p>
</description> </description>
</item> </item>
<item>
<tags>:fk :feedkeys</tags>
<spec>feedkeys<oa>!</oa></spec>
<description>
<p>Fake key events.</p>
<dl>
<dt>-mode</dt> <dd>The in which to feed the keys (short name: <em>-m</em>)</dd>
</dl>
</description>
</item>
<item> <item>
<tags>:norm :normal</tags> <tags>:norm :normal</tags>
<spec>:norm<oa>al</oa><oa>!</oa> <a>keys</a></spec> <spec>:norm<oa>al</oa><oa>!</oa> <a>keys</a></spec>

View File

@@ -153,7 +153,7 @@ const Template = Module("Template", {
return this.highlightSubstrings(str, (function () { return this.highlightSubstrings(str, (function () {
let res; let res;
while ((res = re.exec(str)) && res[0].length) while ((res = re.exec(str)) && res[0].length)
yield [res.index, res[0].length]; yield [res.index, res[0].length, res];
})(), highlight || template.filter); })(), highlight || template.filter);
}, },
@@ -168,12 +168,12 @@ const Template = Module("Template", {
let s = <></>; let s = <></>;
let start = 0; let start = 0;
let n = 0; let n = 0;
for (let [i, length] in iter) { for (let [i, length, args] in iter) {
if (n++ > 50) // Prevent infinite loops. if (n++ > 50) // Prevent infinite loops.
break; break;
XML.ignoreWhitespace = false; XML.ignoreWhitespace = false;
s += <>{str.substring(start, i)}</>; s += <>{str.substring(start, i)}</>;
s += highlight(str.substr(i, length)); s += highlight.apply(this, Array.slice(args || str.substr(i, length)));
start = i + length; start = i + length;
} }
return s + <>{str.substr(start)}</>; return s + <>{str.substr(start)}</>;

View File

@@ -49,12 +49,31 @@
* The concept of completion contexts is now exposed to the user * The concept of completion contexts is now exposed to the user
(see :h :contexts), allowing for powerful and fine-grained (see :h :contexts), allowing for powerful and fine-grained
completion system customization. completion system customization.
* :viusage, :optionusage and :exusage were replaced with :listkeys, * Command changes:
- :viusage, :optionusage and :exusage were replaced with :listkeys,
:listoptions and :listcommands, providing more powerful and :listoptions and :listcommands, providing more powerful and
consistent interactive help facility (improvements include consistent interactive help facility (improvements include
listing keys for modes other than Normal, filtering the output listing keys for modes other than Normal, filtering the output
and linking to source locations). and linking to source locations).
* Added :mksyntax command. - Added :cookies command.
* :extadd now supports remote URLs as well as local files on Firefox 4.
* Added :if/:elseif/:else/:endif conditionals.
- Added -keyword, -tags, -title to :delbmarks.
- Added :extupdate command.
- Added :feedkeys command.
- Added several new options, including -javascript, to :abbrev and :map.
- Added :mksyntax command.
- :open now only opens files beginning with /, ./, ../, or ~/
- Added :write !cmd and :write >>file.
- Added :yank command.
* Improvements to :style and :highlight:
- Added -agent flag to :style.
- The -append flag now updates existing properties rather than
simply appending its arguments to the previous value.
- Active filters are not highlighted in :style listings
- :style-related commands now divide their completions between
those active and inactive for the current site.
- CSS property name completion is not available
* IMPORTANT option changes: * IMPORTANT option changes:
- 'cdpath' and 'runtimepath' no longer treat ",," - 'cdpath' and 'runtimepath' no longer treat ",,"
specially. Use "." instead. specially. Use "." instead.
@@ -80,36 +99,26 @@
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
* Added "bookmarks", "diverted", and "links" to 'activate' * Option changes:
- Added "bookmarks", "diverted", and "links" to 'activate'
option. option.
* Added 'altwildmode' and <A-Tab> command-line key binding. - Added 'altwildmode' and <A-Tab> command-line 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.
* Added 'banghist' option. - Added 'banghist' option.
- Replaced 'focuscontent' with 'strictfocus'.
- 'complete' now defaults to "slf" but file completion only
triggers when the URL begins as above.
- Added 'passkeys' option.
- Changed 'urlseparator' default value to '|'.
- Added "passwords" and "venkman" dialogs to :dialog.
- Added 'wildanchor' option.
- Added 'cookies', 'cookieaccept', and 'cookielifetime' options.
* Added BookmarkChange, BookmarkRemove autocommands. * Added BookmarkChange, BookmarkRemove autocommands.
* Added :cookies, 'cookies', 'cookieaccept', and 'cookielifetime'.
* Added -keyword, -tags, -title to :delbmarks.
* Added "passwords" and "venkman" dialogs to :dialog.
* Added :extupdate command.
* Replaced 'focuscontent' with 'strictfocus'.
* Added :if/:elseif/:else/:endif conditionals.
* Added 'passkeys' option.
* Changed 'urlseparator' default value to '|'.
* Added 'wildanchor' option.
* Added -javascript option to :abbrev and :map.
* Added several new options to :map.
* Added -agent flag to :style.
* Added :write !cmd and :write >>file.
* Added :yank command.
* Removed the :source line at the end of files generated by * Removed the :source line at the end of files generated by
:mkpentadactylrc. :mkpentadactylrc.
* gf now toggles between source and content view. * gf now toggles between source and content view.
The | key binding has been removed. The | key binding has been removed.
* :extadd now supports remote URLs as well as local files on
Firefox 4.
* :open now only opens files beginning with /, ./, ../, or ~/
* 'complete' now defaults to "slf" but file completion only
triggers when the URL begins as above.
* Page zoom information is now shown in the status bar, and * Page zoom information is now shown in the status bar, and
change in zoom status no longer appears in :messages. change in zoom status no longer appears in :messages.
* Added ZO, ZI, ZM, and ZR as aliases for zO, zI, zM, and zR. * Added ZO, ZI, ZM, and ZR as aliases for zO, zI, zM, and zR.