1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 07:28:00 +01:00

Allow specifying line numbers in 'editor'. Take advantage in <C-i> and view-source links.

This commit is contained in:
Kris Maglione
2010-12-09 21:37:21 -05:00
parent e339032fd2
commit c5a1291eac
4 changed files with 83 additions and 36 deletions

View File

@@ -964,18 +964,15 @@ const Buffer = Module("buffer", {
let doc = buffer.focusedFrame.document;
if (isArray(url)) {
if (options.get("editor").has("l"))
this.viewSourceExternally(url[0] || doc, url[1]);
else {
let chrome = "chrome://global/content/viewSource.xul";
window.openDialog(chrome, "_blank", "all,dialog=no",
url[0], null, null, url[1]);
/* FIXME
let win = dactyl.open(chrome)[0];
while (win.document.documentURI != chrome)
util.threadYield(false, true);
win.arguments = [url[0], null, null, url[1]];
*/
return;
}
}
else {
if (useExternalEditor)
this.viewSourceExternally(url || doc);
else {
@@ -992,6 +989,7 @@ const Buffer = Module("buffer", {
else
dactyl.open(url, { hide: true });
}
}
},
/**
@@ -1011,8 +1009,8 @@ const Buffer = Module("buffer", {
viewSourceExternally: Class("viewSourceExternally",
XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), {
init: function (doc, callback) {
this.callback = callback ||
function (file) editor.editFileExternally(file.path);
this.callback = callable(callback) ? callback :
function (file) editor.editFileExternally(file.path, callback);
let url = isString(doc) ? doc : doc.location.href;
let uri = util.newURI(url, charset);

View File

@@ -241,13 +241,11 @@ const Editor = Module("editor", {
return -1;
},
editFileExternally: function (path) {
// TODO: save return value in v:shell_error
let args = commands.parseArgs(options["editor"], { argCount: "*", allowUnknownOptions: true });
editFileExternally: function (path, line, column) {
let args = options.get("editor").format({ f: path, l: line, c: column });
dactyl.assert(args.length >= 1, "No editor specified");
args.push(path);
io.run(io.expandPath(args.shift()), args, true);
},
@@ -257,6 +255,7 @@ const Editor = Module("editor", {
return;
let textBox = config.isComposeWindow ? null : dactyl.focus;
let line, column;
if (!forceEditing && textBox && textBox.type == "password") {
commandline.input("Editing a password field externally will reveal the password. Would you like to continue? (yes/[no]): ",
@@ -267,8 +266,12 @@ const Editor = Module("editor", {
return;
}
if (textBox)
if (textBox) {
var text = textBox.value;
let pre = text.substr(0, textBox.selectionStart);
line = 1 + pre.replace(/[^\n]/g, "").length;
column = 1 + pre.replace(/[^]*\n/, "").length;
}
else {
var editor = window.GetCurrentEditor ? GetCurrentEditor()
: Editor.getEditor(document.commandDispatcher.focusedWindow);
@@ -310,7 +313,7 @@ const Editor = Module("editor", {
timer.initWithCallback({ notify: update }, 100, timer.TYPE_REPEATING_SLACK);
try {
this.editFileExternally(tmpfile.path);
this.editFileExternally(tmpfile.path, line, column);
}
finally {
timer.cancel();
@@ -770,7 +773,21 @@ const Editor = Module("editor", {
options: function () {
options.add(["editor"],
"Set the external text editor",
"string", "gvim -f");
"string", "gvim -f +%l %f", {
format: function (obj, value) {
let args = commands.parseArgs(value || this.value, { argCount: "*", allowUnknownOptions: true })
.map(util.compileFormat).filter(function (fmt) fmt.valid(obj))
.map(function (fmt) fmt(obj));
if (obj["f"] && !this.has("f"))
args.push(obj["f"]);
return args;
},
has: function (key) set.has(util.compileFormat(this.value).seen, key),
validator: function (value) {
this.format({}, value);
return Object.keys(util.compileFormat(value).seen).every(function (k) "cfl".indexOf(k) >= 0)
}
});
options.add(["insertmode", "im"],
"Use Insert mode as the default for text areas",

View File

@@ -69,6 +69,25 @@
</dd>
</dl>
<p tag="format-string">
Some options may be given format strings containing %-delimited escape
sequences. Character sequences in the form of <em>%</em><a>character</a> are
substituted by a specified replacement string. If <a>character</a> is
upper-case, then the string is automatically
<link topic="quoting">quoted</link>. Any substring enclosed by <em>%[</em>
and <em>%]</em> is automatically elided if any of the contained format
characters aren't currently valid. A literal <em>%</em> character may be
included with the special escape sequence <em>%%</em>.
</p>
<p>
For example, given the format string <str>%[(cmd: %c) %]%[line: %l %]%F</str>,
where <em>l</em>=<hl key="Number">32</hl> and
<em>f</em>=<str delim="'">Lieder eines fahrenden Gesellen.txt</str>,
the result is formatted as
<str>line: 32 'Lieder eines fahrenden Gesellen.txt'</str>
</p>
<h2 tag="set-option E764">Setting options</h2>
<item>
@@ -544,6 +563,19 @@
other commands which launch an external text editor.
</p>
<p>
Accepts a <t>format-string</t> with the following escapes available.
Arguments containing escapes which are not relevant to a given call
are automatically elided. All field splitting is done before format
characters are processed.
</p>
<dl>
<dt>%f</dt> <dd>The file to edit. Appended as the final argument if missing.</dd>
<dt>%l</dt> <dd>The line number at which to position the cursor.</dd>
<dt>%c</dt> <dd>The column at which to position the cursor.</dd>
</dl>
<warning>
&dactyl.appName; will not behave correctly if the editor forks its
own process rather than blocking until editing is complete. Gvim

View File

@@ -182,11 +182,11 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
stack.top.elements.push(update(
function (obj) obj[char] != null ? quote(obj, char) : "",
{ test: function (obj) obj[char] != null }));
}
for (let elem in array.iterValues(stack))
elem.seen[char] = true;
}
}
if (end < format.length)
stack.top.elements.push(format.substr(end));