From 75342f09ecb1331a1f0777ece9754b0a93e7d5b1 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 9 Dec 2010 22:25:20 -0500 Subject: [PATCH] Do something sensible for items defined from :map/:com/... in :*usage!. --- common/content/commands.js | 18 +++++++++++++++++- common/content/mappings.js | 2 +- common/content/options.js | 2 +- common/modules/template.jsm | 15 ++++++++++----- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/common/content/commands.js b/common/content/commands.js index 9aef751e..4b7d99b4 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -453,7 +453,7 @@ const Commands = Module("commands", { _addCommand: function (args, replace) { if (!args[3]) args[3] = {}; - args[3].definedAt = Components.stack.caller.caller; + args[3].definedAt = commands.getCaller(Components.stack.caller.caller); let names = array.flatten(Command.parseSpecs(args[0])); dactyl.assert(!names.some(function (name) name in this._exMap && !this._exMap[name].user, this), @@ -636,6 +636,22 @@ const Commands = Module("commands", { return this._exCommands.filter(function (cmd) cmd.user); }, + /** + * Returns a frame object describing the currently executing + * command, if applicable, otherwise returns the passed frame. + * + * @param {nsIStackFrame} frame + */ + getCaller: function (frame) { + if (io.sourcing) + return { + __proto__: frame, + filename: services.io.newFileURI(File(io.sourcing.file)).spec, + lineNumber: io.sourcing.line + }; + return frame; + }, + /** * Returns true if a command invocation contains a URL referring to the * domain *host*. diff --git a/common/content/mappings.js b/common/content/mappings.js index 5885b197..a1681aa1 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -140,7 +140,7 @@ const Mappings = Module("mappings", { _addMap: function (map) { let where = map.user ? this._user : this._main; - map.definedAt = Components.stack.caller.caller; + map.definedAt = commands.getCaller(Components.stack.caller.caller); map.modes.forEach(function (mode) { if (!(mode in where)) where[mode] = []; diff --git a/common/content/options.js b/common/content/options.js index 48a5ab23..2bf4f6d5 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -642,7 +642,7 @@ const Options = Module("options", { if (!extraInfo) extraInfo = {}; - extraInfo.definedAt = Components.stack.caller; + extraInfo.definedAt = commands.getCaller(Components.stack.caller); let name = names[0]; if (name in this._optionMap) { diff --git a/common/modules/template.jsm b/common/modules/template.jsm index e0f771fe..fcc3283e 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -289,6 +289,14 @@ const Template = Module("Template", { }, usage: function usage(iter) { + function getPath(url) { + try { + return util.getFile(util.newURI(url)).path; + } + catch (e) { + return url; + } + } // return { @@ -297,15 +305,12 @@ const Template = Module("Template", {
{ let (name = item.name || item.names[0], frame = item.definedAt) !frame ? name : /* Help... --Kris */ - let (url = frame.filename.replace(/.* -> /, "")) + let (url = (frame.filename || "unknown").replace(/.* -> /, "")) <>{name}  Defined at { - (util.getFile(util.newURI(url)) || { path: url }).path - + ":" + frame.lineNumber - } + highlight="URL">{ getPath(url) + ":" + frame.lineNumber } }