From 138ce60c1d532eaf406d92ae334066a47641c887 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sat, 23 Sep 2017 18:26:53 +1000 Subject: [PATCH 1/3] Add count support to buffer command --- doc/help/commands.asciidoc | 5 ++++- qutebrowser/browser/commands.py | 39 ++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 6e1ffd647..7ca7fe822 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -188,11 +188,14 @@ Syntax: +:buffer 'index'+ 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 * +'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 diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 11efccc11..1c03a39f8 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1011,29 +1011,38 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', scope='window') @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. - Focuses window if necessary. + Focuses window if necessary when index is given. If both index and count + are given, use count. Args: 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. """ - index_parts = index.split('/', 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) - try: - for part in index_parts: - int(part) - except ValueError: - model = miscmodels.buffer() - model.set_pattern(index) - if model.count() > 0: - index = model.data(model.first_item()) - index_parts = index.split('/', 1) - else: - raise cmdexc.CommandError( - "No matching tab for: {}".format(index)) + try: + for part in index_parts: + int(part) + except ValueError: + model = miscmodels.buffer() + model.set_pattern(index) + if model.count() > 0: + index = model.data(model.first_item()) + index_parts = index.split('/', 1) + else: + raise cmdexc.CommandError( + "No matching tab for: {}".format(index)) if len(index_parts) == 2: win_id = int(index_parts[0]) From 8ae0bd2797e8f40ed34d18846c471c37c4dacddf Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Mon, 2 Oct 2017 23:43:49 +1100 Subject: [PATCH 2/3] Update :buffer tests for count support --- tests/end2end/features/tabs.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index bcf7f15f0..02954dbcf 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -897,9 +897,9 @@ Feature: Tab management # :buffer - Scenario: :buffer without args + Scenario: :buffer without args or count When I run :buffer - Then the error "buffer: The following arguments are required: index" should be shown + Then the error "buffer: Either a count or the argument index must be specified." should be shown Scenario: :buffer with a matching title When I open data/title.html From 58bef6ba970eba7ce32c8089932bb8ec7d6374f2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 3 Oct 2017 10:13:16 +0200 Subject: [PATCH 3/3] Regenerate docs --- doc/help/commands.asciidoc | 4 ++-- qutebrowser/browser/commands.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 7ca7fe822..6e8610b8b 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -184,7 +184,7 @@ Load a bookmark. [[buffer]] === buffer -Syntax: +:buffer 'index'+ +Syntax: +:buffer ['index']+ Select tab by index or url/title best match. @@ -193,10 +193,10 @@ Focuses window if necessary when index is given. If both index and count are giv ==== positional arguments * +'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 the current window. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 1c03a39f8..24e7935fb 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1015,8 +1015,8 @@ class CommandDispatcher: def buffer(self, index=None, count=None): """Select tab by index or url/title best match. - Focuses window if necessary when index is given. If both index and count - are given, use count. + Focuses window if necessary when index is given. If both index and + count are given, use count. Args: index: The [win_id/]index of the tab to focus. Or a substring