mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 22:38:00 +01:00
Do something sensible for items defined from :map/:com/... in :*usage!.
This commit is contained in:
@@ -453,7 +453,7 @@ const Commands = Module("commands", {
|
|||||||
_addCommand: function (args, replace) {
|
_addCommand: function (args, replace) {
|
||||||
if (!args[3])
|
if (!args[3])
|
||||||
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]));
|
let names = array.flatten(Command.parseSpecs(args[0]));
|
||||||
dactyl.assert(!names.some(function (name) name in this._exMap && !this._exMap[name].user, this),
|
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);
|
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
|
* Returns true if a command invocation contains a URL referring to the
|
||||||
* domain *host*.
|
* domain *host*.
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ const Mappings = Module("mappings", {
|
|||||||
|
|
||||||
_addMap: function (map) {
|
_addMap: function (map) {
|
||||||
let where = map.user ? this._user : this._main;
|
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) {
|
map.modes.forEach(function (mode) {
|
||||||
if (!(mode in where))
|
if (!(mode in where))
|
||||||
where[mode] = [];
|
where[mode] = [];
|
||||||
|
|||||||
@@ -642,7 +642,7 @@ const Options = Module("options", {
|
|||||||
if (!extraInfo)
|
if (!extraInfo)
|
||||||
extraInfo = {};
|
extraInfo = {};
|
||||||
|
|
||||||
extraInfo.definedAt = Components.stack.caller;
|
extraInfo.definedAt = commands.getCaller(Components.stack.caller);
|
||||||
|
|
||||||
let name = names[0];
|
let name = names[0];
|
||||||
if (name in this._optionMap) {
|
if (name in this._optionMap) {
|
||||||
|
|||||||
@@ -289,6 +289,14 @@ const Template = Module("Template", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
usage: function usage(iter) {
|
usage: function usage(iter) {
|
||||||
|
function getPath(url) {
|
||||||
|
try {
|
||||||
|
return util.getFile(util.newURI(url)).path;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
// <e4x>
|
// <e4x>
|
||||||
return <table>
|
return <table>
|
||||||
{
|
{
|
||||||
@@ -297,15 +305,12 @@ const Template = Module("Template", {
|
|||||||
<td style="padding-right: 20px" highlight="Usage">{
|
<td style="padding-right: 20px" highlight="Usage">{
|
||||||
let (name = item.name || item.names[0], frame = item.definedAt)
|
let (name = item.name || item.names[0], frame = item.definedAt)
|
||||||
!frame ? name : /* Help... --Kris */
|
!frame ? name : /* Help... --Kris */
|
||||||
let (url = frame.filename.replace(/.* -> /, ""))
|
let (url = (frame.filename || "unknown").replace(/.* -> /, ""))
|
||||||
<><span highlight="Title">{name}</span> 
|
<><span highlight="Title">{name}</span> 
|
||||||
<span highlight="LineInfo">
|
<span highlight="LineInfo">
|
||||||
Defined at <a xmlns:dactyl={NS} dactyl:command="buffer.viewSource"
|
Defined at <a xmlns:dactyl={NS} dactyl:command="buffer.viewSource"
|
||||||
href={url} line={frame.lineNumber}
|
href={url} line={frame.lineNumber}
|
||||||
highlight="URL">{
|
highlight="URL">{ getPath(url) + ":" + frame.lineNumber }</a>
|
||||||
(util.getFile(util.newURI(url)) || { path: url }).path
|
|
||||||
+ ":" + frame.lineNumber
|
|
||||||
}</a>
|
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
}</td>
|
}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user