mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 16:47:58 +01:00
Add :pin and :unpin. Closes issue #344.
This commit is contained in:
@@ -1470,7 +1470,7 @@ var Buffer = Module("buffer", {
|
|||||||
command: function () "tabs.select"
|
command: function () "tabs.select"
|
||||||
};
|
};
|
||||||
context.compare = CompletionContext.Sort.number;
|
context.compare = CompletionContext.Sort.number;
|
||||||
context.filters = [CompletionContext.Filter.textDescription];
|
context.filters[0] = CompletionContext.Filter.textDescription;
|
||||||
|
|
||||||
for (let [id, vals] in Iterator(tabGroups))
|
for (let [id, vals] in Iterator(tabGroups))
|
||||||
context.fork(id, 0, this, function (context, [name, browsers]) {
|
context.fork(id, 0, this, function (context, [name, browsers]) {
|
||||||
|
|||||||
@@ -960,7 +960,13 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
if (obj instanceof Command) {
|
if (obj instanceof Command) {
|
||||||
link = function (cmd) <ex>{cmd}</ex>;
|
link = function (cmd) <ex>{cmd}</ex>;
|
||||||
args = obj.parseArgs("", CompletionContext(str || ""));
|
args = obj.parseArgs("", CompletionContext(str || ""));
|
||||||
spec = function (cmd) cmd + (obj.bang ? <oa>!</oa> : <></>);
|
spec = function (cmd) <>{
|
||||||
|
obj.count ? <oa>count</oa> : <></>
|
||||||
|
}{
|
||||||
|
cmd
|
||||||
|
}{
|
||||||
|
obj.bang ? <oa>!</oa> : <></>
|
||||||
|
}</>;
|
||||||
}
|
}
|
||||||
else if (obj instanceof Map) {
|
else if (obj instanceof Map) {
|
||||||
spec = function (map) obj.count ? <><oa>count</oa>{map}</> : <>{map}</>;
|
spec = function (map) obj.count ? <><oa>count</oa>{map}</> : <>{map}</>;
|
||||||
|
|||||||
@@ -527,50 +527,17 @@ var Tabs = Module("tabs", {
|
|||||||
commands.add(["bd[elete]", "bw[ipeout]", "bun[load]", "tabc[lose]"],
|
commands.add(["bd[elete]", "bw[ipeout]", "bun[load]", "tabc[lose]"],
|
||||||
"Delete current buffer",
|
"Delete current buffer",
|
||||||
function (args) {
|
function (args) {
|
||||||
let special = args.bang;
|
let removed = 0;
|
||||||
let count = args.count;
|
for (let tab in matchTabs(args, args.bang)) {
|
||||||
let arg = args[0] || "";
|
config.removeTab(tab);
|
||||||
|
removed++;
|
||||||
if (arg) {
|
}
|
||||||
let removed = 0;
|
|
||||||
let matches = arg.match(/^(\d+):?/);
|
|
||||||
|
|
||||||
if (matches) {
|
|
||||||
config.removeTab(tabs.getTab(parseInt(matches[1], 10) - 1));
|
|
||||||
removed = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let str = arg.toLowerCase();
|
|
||||||
let browsers = config.tabbrowser.browsers;
|
|
||||||
|
|
||||||
for (let i = browsers.length - 1; i >= 0; i--) {
|
|
||||||
let host, title, uri = browsers[i].currentURI.spec;
|
|
||||||
if (browsers[i].currentURI.schemeIs("about")) {
|
|
||||||
host = "";
|
|
||||||
title = "(Untitled)";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
host = browsers[i].currentURI.host;
|
|
||||||
title = browsers[i].contentTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
[host, title, uri] = [host, title, uri].map(String.toLowerCase);
|
|
||||||
|
|
||||||
if (host.indexOf(str) >= 0 || uri == str ||
|
|
||||||
(special && (title.indexOf(str) >= 0 || uri.indexOf(str) >= 0))) {
|
|
||||||
config.removeTab(tabs.getTab(i));
|
|
||||||
removed++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (args[0])
|
||||||
if (removed > 0)
|
if (removed > 0)
|
||||||
dactyl.echomsg(_("buffer.fewer", removed, removed == 1 ? "" : "s"), 9);
|
dactyl.echomsg(_("buffer.fewerTab" + (removed == 1 ? "" : "s"), removed), 9);
|
||||||
else
|
else
|
||||||
dactyl.echoerr(_("buffer.noMatching", arg));
|
dactyl.echoerr(_("buffer.noMatching", arg));
|
||||||
}
|
|
||||||
else // just remove the current tab
|
|
||||||
tabs.remove(tabs.getTab(), Math.max(count, 1), special);
|
|
||||||
}, {
|
}, {
|
||||||
argCount: "?",
|
argCount: "?",
|
||||||
bang: true,
|
bang: true,
|
||||||
@@ -580,6 +547,76 @@ var Tabs = Module("tabs", {
|
|||||||
privateData: true
|
privateData: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function matchTabs(args, substr) {
|
||||||
|
let filter = args[0];
|
||||||
|
|
||||||
|
if (!filter && args.count == null)
|
||||||
|
yield tabs.getTab();
|
||||||
|
else if (!filter)
|
||||||
|
yield dactyl.assert(tabs.getTab(args.count - 1));
|
||||||
|
else {
|
||||||
|
let matches = /^(\d+):?/.exec(filter);
|
||||||
|
if (matches)
|
||||||
|
yield dactyl.assert(args.count == null &&
|
||||||
|
tabs.getTab(parseInt(matches[1], 10) - 1));
|
||||||
|
else {
|
||||||
|
let str = filter.toLowerCase();
|
||||||
|
for (let tab in values(tabs.allTabs)) {
|
||||||
|
let host, title;
|
||||||
|
let browser = tab.linkedBrowser;
|
||||||
|
let uri = browser.currentURI.spec;
|
||||||
|
if (browser.currentURI.schemeIs("about")) {
|
||||||
|
host = "";
|
||||||
|
title = "(Untitled)";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
host = browser.currentURI.host;
|
||||||
|
title = browser.contentTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
[host, title, uri] = [host, title, uri].map(String.toLowerCase);
|
||||||
|
|
||||||
|
if (host.indexOf(str) >= 0 || uri == str ||
|
||||||
|
(substr && (title.indexOf(str) >= 0 || uri.indexOf(str) >= 0)))
|
||||||
|
if (args.count == null || --args.count == 0)
|
||||||
|
yield tab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.add(["pin[tab]"],
|
||||||
|
"Pin tab as an application tab",
|
||||||
|
function (args) {
|
||||||
|
for (let tab in matchTabs(args, true))
|
||||||
|
config.browser[!args.bang || !tab.pinned ? "pinTab" : "unpinTab"](tab);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
argCount: "?",
|
||||||
|
bang: true,
|
||||||
|
count: true,
|
||||||
|
completer: function (context, args) {
|
||||||
|
if (!args.bang)
|
||||||
|
context.filters.push(function ({ item }) !item.tab.pinned);
|
||||||
|
completion.buffer(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.add(["unpin[tab]"],
|
||||||
|
"Unpin tab as an application tab",
|
||||||
|
function (args) {
|
||||||
|
for (let tab in matchTabs(args, true))
|
||||||
|
config.browser.unpinTab(tab);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
argCount: "?",
|
||||||
|
count: true,
|
||||||
|
completer: function (context, args) {
|
||||||
|
context.filters.push(function ({ item }) item.tab.pinned);
|
||||||
|
completion.buffer(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
commands.add(["keepa[lt]"],
|
commands.add(["keepa[lt]"],
|
||||||
"Execute a command without changing the current alternate buffer",
|
"Execute a command without changing the current alternate buffer",
|
||||||
function (args) {
|
function (args) {
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ bookmark.removed-1 = Removed bookmark: %S
|
|||||||
bookmark.added-1 = Added bookmark: %S
|
bookmark.added-1 = Added bookmark: %S
|
||||||
bookmark.deleted-1 = %S bookmark(s) deleted
|
bookmark.deleted-1 = %S bookmark(s) deleted
|
||||||
|
|
||||||
buffer.fewer-2 = %S fewer tab%S
|
buffer.fewerTab-1 = %S fewer tab
|
||||||
|
buffer.fewerTabs-1 = %S fewer tabs
|
||||||
buffer.cantDetatchLast = Can't detach the last tab
|
buffer.cantDetatchLast = Can't detach the last tab
|
||||||
buffer.noMatching-1 = No matching buffer for %S
|
buffer.noMatching-1 = No matching buffer for %S
|
||||||
buffer.multipleMatching-1 = More than one match for %S
|
buffer.multipleMatching-1 = More than one match for %S
|
||||||
|
|||||||
@@ -381,6 +381,32 @@
|
|||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<h2 tag="app-tabs application-tabs pinned-tabs">Application Tabs</h2>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>pin pintab</tags>
|
||||||
|
<spec><oa>count</oa>pin<oa>tab</oa><oa>!</oa> <oa>arg</oa></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Pin tab as an application tab. If <oa>!</oa> is given,
|
||||||
|
the tab's pinned state is toggled. Arguments and count
|
||||||
|
are the same as for <ex>:bdelete</ex> and <ex>:buffer</ex>.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>unpin unpintab</tags>
|
||||||
|
<spec><oa>count</oa>pin<oa>tab</oa> <oa>arg</oa></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Unpin tab as an application tab. Arguments and count
|
||||||
|
are the same as for <ex>:pintab</ex>.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
|
||||||
</document>
|
</document>
|
||||||
|
|
||||||
<!-- vim:se sts=4 sw=4 et: -->
|
<!-- vim:se sts=4 sw=4 et: -->
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
|||||||
* Adds a new command to the builtin hive. Accessible only to core
|
* Adds a new command to the builtin hive. Accessible only to core
|
||||||
* dactyl code. Plugins should use group.commands.add instead.
|
* dactyl code. Plugins should use group.commands.add instead.
|
||||||
*
|
*
|
||||||
* @param {string[]} names The names by which this command can be
|
* @param {string[]} specs The names by which this command can be
|
||||||
* invoked. The first name specified is the command's canonical
|
* invoked. The first name specified is the command's canonical
|
||||||
* name.
|
* name.
|
||||||
* @param {string} description A description of the command.
|
* @param {string} description A description of the command.
|
||||||
@@ -455,7 +455,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
|||||||
* @param {Object} extra An optional extra configuration hash.
|
* @param {Object} extra An optional extra configuration hash.
|
||||||
* @optional
|
* @optional
|
||||||
*/
|
*/
|
||||||
add: function add(names, description, action, extra, replace) {
|
add: function add(specs, description, action, extra, replace) {
|
||||||
const { commands, contexts } = this.modules;
|
const { commands, contexts } = this.modules;
|
||||||
|
|
||||||
extra = extra || {};
|
extra = extra || {};
|
||||||
@@ -463,7 +463,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
|||||||
extra.definedAt = contexts.getCaller(Components.stack.caller);
|
extra.definedAt = contexts.getCaller(Components.stack.caller);
|
||||||
|
|
||||||
extra.hive = this;
|
extra.hive = this;
|
||||||
extra.parsedSpecs = Command.parseSpecs(names);
|
extra.parsedSpecs = Command.parseSpecs(specs);
|
||||||
|
|
||||||
let names = array.flatten(extra.parsedSpecs);
|
let names = array.flatten(extra.parsedSpecs);
|
||||||
let name = names[0];
|
let name = names[0];
|
||||||
@@ -483,7 +483,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
|||||||
let self = this;
|
let self = this;
|
||||||
let closure = function () self._map[name];
|
let closure = function () self._map[name];
|
||||||
|
|
||||||
memoize(this._map, name, function () commands.Command(names, description, action, extra));
|
memoize(this._map, name, function () commands.Command(specs, description, action, extra));
|
||||||
memoize(this._list, this._list.length, closure);
|
memoize(this._list, this._list.length, closure);
|
||||||
for (let alias in values(names.slice(1)))
|
for (let alias in values(names.slice(1)))
|
||||||
memoize(this._map, alias, closure);
|
memoize(this._map, alias, closure);
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
assert: function (condition, message, quiet) {
|
assert: function (condition, message, quiet) {
|
||||||
if (!condition)
|
if (!condition)
|
||||||
throw FailedAssertion(message, 1, quiet === undefined ? true : quiet);
|
throw FailedAssertion(message, 1, quiet === undefined ? true : quiet);
|
||||||
|
return condition;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -108,6 +108,7 @@
|
|||||||
- Added several new options, including -javascript, to :abbreviate and
|
- Added several new options, including -javascript, to :abbreviate and
|
||||||
:map. [b2]
|
:map. [b2]
|
||||||
- Added :mksyntax command to auto-generate Vim syntax files. [b4]
|
- Added :mksyntax command to auto-generate Vim syntax files. [b4]
|
||||||
|
- Added :pintab and :unpintab commands. [b7]
|
||||||
- :open now only opens files beginning with /, ./, ../, or ~/ [b1]
|
- :open now only opens files beginning with /, ./, ../, or ~/ [b1]
|
||||||
- :saveas now provides completions for default file names, and
|
- :saveas now provides completions for default file names, and
|
||||||
automatically chooses a filename when the save target is a
|
automatically chooses a filename when the save target is a
|
||||||
|
|||||||
Reference in New Issue
Block a user