From f1b40dd6ecd6f2f40b3dd5c570f663173f880383 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 30 Sep 2008 12:27:16 +0000 Subject: [PATCH] improve error messages given when sourcing files --- content/io.js | 78 ++++++++++++++++++++++++++++----------------- content/ui.js | 1 + skin/vimperator.css | 4 +++ 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/content/io.js b/content/io.js index 25bffcd1..82b3842d 100644 --- a/content/io.js +++ b/content/io.js @@ -777,7 +777,7 @@ lookup: liberator.echomsg("sourcing \"" + filename + "\"", 2); - var str = ioManager.readFile(file); + let str = ioManager.readFile(file); // handle pure javascript files specially if (/\.js$/.test(filename)) @@ -786,14 +786,12 @@ lookup: } else { - var heredoc = ""; - var heredocEnd = null; // the string which ends the heredoc - var lines = str.split("\n"); + let heredoc = ""; + let heredocEnd = null; // the string which ends the heredoc + let lines = str.split("\n"); - for (let i = 0; i < lines.length; i++) + for (let [i, line] in Iterator(lines)) { - let line = lines[i]; - if (heredocEnd) // we already are in a heredoc { if (heredocEnd.test(line)) @@ -809,33 +807,53 @@ lookup: } else { - var [count, cmd, special, args] = liberator.commands.parseCommand(line); - var command = liberator.commands.get(cmd); + // skip line comments and blank lines + if (/^\s*(".*)?$/.test(line)) + continue; - if (command && command.name == "finish") - { - break; - } - else if (command && command.name == "javascript") - { - // check for a heredoc - var matches = args.match(/(.*)<<\s*([^\s]+)$/); + let [count, cmd, special, args] = liberator.commands.parseCommand(line); + let command = liberator.commands.get(cmd); - if (matches) - { - heredocEnd = new RegExp("^" + matches[2] + "$", "m"); - if (matches[1]) - heredoc = matches[1] + "\n"; - } - else - { - command.execute(args, special, count); - } + if (!command) + { + let lineNumber = i + 1; + + // FIXME: messages need to be able to specify + // whether they can be cleared/overwritten or + // should be appended to and the MOW opened + liberator.echoerr("Error detected while processing " + file.path, + liberator.commandline.FORCE_MULTILINE); + liberator.commandline.echo("line " + lineNumber + ":", liberator.commandline.HL_LINENR, + liberator.commandline.APPEND_TO_MESSAGES); + liberator.echoerr("E492: Not an editor command: " + line); } else { - // execute a normal liberator command - liberator.execute(line); + if (command.name == "finish") + { + break; + } + else if (command.name == "javascript") + { + // check for a heredoc + let matches = args.match(/(.*)<<\s*([^\s]+)$/); + + if (matches) + { + heredocEnd = new RegExp("^" + matches[2] + "$", "m"); + if (matches[1]) + heredoc = matches[1] + "\n"; + } + else + { + command.execute(args, special, count); + } + } + else + { + // execute a normal liberator command + liberator.execute(line); + } } } } @@ -854,7 +872,7 @@ lookup: } catch (e) { - var message = "Sourcing file: " + file.path + ": " + e; + let message = "Sourcing file: " + file.path + ": " + e; Components.utils.reportError(message); if (!silent) liberator.echoerr(message); diff --git a/content/ui.js b/content/ui.js index 3e5bedba..5d381021 100644 --- a/content/ui.js +++ b/content/ui.js @@ -529,6 +529,7 @@ liberator.CommandLine = function () //{{{ HL_QUESTION : "hl-Question", HL_INFOMSG : "hl-InfoMsg", HL_WARNINGMSG : "hl-WarningMsg", + HL_LINENR : "hl-LineNr", // not yet used FORCE_MULTILINE : 1 << 0, diff --git a/skin/vimperator.css b/skin/vimperator.css index 8d0040cd..b5291acd 100644 --- a/skin/vimperator.css +++ b/skin/vimperator.css @@ -127,6 +127,10 @@ the terms of any one of the MPL, the GPL or the LGPL. background-color: white; color: black; } +.hl-LineNr { + background-color: white; + color: orange; +} .hl-MoreMsg { background-color: white; color: green;