mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-15 08:25:46 +01:00
Replace uses of commands.replaceTokens with util.compileMacro.
This commit is contained in:
@@ -335,12 +335,13 @@ const Command = Class("Command", {
|
||||
case "-keys":
|
||||
let silent = args["-silent"];
|
||||
rhs = events.canonicalKeys(rhs, true);
|
||||
var action = function action(count)
|
||||
events.feedkeys(commands.replaceTokens(rhs, { count: count }),
|
||||
noremap, silent);
|
||||
let macro = util.compileMacro(rhs, true);
|
||||
var action = function action(count) events.feedkeys(macro({ count: count }),
|
||||
noremap, silent);
|
||||
break;
|
||||
case "-ex":
|
||||
action = function action() commands.execute(rhs, makeParams.apply(this, arguments),
|
||||
macro = util.compileMacro(rhs, true);
|
||||
action = function action() commands.execute(macro, makeParams.apply(this, arguments),
|
||||
false, null, action.sourcing);
|
||||
action.sourcing = io.sourcing && update({}, io.sourcing);
|
||||
break;
|
||||
@@ -572,8 +573,10 @@ const Commands = Module("commands", {
|
||||
|
||||
args = update({}, args || {});
|
||||
|
||||
if (tokens)
|
||||
string = commands.replaceTokens(string, tokens);
|
||||
if (tokens && !callable(string))
|
||||
string = util.compileMacro(string, true);
|
||||
if (callable(string))
|
||||
string = string(tokens || {});
|
||||
|
||||
let lines = string.split(/\r\n|[\r\n]/);
|
||||
|
||||
@@ -1150,34 +1153,6 @@ const Commands = Module("commands", {
|
||||
this._exCommands = this._exCommands.filter(function (c) c !== cmd);
|
||||
for (let name in values(cmd.names))
|
||||
delete this._exMap[name];
|
||||
},
|
||||
|
||||
// FIXME: still belong here? Also used for autocommand parameters.
|
||||
/**
|
||||
* Returns a string with all tokens in *string* matching "<key>" replaced
|
||||
* with "value". Where "key" is a property of the specified *tokens* object
|
||||
* and "value" is the corresponding value. The <lt> token can be used to
|
||||
* include a literal "<" in the returned string. Any tokens prefixed with
|
||||
* "q-" will be quoted except for <q-lt> which is treated like <lt>.
|
||||
*
|
||||
* @param {string} str The string with tokens to replace.
|
||||
* @param {Object} tokens A map object whose keys are replaced with its
|
||||
* values.
|
||||
* @returns {string}
|
||||
*/
|
||||
replaceTokens: function replaceTokens(str, tokens) {
|
||||
return str.replace(/<((?:q-)?)([a-zA-Z]+)?>/g, function (match, quote, token) {
|
||||
if (token == "lt") // Don't quote, as in Vim (but, why so in Vim? You'd think people wouldn't say <q-lt> if they didn't want it)
|
||||
return "<";
|
||||
let res = tokens[token];
|
||||
if (res === undefined) // Ignore anything undefined
|
||||
res = "<" + token + ">";
|
||||
if (res === null)
|
||||
res = "";
|
||||
if (quote && typeof res != "number")
|
||||
return Commands.quoteArg['"'](res);
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
// returns [count, parsed_argument]
|
||||
|
||||
@@ -586,7 +586,7 @@ lookup:
|
||||
file.append(config.name + ".vim");
|
||||
dactyl.assert(!file.exists() || args.bang, "File exists");
|
||||
|
||||
let template = <![CDATA[
|
||||
let template = util.compileMacro(String(<![CDATA[
|
||||
" Vim syntax file
|
||||
" Language: Pentadactyl configuration file
|
||||
" Maintainer: Doug Kearns <dougkearns@gmail.com>
|
||||
@@ -631,7 +631,7 @@ execute 'syn match <name>Option "\<\%(no\|inv\)\=\%(' .
|
||||
\ join(s:toggleOptions, '\|') .
|
||||
\ '\)\>!\=" contained nextgroup=<name>SetMod'
|
||||
|
||||
syn match <name>SetMod "\%(\<[a-z_]\+\)\@<=&" contained
|
||||
syn match <name>SetMod "\%(\<lt>[a-z_]\+\)\@<=&" contained
|
||||
|
||||
syn region <name>JavaScript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline
|
||||
syn region <name>JavaScript matchgroup=<name>JavaScriptDelimiter
|
||||
@@ -642,7 +642,7 @@ execute 'syn region <name>Css start="' . s:cssRegionStart . '" end="$" contains=
|
||||
execute 'syn region <name>Css matchgroup=<name>CssDelimiter'
|
||||
\ 'start="' . s:cssRegionStart . '<<\s*\z(\h\w*\)"hs=s+2 end="^\z1$" contains=@cssTop fold'
|
||||
|
||||
syn match <name>Notation "<[0-9A-Za-z-]\+>"
|
||||
syn match <name>Notation "<lt>[0-9A-Za-z-]\+>"
|
||||
|
||||
syn match <name>Comment +".*$+ contains=<name>Todo,@Spell
|
||||
syn keyword <name>Todo FIXME NOTE TODO XXX contained
|
||||
@@ -671,7 +671,7 @@ let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: tw=130 et ts=4 sw=4:
|
||||
]]>;
|
||||
]]>), true);
|
||||
|
||||
const WIDTH = 80;
|
||||
function wrap(prefix, items, sep) {
|
||||
@@ -693,7 +693,7 @@ unlet s:cpo_save
|
||||
return lines.map(function (l) l.join("")).join("\n").replace(/\s+\n/gm, "\n");
|
||||
}
|
||||
|
||||
file.write(commands.replaceTokens(String(template), {
|
||||
file.write(template({
|
||||
name: config.name,
|
||||
autocommands: wrap("syn keyword " + config.name + "AutoEvent ",
|
||||
keys(config.autocommands)),
|
||||
|
||||
Reference in New Issue
Block a user