1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-05 20:24:12 +01:00

add rough initial implementations of :message, g< (gm for now) and 'messages'

This commit is contained in:
Doug Kearns
2008-09-27 12:33:23 +00:00
parent 8154f7b5fa
commit 675ae16f24
13 changed files with 253 additions and 101 deletions

View File

@@ -54,7 +54,7 @@ liberator.AutoCommands = function () //{{{
{
let values = value.split(",");
let events = liberator.config.autocommands.map(function (e) e[0]);
events.push("all");
return values.every(function (event) events.indexOf(event) >= 0);
@@ -242,6 +242,8 @@ liberator.AutoCommands = function () //{{{
if (events.some(function (event) event == "all" || event == auEvent))
return;
liberator.echomsg("Executing " + auEvent + " Auto commands for \"*\"", 8);
if (autoCommands[auEvent])
{
for (let i = 0; i < autoCommands[auEvent].length; i++)
@@ -494,7 +496,7 @@ liberator.Events = function () //{{{
}
else // background tab
{
liberator.commandline.echo("Background tab loaded: " + title || url, liberator.commandline.HL_INFOMSG);
liberator.echomsg("Background tab loaded: " + title || url, 1);
}
}
}
@@ -557,8 +559,7 @@ liberator.Events = function () //{{{
{
for (let [,dir] in Iterator(dirs))
{
if (liberator.options["verbose"] >= 2)
liberator.echo("Searching for \"macros/*\" in \"" + dir.path + "\"\n");
liberator.echomsg("Searching for \"macros/*\" in \"" + dir.path + "\"", 2);
liberator.log("Sourcing macros directory: " + dir.path + "...", 3);

View File

@@ -375,9 +375,11 @@ liberator.Search = function () //{{{
// our command line
setTimeout(function () {
if (up)
liberator.commandline.echo("search hit TOP, continuing at BOTTOM", liberator.commandline.HL_WARNINGMSG);
liberator.commandline.echo("search hit TOP, continuing at BOTTOM",
liberator.commandline.HL_WARNINGMSG, liberator.commandline.APPEND_TO_MESSAGES);
else
liberator.commandline.echo("search hit BOTTOM, continuing at TOP", liberator.commandline.HL_WARNINGMSG);
liberator.commandline.echo("search hit BOTTOM, continuing at TOP",
liberator.commandline.HL_WARNINGMSG, liberator.commandline.APPEND_TO_MESSAGES);
}, 0);
}
else

View File

@@ -273,6 +273,10 @@ liberator.IO = function () //{{{
// : unify with startup sourcing loop
let paths = args.arguments;
let runtimeDirs = liberator.options["runtimepath"].split(",");
let found = false;
// FIXME: should use original arg string
liberator.echomsg("Searching for \"" + paths.join(" ") + "\" in \"" + liberator.options["runtimepath"] + "\"", 2);
outer:
for (let [,runtimeDir] in Iterator(runtimeDirs))
@@ -281,8 +285,11 @@ liberator.IO = function () //{{{
{
let file = liberator.io.getFile(joinPaths(runtimeDir, path));
liberator.echomsg("Searching for \"" + file.path + "\" in \"", 3);
if (file.exists() && file.isReadable() && !file.isDirectory()) // XXX
{
found = true;
liberator.io.source(file.path, false);
if (!special)
@@ -290,6 +297,9 @@ liberator.IO = function () //{{{
}
}
}
if (!found)
liberator.echomsg("not found in 'runtimepath': \"" + paths.join(" ") + "\"", 1); // FIXME: should use original arg string
},
{ argCount: "+" }
);
@@ -696,8 +706,10 @@ lookup:
// when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is fixed
// is fixed, should use that instead of a tmpfile
system: function (str, input)
system: function (command, input)
{
liberator.echomsg("Calling shell to execute: " + command, 4);
var stdoutFile = ioManager.createTempFile();
var stderrFile = ioManager.createTempFile();
@@ -707,10 +719,9 @@ lookup:
return "";
if (WINDOWS)
var command = str + " > " + stdoutFile.path + " 2> " + stderrFile.path;
command += " > " + stdoutFile.path + " 2> " + stderrFile.path;
else
var command = str + " > \"" + escapeQuotes(stdoutFile.path) + "\""
+ " 2> \"" + escapeQuotes(stderrFile.path) + "\"";
command += " > \"" + escapeQuotes(stdoutFile.path) + "\"" + " 2> \"" + escapeQuotes(stderrFile.path) + "\"";
var stdinFile = null;
@@ -754,7 +765,9 @@ lookup:
if (!silent)
{
if (file.isDirectory())
liberator.echo("Cannot source a directory: \"" + filename + "\"\n");
liberator.echomsg("Cannot source a directory: \"" + filename + "\"", 0);
else
liberator.echomsg("could not source: \"" + filename + "\"", 1);
liberator.echoerr("E484: Can't open file " + filename);
}
@@ -762,6 +775,8 @@ lookup:
return;
}
liberator.echomsg("sourcing \"" + filename + "\"", 2);
var str = ioManager.readFile(file);
// handle pure javascript files specially
@@ -833,6 +848,8 @@ lookup:
if (scriptNames.indexOf(file.path) == -1)
scriptNames.push(file.path);
liberator.echomsg("finished sourcing \"" + filename + "\"", 2);
liberator.log("Sourced: " + file.path, 3);
}
catch (e)

View File

@@ -94,10 +94,10 @@ const liberator = (function () //{{{
"boolean", true);
liberator.options.add(["verbose", "vbs"],
"Define which type of messages are logged",
"Define which info messages are displayed",
"number", 0,
{
validator: function (value) value >= 0 && value <= 9
validator: function (value) value >= 0 && value <= 15
});
liberator.options.add(["visualbell", "vb"],
@@ -785,7 +785,25 @@ const liberator = (function () //{{{
echo: function (str, flags) { liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, flags); },
echoerr: function (str, flags) { liberator.commandline.echo(str, liberator.commandline.HL_ERRORMSG, flags); },
// TODO: Vim replaces unprintable characters in echoerr/echomsg
echoerr: function (str, flags)
{
flags |= liberator.commandline.APPEND_TO_MESSAGES;
liberator.commandline.echo(str, liberator.commandline.HL_ERRORMSG, flags);
},
// TODO: add proper level constants
echomsg: function (str, verbosity, flags)
{
flags |= liberator.commandline.APPEND_TO_MESSAGES;
if (verbosity == null)
verbosity = 0; // verbosity level is exclusionary
if (liberator.options["verbose"] >= verbosity)
liberator.commandline.echo(str, liberator.commandline.HL_INFOMSG, flags);
},
// return true, if this VIM-like extension has a certain feature
has: function (feature)
@@ -853,15 +871,16 @@ const liberator = (function () //{{{
// logs a message to the javascript error console
// if msg is an object, it is beautified
// TODO: add proper level constants
log: function (msg, level)
{
var verbose = 0;
if (typeof level != "number")
if (typeof level != "number") // XXX
level = 1;
// liberator.options does not exist at the very beginning
if (liberator.options)
verbose = liberator.options["verbose"];
verbose = liberator.options.getPref("extensions.liberator.loglevel", 0);
if (level > verbose)
return;
@@ -871,7 +890,7 @@ const liberator = (function () //{{{
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
consoleService.logStringMessage("vimperator: " + msg);
consoleService.logStringMessage(liberator.config.name.toLowerCase() + ": " + msg);
},
// open one or more URLs
@@ -1080,8 +1099,7 @@ const liberator = (function () //{{{
for (let [,dir] in Iterator(dirs))
{
// TODO: search plugins/**/* for plugins
if (liberator.options["verbose"] >= 2)
liberator.echo("Searching for \"plugin/*.{js,vimp}\" in \"" + dir.path + "\"\n");
liberator.echomsg("Searching for \"plugin/*.{js,vimp}\" in \"" + dir.path + "\"", 2);
liberator.log("Sourcing plugin directory: " + dir.path + "...", 3);

View File

@@ -209,7 +209,7 @@ liberator.Options = function () //{{{
function loadPreference(name, forcedDefault, defaultBranch)
{
var defaultValue = null;
var defaultValue = null; // XXX
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history)
defaultValue = forcedDefault;

View File

@@ -43,7 +43,6 @@ liberator.CommandLine = function () //{{{
liberator.storage.newArray("history-search", true);
liberator.storage.newArray("history-command", true);
// TODO: clean this up when it's not 3am...
var history = {
get mode() (liberator.modes.extended == liberator.modes.EX) ? "command" : "search",
@@ -67,6 +66,34 @@ liberator.CommandLine = function () //{{{
var historyIndex = UNINITIALIZED;
var historyStart = "";
var messageHistory = {
_messages: [],
get messages()
{
let max = liberator.options["messages"];
// resize if 'messages' has changed
if (this._messages.length > max)
this._messages = this._messages.splice(this._messages.length - max);
return this._messages;
},
get length() this._messages.length,
add: function (message)
{
if (!message)
return;
if (this._messages.length >= liberator.options["messages"])
this._messages.shift();
this._messages.push(message);
}
};
var lastMowOutput = null;
var completionList = new liberator.ItemList("liberator-completions");
var completions = [];
// for the example command "open sometext| othertext" (| is the cursor pos):
@@ -97,8 +124,8 @@ liberator.CommandLine = function () //{{{
multilineOutputWidget.contentDocument.body.id = "liberator-multiline-output-content";
// TODO: is there a better way to determine and set the UI font, 'guifont' perhaps?
var id = liberator.config.mainWindowID || "main-window";
var fontSize = document.defaultView.getComputedStyle(document.getElementById(id), null).getPropertyValue("font-size");
var mainWindowID = liberator.config.mainWindowID || "main-window";
var fontSize = document.defaultView.getComputedStyle(document.getElementById(mainWindowID), null).getPropertyValue("font-size");
multilineOutputWidget.contentDocument.body.setAttribute("style", "font-size: " + fontSize);
multilineOutputWidget.contentDocument.body.innerHTML = "";
@@ -188,6 +215,9 @@ liberator.CommandLine = function () //{{{
//outputContainer.collapsed = true;
var output = "<div class=\"ex-command-output " + highlightGroup + "\">" + str + "</div>";
lastMowOutput = output;
if (!outputContainer.collapsed)
{
// FIXME: need to make sure an open MOW is closed when commands
@@ -276,17 +306,6 @@ liberator.CommandLine = function () //{{{
////////////////////// OPTIONS /////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.options.add(["history", "hi"],
"Number of Ex commands and search patterns to store in the command-line history",
"number", 500,
{
validator: function (value) value >= 0
});
liberator.options.add(["more"],
"Pause the message list window when more than one screen of listings is displayed",
"boolean", true);
// TODO: doesn't belong in ui.js
liberator.options.add(["complete", "cpt"],
"Items which are completed at the :[tab]open prompt",
@@ -306,6 +325,28 @@ liberator.CommandLine = function () //{{{
validator: function (value) !/[^sfbhSl]/.test(value)
});
liberator.options.add(["history", "hi"],
"Number of Ex commands and search patterns to store in the command-line history",
"number", 500,
{
validator: function (value) value >= 0
});
liberator.options.add(["messages", "msgs"],
"Number of messages to store in the message history",
"number", 100,
{
validator: function (value) value >= 0
});
liberator.options.add(["more"],
"Pause the message list window when more than one screen of listings is displayed",
"boolean", true);
liberator.options.add(["showmode", "smd"],
"Show the current mode in the command line",
"boolean", true);
liberator.options.add(["suggestengines"],
"Engine Alias which has a feature of suggest",
"stringlist", "google",
@@ -316,7 +357,7 @@ liberator.CommandLine = function () //{{{
.getService(Components.interfaces.nsIBrowserSearchService);
let engines = ss.getEngines({})
.filter(function (engine) engine.supportsResponseType("application/x-suggestions+json"));
return engines.map(function (engine) [engine.alias, engine.description]);
},
validator: function (value)
@@ -331,9 +372,24 @@ liberator.CommandLine = function () //{{{
}
});
liberator.options.add(["showmode", "smd"],
"Show the current mode in the command line",
"boolean", true);
liberator.options.add(["wildignore", "wig"],
"List of file patterns to ignore when completing files",
"stringlist", "",
{
validator: function (value)
{
// TODO: allow for escaping the ","
try
{
new RegExp("^(" + value.replace(",", "|", "g") + ")$");
return true;
}
catch (e)
{
return false;
}
}
});
liberator.options.add(["wildmode", "wim"],
"Define how command line completion works",
@@ -358,25 +414,6 @@ liberator.CommandLine = function () //{{{
}
});
liberator.options.add(["wildignore", "wig"],
"List of file patterns to ignore when completing files",
"stringlist", "",
{
validator: function (value)
{
// TODO: allow for escaping the ","
try
{
new RegExp("^(" + value.replace(",", "|", "g") + ")$");
return true;
}
catch (e)
{
return false;
}
}
});
liberator.options.add(["wildoptions", "wop"],
"Change how command line completion is done",
"stringlist", "",
@@ -418,33 +455,74 @@ liberator.CommandLine = function () //{{{
["<C-]>", "<C-5>"], "Expand command line abbreviation",
function () { liberator.editor.expandAbbreviation("c"); });
// FIXME: Should be "g<" but that doesn't work unless it has a non-null
// rhs, getCandidates broken?
liberator.mappings.add([liberator.modes.NORMAL],
["gm"], "Redisplay the last command output",
function ()
{
if (lastMowOutput)
liberator.commandline.echo(lastMowOutput,
liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE)
else
liberator.beep();
});
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMMANDS ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.commands.add(["ec[ho]"],
"Display a string at the bottom of the window",
function (args)
var echoCommands = [
{
var res = echoArgumentToString(args, true);
if (res != null)
liberator.echo(res);
name: "ec[ho]",
description: "Display a string at the bottom of the window",
action: liberator.echo
},
{
completer: function (filter) liberator.completion.javascript(filter)
});
name: "echoe[rr]",
description: "Display an error string at the bottom of the window",
action: liberator.echoerr
},
{
name: "echom[sg]",
description: "Display a message at the bottom of the window saving it in the message history",
action: liberator.echomsg
}
];
liberator.commands.add(["echoe[rr]"],
"Display an error string at the bottom of the window",
function (args)
echoCommands.forEach(function (command) {
liberator.commands.add([command.name],
command.description,
function (args)
{
var str = echoArgumentToString(args, true);
if (str != null)
command.action(str);
},
{
completer: function (filter) liberator.completion.javascript(filter)
});
});
liberator.commands.add(["mes[sages]"],
"Display previously given messages",
function ()
{
var res = echoArgumentToString(args, false);
if (res != null)
liberator.echoerr(res);
},
{
completer: function (filter) liberator.completion.javascript(filter)
});
// TODO: the MOW<->command-line disjoint is really annoying
if (messageHistory.length == 1)
{
liberator.commandline.echo(messageHistory.messages[0], liberator.commandline.HL_NORMAL);
}
else if (messageHistory.length > 1)
{
let list = "";
for (let [,message] in Iterator(messageHistory.messages))
list += message + "<br/>";
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}
}, { argCount: "0" });
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION //////////////////////////////////////////
@@ -466,7 +544,7 @@ liberator.CommandLine = function () //{{{
DISALLOW_MULTILINE : 1 << 2, // if an echo() should try to use the single line
// but output nothing when the MOW is open; when also
// FORCE_MULTILINE is given, FORCE_MULTILINE takes precedence
APPEND_TO_MESSAGES : 1 << 3, // will show the string in :messages
APPEND_TO_MESSAGES : 1 << 3, // add the string to the message history
get mode() (liberator.modes.extended == liberator.modes.EX) ? "cmd" : "search",
@@ -523,7 +601,6 @@ liberator.CommandLine = function () //{{{
setLine("", this.HL_NORMAL);
},
// TODO: add :messages entry
// liberator.echo uses different order of flags as it omits the hightlight group, change v.commandline.echo argument order? --mst
echo: function (str, highlightGroup, flags)
{
@@ -540,6 +617,9 @@ liberator.CommandLine = function () //{{{
highlightGroup = highlightGroup || this.HL_NORMAL;
if (flags & this.APPEND_TO_MESSAGES)
messageHistory.add(str);
var where = setLine;
if (flags & this.FORCE_MULTILINE)
where = setMultiline;
@@ -1133,8 +1213,8 @@ liberator.ItemList = function (id) //{{{
doc.body.id = id + "-content";
var id = liberator.config.mainWindowID || "main-window";
var fontSize = document.defaultView.getComputedStyle(document.getElementById(id), null).getPropertyValue("font-size");
var mainWindowID = liberator.config.mainWindowID || "main-window";
var fontSize = document.defaultView.getComputedStyle(document.getElementById(mainWindowID), null).getPropertyValue("font-size");
doc.body.setAttribute("style", "font-size: " + fontSize);
var completions = []; // a reference to the Array of completions

View File

@@ -106,7 +106,7 @@ liberator.config = { //{{{
"buffer.html", "cmdline.html", "options.html", "pattern.html",
"tabs.html", "hints.html", "map.html", "eval.html", "marks.html",
"repeat.html", "autocommands.html", "print.html", "gui.html",
"developer.html", "various.html", "index.html"
"message.html", "developer.html", "various.html", "index.html"
],
init: function ()