mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 07:08:00 +01:00
Update :au to use args parser, and perform certain replacements (more to come?).
This commit is contained in:
@@ -44,9 +44,9 @@ liberator.Bookmarks = function () //{{{
|
|||||||
.getService(Components.interfaces.nsIFaviconService);
|
.getService(Components.interfaces.nsIFaviconService);
|
||||||
|
|
||||||
const storage = liberator.storage;
|
const storage = liberator.storage;
|
||||||
|
const properties = { url: 0, title: 1, keyword: 2, tags: 3, id: 4, icon: 5 };
|
||||||
function Cache(name, store, serial)
|
function Cache(name, store, serial)
|
||||||
{
|
{
|
||||||
const properties = { uri: 0, title: 1, keyword: 2, tags: 3, id: 4, icon: 5 };
|
|
||||||
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
|
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
|
||||||
|
|
||||||
var bookmarks = [];
|
var bookmarks = [];
|
||||||
@@ -67,7 +67,7 @@ liberator.Bookmarks = function () //{{{
|
|||||||
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
||||||
let tags = taggingService.getTagsForURI(uri, {}) || [];
|
let tags = taggingService.getTagsForURI(uri, {}) || [];
|
||||||
let icon = faviconService.getFaviconImageForPage(uri).spec;
|
let icon = faviconService.getFaviconImageForPage(uri).spec;
|
||||||
bookmarks.push([node.uri, node.title, keyword, tags, node.itemId, icon]);
|
return bookmarks.push([node.uri, node.title, keyword, tags, node.itemId, icon]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBookmark(id)
|
function readBookmark(id)
|
||||||
@@ -144,8 +144,8 @@ liberator.Bookmarks = function () //{{{
|
|||||||
{
|
{
|
||||||
if (rootFolders.indexOf(findRoot(itemId)) >= 0)
|
if (rootFolders.indexOf(findRoot(itemId)) >= 0)
|
||||||
{
|
{
|
||||||
loadBookmark(readBookmark(itemId));
|
let bmark = loadBookmark(readBookmark(itemId));
|
||||||
storage.fireEvent(name, "add", itemId);
|
storage.fireEvent(name, "add", bmark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -164,7 +164,7 @@ liberator.Bookmarks = function () //{{{
|
|||||||
if (bookmark)
|
if (bookmark)
|
||||||
{
|
{
|
||||||
if (property == "tags")
|
if (property == "tags")
|
||||||
value = taggingService.getTagsForURI(ioService.newURI(bookmark[properties.uri], null, null), {});
|
value = taggingService.getTagsForURI(ioService.newURI(bookmark[properties.url], null, null), {});
|
||||||
if (property in properties)
|
if (property in properties)
|
||||||
bookmark[properties[property]] = value;
|
bookmark[properties[property]] = value;
|
||||||
storage.fireEvent(name, "change", itemId);
|
storage.fireEvent(name, "change", itemId);
|
||||||
@@ -184,9 +184,15 @@ liberator.Bookmarks = function () //{{{
|
|||||||
let bookmarkObserver = function (key, event, arg)
|
let bookmarkObserver = function (key, event, arg)
|
||||||
{
|
{
|
||||||
if (event == "add")
|
if (event == "add")
|
||||||
liberator.autocommands.trigger("BookmarkAdd", "");
|
{
|
||||||
|
let args = {};
|
||||||
|
for (let [k, v] in Iterator(properties))
|
||||||
|
args[k] = arg[v];
|
||||||
|
liberator.autocommands.trigger("BookmarkAdd", args);
|
||||||
|
}
|
||||||
liberator.statusline.updateUrl();
|
liberator.statusline.updateUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cache = liberator.storage.newObject("bookmark-cache", Cache, false);
|
var cache = liberator.storage.newObject("bookmark-cache", Cache, false);
|
||||||
liberator.storage.addObserver("bookmark-cache", bookmarkObserver);
|
liberator.storage.addObserver("bookmark-cache", bookmarkObserver);
|
||||||
liberator.registerObserver("shutdown", function () {
|
liberator.registerObserver("shutdown", function () {
|
||||||
|
|||||||
@@ -72,61 +72,49 @@ liberator.AutoCommands = function () //{{{
|
|||||||
"Execute commands automatically on events",
|
"Execute commands automatically on events",
|
||||||
function (args, special)
|
function (args, special)
|
||||||
{
|
{
|
||||||
if (!args)
|
let [event, regex] = args.arguments;
|
||||||
|
let cmd = args.literalArg;
|
||||||
|
let events = null;
|
||||||
|
if (event)
|
||||||
{
|
{
|
||||||
if (special)
|
|
||||||
liberator.autocommands.remove(null, null); // remove all
|
|
||||||
else
|
|
||||||
liberator.autocommands.list(null, null); // list all
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO: assume the pattern doesn't contain spaces until we have whitespace escaping
|
|
||||||
let [, event, regex, cmd] = args.match(/^(\S+)?(?:\s+)?(\S+)?(?:\s+)?(.+)?$/);
|
|
||||||
|
|
||||||
// NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}|
|
// NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}|
|
||||||
let events = event.split(",");
|
|
||||||
let validEvents = liberator.config.autocommands.map(function (event) event[0]);
|
let validEvents = liberator.config.autocommands.map(function (event) event[0]);
|
||||||
|
|
||||||
validEvents.push("*");
|
validEvents.push("*");
|
||||||
|
|
||||||
|
events = event.split(",");
|
||||||
if (!events.every(function (event) validEvents.indexOf(event) >= 0))
|
if (!events.every(function (event) validEvents.indexOf(event) >= 0))
|
||||||
{
|
{
|
||||||
liberator.echoerr("E216: No such group or event: " + args);
|
liberator.echoerr("E216: No such group or event: " + event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cmd) // add new command, possibly removing all others with the same event/pattern
|
if (cmd) // add new command, possibly removing all others with the same event/pattern
|
||||||
{
|
{
|
||||||
if (special)
|
if (special)
|
||||||
liberator.autocommands.remove(event, regex);
|
liberator.autocommands.remove(event, regex);
|
||||||
|
|
||||||
liberator.autocommands.add(events, regex, cmd);
|
liberator.autocommands.add(events, regex, cmd);
|
||||||
}
|
}
|
||||||
else if (regex)
|
|
||||||
{
|
|
||||||
if (special)
|
|
||||||
liberator.autocommands.remove(event == "*" ? null : event, regex);
|
|
||||||
else
|
else
|
||||||
liberator.autocommands.list(event == "*" ? null : event, regex);
|
|
||||||
}
|
|
||||||
else if (event)
|
|
||||||
{
|
{
|
||||||
|
if (event == "*")
|
||||||
|
event = null;
|
||||||
if (special)
|
if (special)
|
||||||
{
|
{
|
||||||
// TODO: "*" only appears to work in Vim when there is a {group} specified
|
// TODO: "*" only appears to work in Vim when there is a {group} specified
|
||||||
if (event != "*")
|
if (args.arguments[0] != "*" || regex)
|
||||||
liberator.autocommands.remove(event, null);
|
liberator.autocommands.remove(event, regex); // remove all
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
liberator.autocommands.list(event == "*" ? null : event, null);
|
liberator.autocommands.list(event, regex); // list all
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
argCount: 2,
|
||||||
bang: true,
|
bang: true,
|
||||||
|
literal: true,
|
||||||
completer: function (filter) liberator.completion.event(filter)
|
completer: function (filter) liberator.completion.event(filter)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -166,10 +154,11 @@ liberator.AutoCommands = function () //{{{
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: perhaps trigger could return the number of autocmds triggered
|
// TODO: perhaps trigger could return the number of autocmds triggered
|
||||||
|
// TODO: Perhaps this should take -args to pass to the command?
|
||||||
if (!liberator.autocommands.get(event).some(function (c) c.pattern.test(url)))
|
if (!liberator.autocommands.get(event).some(function (c) c.pattern.test(url)))
|
||||||
liberator.echo("No matching autocommands");
|
liberator.echo("No matching autocommands");
|
||||||
else
|
else
|
||||||
liberator.autocommands.trigger(event, url);
|
liberator.autocommands.trigger(event, {url: url});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -249,7 +238,7 @@ liberator.AutoCommands = function () //{{{
|
|||||||
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
|
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
|
||||||
},
|
},
|
||||||
|
|
||||||
trigger: function (event, url)
|
trigger: function (event, args)
|
||||||
{
|
{
|
||||||
let events = liberator.options["eventignore"].split(",");
|
let events = liberator.options["eventignore"].split(",");
|
||||||
|
|
||||||
@@ -262,6 +251,7 @@ liberator.AutoCommands = function () //{{{
|
|||||||
|
|
||||||
let lastPattern = null;
|
let lastPattern = null;
|
||||||
|
|
||||||
|
let url = args.url || "";
|
||||||
for (let [,autoCmd] in Iterator(autoCmds))
|
for (let [,autoCmd] in Iterator(autoCmds))
|
||||||
{
|
{
|
||||||
if (autoCmd.pattern.test(url))
|
if (autoCmd.pattern.test(url))
|
||||||
@@ -272,7 +262,7 @@ liberator.AutoCommands = function () //{{{
|
|||||||
lastPattern = autoCmd.pattern;
|
lastPattern = autoCmd.pattern;
|
||||||
|
|
||||||
liberator.echomsg("autocommand " + autoCmd.command, 9);
|
liberator.echomsg("autocommand " + autoCmd.command, 9);
|
||||||
liberator.execute(autoCmd.command);
|
liberator.execute(liberator.commands.replaceTokens(autoCmd.command, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -475,10 +465,22 @@ liberator.Events = function () //{{{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function triggerLoadAutocmd(name, doc)
|
||||||
|
{
|
||||||
|
let args = {
|
||||||
|
url: doc.location.href,
|
||||||
|
title: doc.title
|
||||||
|
}
|
||||||
|
if (liberator.has("tabs"))
|
||||||
|
args.tab = liberator.tabs.getContentIndex(doc) + 1;
|
||||||
|
|
||||||
|
liberator.autocommands.trigger(name, args);
|
||||||
|
}
|
||||||
|
|
||||||
function onDOMContentLoaded(event)
|
function onDOMContentLoaded(event)
|
||||||
{
|
{
|
||||||
if (event.originalTarget instanceof HTMLDocument)
|
if (event.originalTarget instanceof HTMLDocument)
|
||||||
liberator.autocommands.trigger("DOMLoad", event.originalTarget.location.href);
|
triggerLoadAutocmd("DOMLoad", event.originalTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: see what can be moved to onDOMContentLoaded()
|
// TODO: see what can be moved to onDOMContentLoaded()
|
||||||
@@ -486,7 +488,7 @@ liberator.Events = function () //{{{
|
|||||||
{
|
{
|
||||||
if (event.originalTarget instanceof HTMLDocument)
|
if (event.originalTarget instanceof HTMLDocument)
|
||||||
{
|
{
|
||||||
var doc = event.originalTarget;
|
let doc = event.originalTarget;
|
||||||
// document is part of a frameset
|
// document is part of a frameset
|
||||||
if (doc.defaultView.frameElement)
|
if (doc.defaultView.frameElement)
|
||||||
{
|
{
|
||||||
@@ -499,8 +501,8 @@ liberator.Events = function () //{{{
|
|||||||
|
|
||||||
// code which should happen for all (also background) newly loaded tabs goes here:
|
// code which should happen for all (also background) newly loaded tabs goes here:
|
||||||
|
|
||||||
var url = doc.location.href;
|
let url = doc.location.href;
|
||||||
var title = doc.title;
|
let title = doc.title;
|
||||||
|
|
||||||
// update history
|
// update history
|
||||||
if (url && liberator.history)
|
if (url && liberator.history)
|
||||||
@@ -530,7 +532,7 @@ liberator.Events = function () //{{{
|
|||||||
liberator.echomsg("Background tab loaded: " + title || url, 1);
|
liberator.echomsg("Background tab loaded: " + title || url, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
liberator.autocommands.trigger("PageLoad", url);
|
triggerLoadAutocmd("PageLoad", doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1474,7 +1476,7 @@ liberator.Events = function () //{{{
|
|||||||
liberator.buffer.loaded = 0;
|
liberator.buffer.loaded = 0;
|
||||||
liberator.statusline.updateProgress(0);
|
liberator.statusline.updateProgress(0);
|
||||||
|
|
||||||
liberator.autocommands.trigger("PageLoadPre", liberator.buffer.URL);
|
liberator.autocommands.trigger("PageLoadPre", {url: liberator.buffer.URL});
|
||||||
|
|
||||||
// don't reset mode if a frame of the frameset gets reloaded which
|
// don't reset mode if a frame of the frameset gets reloaded which
|
||||||
// is not the focused frame
|
// is not the focused frame
|
||||||
@@ -1516,7 +1518,7 @@ liberator.Events = function () //{{{
|
|||||||
liberator.statusline.updateUrl();
|
liberator.statusline.updateUrl();
|
||||||
liberator.statusline.updateProgress();
|
liberator.statusline.updateProgress();
|
||||||
|
|
||||||
liberator.autocommands.trigger("LocationChange", liberator.buffer.URL);
|
liberator.autocommands.trigger("LocationChange", {url: liberator.buffer.URL});
|
||||||
|
|
||||||
// if this is not delayed we get the position of the old buffer
|
// if this is not delayed we get the position of the old buffer
|
||||||
setTimeout(function () { liberator.statusline.updateBufferPosition(); }, 100);
|
setTimeout(function () { liberator.statusline.updateBufferPosition(); }, 100);
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ liberator.IO = function () //{{{
|
|||||||
|
|
||||||
liberator.echo(command + liberator.util.escapeHTML(output));
|
liberator.echo(command + liberator.util.escapeHTML(output));
|
||||||
|
|
||||||
liberator.autocommands.trigger("ShellCmdPost", "");
|
liberator.autocommands.trigger("ShellCmdPost", {});
|
||||||
},
|
},
|
||||||
{ bang: true });
|
{ bang: true });
|
||||||
|
|
||||||
|
|||||||
@@ -1155,7 +1155,7 @@ const liberator = (function () //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
liberator.triggerObserver("enter", null);
|
liberator.triggerObserver("enter", null);
|
||||||
liberator.autocommands.trigger(liberator.config.name + "Enter", "");
|
liberator.autocommands.trigger(liberator.config.name + "Enter", {});
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
liberator.statusline.update();
|
liberator.statusline.update();
|
||||||
@@ -1165,7 +1165,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
shutdown: function ()
|
shutdown: function ()
|
||||||
{
|
{
|
||||||
liberator.autocommands.trigger(liberator.config.name + "LeavePre", "");
|
liberator.autocommands.trigger(liberator.config.name + "LeavePre", {});
|
||||||
|
|
||||||
liberator.storage.saveAll();
|
liberator.storage.saveAll();
|
||||||
|
|
||||||
@@ -1173,7 +1173,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
liberator.dump("All liberator modules destroyed\n");
|
liberator.dump("All liberator modules destroyed\n");
|
||||||
|
|
||||||
liberator.autocommands.trigger(liberator.config.name + "Leave", "");
|
liberator.autocommands.trigger(liberator.config.name + "Leave", {});
|
||||||
},
|
},
|
||||||
|
|
||||||
sleep: function (ms)
|
sleep: function (ms)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ liberator.Mail = function () //{{{
|
|||||||
if (folder)
|
if (folder)
|
||||||
{
|
{
|
||||||
var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
|
var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
|
||||||
liberator.autocommands.trigger("FolderLoaded", msgFolder);
|
liberator.autocommands.trigger("FolderLoaded", {url: msgFolder});
|
||||||
|
|
||||||
// Jump to a message when requested
|
// Jump to a message when requested
|
||||||
var indices = [];
|
var indices = [];
|
||||||
|
|||||||
@@ -634,6 +634,13 @@ liberator.Tabs = function () //{{{
|
|||||||
|
|
||||||
get alternate() alternates[1],
|
get alternate() alternates[1],
|
||||||
|
|
||||||
|
get browsers() function ()
|
||||||
|
{
|
||||||
|
let browsers = getBrowser.browsers;
|
||||||
|
for (let i = 0; i < browsers.length; i++)
|
||||||
|
yield [i, browsers[i]];
|
||||||
|
},
|
||||||
|
|
||||||
get count() getBrowser().mTabs.length,
|
get count() getBrowser().mTabs.length,
|
||||||
|
|
||||||
// used for :setlocal
|
// used for :setlocal
|
||||||
@@ -676,17 +683,27 @@ liberator.Tabs = function () //{{{
|
|||||||
get: function (filter)
|
get: function (filter)
|
||||||
{
|
{
|
||||||
var buffers = [];
|
var buffers = [];
|
||||||
var browsers = getBrowser().browsers;
|
for (let [i, browser] in this.browsers)
|
||||||
for (let i = 0; i < browsers.length; i++)
|
|
||||||
{
|
{
|
||||||
var title = browsers[i].contentTitle || "(Untitled)";
|
var title = browser.contentTitle || "(Untitled)";
|
||||||
var uri = browsers[i].currentURI.spec;
|
var uri = browser.currentURI.spec;
|
||||||
var number = i + 1;
|
var number = i + 1;
|
||||||
buffers.push([number, title, uri]);
|
buffers.push([number, title, uri]);
|
||||||
}
|
}
|
||||||
return buffers;
|
return buffers;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getContentIndex: function (content)
|
||||||
|
{
|
||||||
|
for (let [i, browser] in this.browsers)
|
||||||
|
{
|
||||||
|
if (browser.contentWindow == content)
|
||||||
|
return i;
|
||||||
|
if (browser.contentDocument == content)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getTab: function (index)
|
getTab: function (index)
|
||||||
{
|
{
|
||||||
if (index)
|
if (index)
|
||||||
|
|||||||
Reference in New Issue
Block a user