1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-13 10:23:36 +02:00

rename :qmarkadd :qmark and :qmarkdel :delqmarks, sort :qmarks list output and

limit buffer marks to [a-zA-Z]
This commit is contained in:
Doug Kearns
2007-08-11 09:28:21 +00:00
parent 2a4cfbc4e3
commit 575833ac86
4 changed files with 168 additions and 81 deletions

View File

@@ -1,6 +1,7 @@
<pre> <pre>
2007-07-02: 2007-07-02:
* version 0.5 * version 0.5
* rename :qmarkadd :qmark and :qmarkdel :delqmarks
* vimperator.events.feedkeys("2zi") support for scripts * vimperator.events.feedkeys("2zi") support for scripts
* Ctrl-U/Ctrl-D for scrolling the window up/down and the associated * Ctrl-U/Ctrl-D for scrolling the window up/down and the associated
'scroll' option 'scroll' option

View File

@@ -532,6 +532,7 @@ function Marks() //{{{
{ {
// local marks // local marks
var lmarks = []; var lmarks = [];
for (var mark in local_marks) for (var mark in local_marks)
{ {
for (var i = 0; i < local_marks[mark].length; i++) for (var i = 0; i < local_marks[mark].length; i++)
@@ -544,17 +545,18 @@ function Marks() //{{{
// URL marks // URL marks
var umarks = []; var umarks = [];
for (var mark in url_marks) for (var mark in url_marks)
umarks.push([mark, url_marks[mark]]); umarks.push([mark, url_marks[mark]]);
// FIXME: why does umarks.sort() cause a "Component is not available = // FIXME: why does umarks.sort() cause a "Component is not available =
// NS_ERROR_NOT_AVAILABLE" exception when used here? // NS_ERROR_NOT_AVAILABLE" exception when used here?
umarks.sort(function(a, b) { umarks.sort(function(a, b) {
if (a[0] < b[0]) if (a[0] < b[0])
return -1; return -1;
else if (a[0] > b[0]) else if (a[0] > b[0])
return 1; return 1;
else else
return 0; return 0;
}); });
return lmarks.concat(umarks); return lmarks.concat(umarks);
@@ -578,6 +580,7 @@ function Marks() //{{{
var x = win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0; var x = win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0;
var y = win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0; var y = win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0;
var position = { x: x, y: y }; var position = { x: x, y: y };
if (isURLMark(mark)) if (isURLMark(mark))
{ {
vimperator.log("Adding URL mark: " + mark + " | " + win.location.href + " | (" + position.x + ", " + position.y + ") | tab: " + vimperator.tabs.index(vimperator.tabs.getTab()), 5); vimperator.log("Adding URL mark: " + mark + " | " + win.location.href + " | (" + position.x + ", " + position.y + ") | tab: " + vimperator.tabs.index(vimperator.tabs.getTab()), 5);
@@ -621,6 +624,7 @@ function Marks() //{{{
this.jumpTo = function(mark) this.jumpTo = function(mark)
{ {
var ok = false; var ok = false;
if (isURLMark(mark)) if (isURLMark(mark))
{ {
var slice = url_marks[mark]; var slice = url_marks[mark];
@@ -655,6 +659,7 @@ function Marks() //{{{
{ {
var win = window.content; var win = window.content;
var slice = local_marks[mark] || []; var slice = local_marks[mark] || [];
for (var i = 0; i < slice.length; i++) for (var i = 0; i < slice.length; i++)
{ {
if (win.location.href == slice[i].location) if (win.location.href == slice[i].location)
@@ -716,70 +721,96 @@ function QuickMarks() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var marks = {}; var qmarks = {};
// load the saved quickmarks -- TODO: change to sqlite // load the saved quickmarks -- TODO: change to sqlite
var saved_marks = Options.getPref("quickmarks", "").split("\n"); var saved_marks = Options.getPref("quickmarks", "").split("\n");
for (var i = 0; i < saved_marks.length - 1; i += 2) for (var i = 0; i < saved_marks.length - 1; i += 2)
{ {
marks[saved_marks[i]] = saved_marks[i + 1]; qmarks[saved_marks[i]] = saved_marks[i + 1];
} }
// TODO: should we sort by a-zA-Z0-9 rather than 0-9A-Za-z?
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
this.add = function(mark, location) this.add = function(qmark, location)
{ {
marks[mark] = location; qmarks[qmark] = location;
} }
this.remove = function(filter) this.remove = function(filter)
{ {
var pattern = new RegExp("[" + filter.replace(/\s+/g, '') + "]"); var pattern = new RegExp("[" + filter.replace(/\s+/g, '') + "]");
for (var mark in marks)
for (var qmark in qmarks)
{ {
if (pattern.test(mark)) if (pattern.test(qmark))
delete marks[mark]; delete qmarks[qmark];
} }
} }
this.jumpTo = function(mark, where) this.jumpTo = function(qmark, where)
{ {
var url = marks[mark]; var url = qmarks[qmark];
if (url) if (url)
vimperator.open(url, where); vimperator.open(url, where);
else else
vimperator.echoerr("E20: QuickMark not set"); vimperator.echoerr("E20: QuickMark not set");
} }
this.list = function() this.list = function(filter)
{ {
var is_empty = true; var marks = [];
var list = "<table><tr style=\"color: magenta\"><td>mark</td><td>URL</td></tr>";
for (var i in marks) // TODO: should we sort these in a-zA-Z0-9 order?
for (var mark in qmarks)
marks.push([mark, qmarks[mark]]);
marks.sort();
if (marks.length == 0)
{ {
is_empty = false; vimperator.echoerr("No marks set");
list += "<tr><td>&nbsp;" + i + "</td><td>" return;
+ marks[i] + "</td></tr>"; }
if (filter.length > 0)
{
marks = marks.filter(function(mark) {
if (filter.indexOf(mark[0]) > -1)
return mark;
});
if (marks.length == 0)
{
vimperator.echoerr("E283: No QuickMarks matching \"" + filter + "\"");
return;
}
}
var list = "<table><tr style=\"color: magenta\"><td>QuickMark</td><td>URL</td></tr>";
for (var i = 0; i < marks.length; i++)
{
list += "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;" + marks[i][0] + "</td><td>" + marks[i][1] + "</td></tr>";
} }
list += "</table>"; list += "</table>";
if (!is_empty) vimperator.commandline.echo(list, true); // TODO: force of multiline widget a better way
vimperator.commandline.echo(list, true); // TODO: force of multiline widget a better way
else
vimperator.echoerr("No quickmarks defined");
} }
this.destroy = function() this.destroy = function()
{ {
// save the marks // save the quickmarks
var saved_marks = ""; var saved_qmarks = "";
for (var i in marks)
for (var i in qmarks)
{ {
saved_marks += i + "\n"; saved_qmarks += i + "\n";
saved_marks += marks[i] + "\n"; saved_qmarks += qmarks[i] + "\n";
} }
Options.setPref("quickmarks", saved_marks);
Options.setPref("quickmarks", saved_qmarks);
} }
//}}} //}}}
} //}}} } //}}}

View File

@@ -421,8 +421,8 @@ function Commands() //{{{
vimperator.marks.remove(args, special); vimperator.marks.remove(args, special);
}, },
{ {
usage: ["delm[arks][!] {marks}"], usage: ["delm[arks] {marks}", "delm[arks]!"],
short_help: "Delete the specified marks {a-zA-Z}", short_help: "Delete the specified marks",
help: "Marks are presented as a list. Example:<br/>" + help: "Marks are presented as a list. Example:<br/>" +
"<code class=\"command\">:delmarks Aa b p</code> will delete marks A, a, b and p<br/>" + "<code class=\"command\">:delmarks Aa b p</code> will delete marks A, a, b and p<br/>" +
"<code class=\"command\">:delmarks b-p</code> will delete all marks in the range b to p<br/>" + "<code class=\"command\">:delmarks b-p</code> will delete all marks in the range b to p<br/>" +
@@ -430,6 +430,32 @@ function Commands() //{{{
} }
)); ));
addDefaultCommand(new Command(["delqm[arks]"],
function(args, special)
{
// TODO: finish arg parsing - we really need a proper way to do this. :)
if (!special && !args)
{
vimperator.echoerr("E471: Argument required");
return;
}
if (special && args)
{
vimperator.echoerr("E474: Invalid argument");
return
}
vimperator.quickmarks.remove(args);
},
{
usage: ["delqm[arks] {marks}", "delqm[arks]!"],
short_help: "Delete the specified QuickMarks",
help: "QuickMarks are presented as a list. Example:<br/>" +
"<code class=\"command\">:delqmarks Aa b p</code> will delete QuickMarks A, a, b and p<br/>" +
"<code class=\"command\">:delqmarks b-p</code> will delete all QuickMarks in the range b to p<br/>" +
"<code class=\"command\">:delqmarks!</code> will delete all QuickMarks"
}
));
addDefaultCommand(new Command(["downl[oads]", "dl"], addDefaultCommand(new Command(["downl[oads]", "dl"],
function() { vimperator.open("chrome://mozapps/content/downloads/downloads.xul", vimperator.NEW_TAB); }, function() { vimperator.open("chrome://mozapps/content/downloads/downloads.xul", vimperator.NEW_TAB); },
{ {
@@ -619,7 +645,7 @@ function Commands() //{{{
}, },
{ {
short_help: "Remove all mappings", short_help: "Remove all mappings",
help: "" help: "TODO"
} }
)); ));
addDefaultCommand(new Command(["ma[rk]"], addDefaultCommand(new Command(["ma[rk]"],
@@ -642,24 +668,27 @@ function Commands() //{{{
vimperator.marks.add(args); vimperator.marks.add(args);
}, },
{ {
usage: ["ma[rk] {arg}"], usage: ["ma[rk] {a-zA-Z}"],
short_help: "Mark current location within the web page" short_help: "Mark current location within the web page"
} }
)); ));
addDefaultCommand(new Command(["marks"], addDefaultCommand(new Command(["marks"],
function(args) function(args)
{ {
if (args.length > 1 && !/[a-zA-Z]/.test(args)) // ignore invalid mark characters unless there are no valid mark chars
if (args.length > 0 && !/[a-zA-Z]/.test(args))
{ {
vimperator.echoerr("E283: No marks matching \"" + args + "\""); vimperator.echoerr("E283: No marks matching \"" + args + "\"");
return; return;
} }
var filter = args.replace(/[^a-zA-Z]/g, ''); var filter = args.replace(/[^a-zA-Z]/g, '');
vimperator.marks.list(filter) vimperator.marks.list(filter)
}, },
{ {
usage: ["marks {arg}"], usage: ["marks [arg]"],
short_help: "Show all location marks of current web page" short_help: "Show all location marks of current web page",
help: "If <code class=\"argument\">[arg]</code> is specified then limit the list to the those marks mentioned."
} }
)); ));
// TODO: remove duplication in :map // TODO: remove duplication in :map
@@ -771,6 +800,50 @@ function Commands() //{{{
"Works like <code class=\"command\">:set!</code>, but opens the dialog in a new window instead of a new tab. Use this, if you experience problems/crashes when using <code class=\"command\">:set!</code>" "Works like <code class=\"command\">:set!</code>, but opens the dialog in a new window instead of a new tab. Use this, if you experience problems/crashes when using <code class=\"command\">:set!</code>"
} }
)); ));
addDefaultCommand(new Command(["qma[rk]"],
function(args)
{
if (!args) {
vimperator.echoerr("E471: Argument required");
return;
}
var matches1 = args.match(/([a-zA-Z0-9])\s+(.+)/);
var matches2 = args.match(/([a-zA-Z0-9])\s*$/);
if (matches1 && matches1[1])
vimperator.quickmarks.add(matches1[1], matches1[2]);
else if (matches2 && matches2)
vimperator.quickmarks.add(matches2[1], vimperator.buffer.location);
else
vimperator.echoerr("E488: Trailing characters");
},
{
usage: ["qma[rk] {a-zA-Z0-9} [url]"],
short_help: "Mark a URL with a letter for quick access",
help: "You can also mark whole groups like this: <br/>"+
"<code class=\"command\">:qmark f http://forum1.com, http://forum2.com, imdb some artist</code>"
}
));
addDefaultCommand(new Command(["qmarks"],
function(args)
{
// ignore invalid mark characters unless there are no valid mark chars
if (args.length > 0 && !/[a-zA-Z0-9]/.test(args))
{
vimperator.echoerr("E283: No QuickMarks matching \"" + args + "\"");
return;
}
var filter = args.replace(/[^a-zA-Z0-9]/g, '');
vimperator.quickmarks.list(filter);
},
{
usage: ["qmarks [arg]"],
short_help: "Show all QuickMarks",
help: "If <code class=\"argument\">[arg]</code> is specified then limit the list to the those QuickMarks mentioned."
}
));
addDefaultCommand(new Command(["q[uit]"], addDefaultCommand(new Command(["q[uit]"],
function() { vimperator.tabs.remove(getBrowser().mCurrentTab, 1, false, 1); }, function() { vimperator.tabs.remove(getBrowser().mCurrentTab, 1, false, 1); },
{ {
@@ -1045,42 +1118,6 @@ function Commands() //{{{
help: "If a count is given, don't close the last but the n'th last tab." help: "If a count is given, don't close the last but the n'th last tab."
} }
)); ));
addDefaultCommand(new Command(["qmarka[dd]", "qma[dd]"],
function(args)
{
var matches1 = args.match(/([a-zA-Z0-9])\s+(.+)/);
var matches2 = args.match(/([a-zA-Z0-9])\s*$/);
if (matches1 && matches1[1])
vimperator.quickmarks.add(matches1[1], matches1[2]);
else if (matches2 && matches2)
vimperator.quickmarks.add(matches2[1], vimperator.buffer.location);
else
vimperator.echoerr("E488: Trailing characters");
},
{
usage: ["qmarka[dd] {a-zA-Z0-9} [url]"],
short_help: "Mark a URL with a letter for quick access",
help: "You can also mark whole groups like this: <br/>"+
"<code class=\"command\">:qmarkadd f http://forum1.com, http://forum2.com, imdb some artist</code>",
completer: function(filter) { return [["a", ""], ["b", ""]]; }
}
));
addDefaultCommand(new Command(["qmarkd[el]", "qmd[el]"],
function(args) { vimperator.quickmarks.remove(args); },
{
usage: ["qmarkd[el] {a-zA-Z0-9}"],
short_help: "Remove a marked URL",
help: "TODO.",
completer: function(filter) { return [["a", ""], ["b", ""]]; }
}
));
addDefaultCommand(new Command(["qmarks", "qms"],
function(args) { vimperator.quickmarks.list(args); },
{
short_help: "Show marked URLs",
help: "TODO."
}
));
addDefaultCommand(new Command(["unm[ap]"], addDefaultCommand(new Command(["unm[ap]"],
function(args) function(args)
{ {

View File

@@ -299,8 +299,8 @@ function Mappings() //{{{
function(arg) { vimperator.marks.jumpTo(arg) }, function(arg) { vimperator.marks.jumpTo(arg) },
{ {
short_help: "Jump to the mark in the current buffer", short_help: "Jump to the mark in the current buffer",
usage: ["'{a-zA-Z0-9}"], usage: ["'{a-zA-Z}"],
help: "Marks a-z are local to the buffer, whereas A-Z and 0-9 are valid between buffers.", help: "Marks a-z are local to the buffer, whereas A-Z are valid between buffers.",
flags: Mappings.flags.ARGUMENT flags: Mappings.flags.ARGUMENT
} }
)); ));
@@ -452,16 +452,34 @@ function Mappings() //{{{
} }
)); ));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["m"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["m"],
function(arg) { vimperator.marks.add(arg) }, function(arg)
{
if (/[^a-zA-Z]/.test(arg))
{
vimperator.beep();
return;
}
vimperator.marks.add(arg)
},
{ {
short_help: "Set mark at the cursor position", short_help: "Set mark at the cursor position",
usage: ["m{a-zA-Z0-9}"], usage: ["m{a-zA-Z}"],
help: "Marks a-z are local to the buffer, whereas A-Z and 0-9 are valid between buffers.", help: "Marks a-z are local to the buffer, whereas A-Z are valid between buffers.",
flags: Mappings.flags.ARGUMENT flags: Mappings.flags.ARGUMENT
} }
)); ));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["M"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["M"],
function(arg) { vimperator.quickmarks.add(arg, vimperator.buffer.location) }, function(arg)
{
if (/[^a-zA-Z0-9]/.test(arg))
{
vimperator.beep();
return;
}
vimperator.quickmarks.add(arg, vimperator.buffer.location)
},
{ {
short_help: "Add new QuickMark for current URL", short_help: "Add new QuickMark for current URL",
usage: ["M{a-zA-Z0-9}"], usage: ["M{a-zA-Z0-9}"],