Add count support to buffer command

This commit is contained in:
Michael Hoang 2017-09-23 18:26:53 +10:00
parent 5af8a95c82
commit 138ce60c1d
2 changed files with 28 additions and 16 deletions

View File

@ -188,11 +188,14 @@ Syntax: +:buffer 'index'+
Select tab by index or url/title best match. Select tab by index or url/title best match.
Focuses window if necessary. Focuses window if necessary when index is given. If both index and count are given, use count.
==== positional arguments ==== positional arguments
* +'index'+: The [win_id/]index of the tab to focus. Or a substring in which case the closest match will be focused. * +'index'+: The [win_id/]index of the tab to focus. Or a substring in which case the closest match will be focused.
==== count
The tab index to focus, starting with 1.
[[close]] [[close]]
=== close === close

View File

@ -1011,15 +1011,24 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('index', completion=miscmodels.buffer) @cmdutils.argument('index', completion=miscmodels.buffer)
def buffer(self, index): @cmdutils.argument('count', count=True)
def buffer(self, index=None, count=None):
"""Select tab by index or url/title best match. """Select tab by index or url/title best match.
Focuses window if necessary. Focuses window if necessary when index is given. If both index and count
are given, use count.
Args: Args:
index: The [win_id/]index of the tab to focus. Or a substring index: The [win_id/]index of the tab to focus. Or a substring
in which case the closest match will be focused. in which case the closest match will be focused.
count: The tab index to focus, starting with 1.
""" """
if count is not None:
index_parts = [count]
elif index is None:
raise cmdexc.CommandError("buffer: Either a count or the argument "
"index must be specified.")
else:
index_parts = index.split('/', 1) index_parts = index.split('/', 1)
try: try: