1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 17:27:57 +01:00

allow single line :js commands to be source from RC files

This commit is contained in:
Doug Kearns
2007-09-14 04:31:37 +00:00
parent 79bbf87a8e
commit 2209703239

View File

@@ -518,24 +518,28 @@ const vimperator = (function() //{{{
// handle pure javascript files specially // handle pure javascript files specially
if (filename.search("\.js$") != -1) if (filename.search("\.js$") != -1)
{
eval(s); eval(s);
}
else else
{ {
var heredoc = ""; var heredoc = "";
var heredocEnd = null; // the string which ends the heredoc var heredoc_end = null; // the string which ends the heredoc
s.split("\n").forEach(function(line) s.split("\n").forEach(function(line)
{ {
if (heredocEnd) // we already are in a heredoc if (heredoc_end) // we already are in a heredoc
{ {
if (line.search(heredocEnd) != -1) if (heredoc_end.test(line))
{ {
eval(heredoc); eval(heredoc);
heredoc = ""; heredoc = "";
heredocEnd = null; heredoc_end = null;
} }
else else
{
heredoc += line + "\n"; heredoc += line + "\n";
} }
}
else else
{ {
// check for a heredoc // check for a heredoc
@@ -544,12 +548,16 @@ const vimperator = (function() //{{{
if (command && command.name == "javascript") if (command && command.name == "javascript")
{ {
var matches = args.match(/(.*)<<\s*([^\s]+)$/); var matches = args.match(/(.*)<<\s*([^\s]+)$/);
if (matches && matches[2]) if (matches)
{ {
heredocEnd = new RegExp("^" + matches[2] + "$", "m"); heredoc_end = new RegExp("^" + matches[2] + "$", "m");
if (matches[1]) if (matches[1])
heredoc = matches[1] + "\n"; heredoc = matches[1] + "\n";
} }
else
{
command.execute(args, special, count);
}
} }
else else
{ {