Skip to content

Instantly share code, notes, and snippets.

@stepnem
Created August 12, 2012 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepnem/3331062 to your computer and use it in GitHub Desktop.
Save stepnem/3331062 to your computer and use it in GitHub Desktop.
Jump to a command, mapping or option source definition from Pentadactyl
[.pentadactylrc:]
com! jumptodef,jd -literal=1 -nargs=1 -complete help
\ -js buffer.viewSource(plugins.misc.sourceLocation(args[0]))
[plugins/misc.js:]
function sourceLocation(str) {
if (isArray(str))
str = str[0];
function mapping(s) {
let [, mc, key] = /(?:(.)_)?(.*)/.exec(s);
return mappings.get(mc ? modes.modeChars[mc] : modes.NORMAL, key) ||
dactyl.echoerr("Bad bad: " + s);
}
let frame = ((str[0] === ":") ? commands.get(str.substr(1)) :
/'.*?'/.test(str) ? options.get(str.slice(1,-1)) :
mapping(str)).definedAt;
return { url: util.fixURI(frame.filename), line: frame.lineNumber };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment