set-cmd-text: Add -s/--space argument.

We need this because quotes are ignored now, so there'd be no way to set the
text to ":open -t " for example.
This commit is contained in:
Florian Bruhin 2015-04-03 17:10:14 +02:00
parent 3b3b55234b
commit 6917c3b32d
3 changed files with 18 additions and 10 deletions

View File

@ -463,13 +463,16 @@ If the option name ends with '?', the value of the option is shown instead. If t
[[set-cmd-text]]
=== set-cmd-text
Syntax: +:set-cmd-text 'text'+
Syntax: +:set-cmd-text [*--space*] 'text'+
Preset the statusbar to some text.
==== positional arguments
* +'text'+: The commandline to set.
==== optional arguments
* +*-s*+, +*--space*+: If given, a space is added to the end.
[[spawn]]
=== spawn
Syntax: +:spawn [*--userscript*] 'args' ['args' ...]+

View File

@ -1029,14 +1029,14 @@ KEY_DATA = collections.OrderedDict([
('normal', collections.OrderedDict([
('search ""', ['<Escape>']),
('set-cmd-text ":open "', ['o']),
('set-cmd-text ":open {url}"', ['go']),
('set-cmd-text ":open -t "', ['O']),
('set-cmd-text ":open -t {url}"', ['gO']),
('set-cmd-text ":open -b "', ['xo']),
('set-cmd-text ":open -b {url}"', ['xO']),
('set-cmd-text ":open -w "', ['wo']),
('set-cmd-text ":open -w {url}"', ['wO']),
('set-cmd-text -s :open', ['o']),
('set-cmd-text :open {url}', ['go']),
('set-cmd-text -s :open -t', ['O']),
('set-cmd-text :open -t {url}', ['gO']),
('set-cmd-text -s :open -b', ['xo']),
('set-cmd-text :open -b {url}', ['xO']),
('set-cmd-text -s :open -w', ['wo']),
('set-cmd-text :open -w {url}', ['wO']),
('open -t', ['ga']),
('tab-close', ['d', '<Ctrl-W>']),
('tab-close -o', ['D']),
@ -1189,4 +1189,6 @@ CHANGED_KEY_COMMANDS = [
(re.compile(r'^cancel-download$'), r'download-cancel'),
(re.compile(r'^search ""$'), r'search'),
(re.compile(r"^search ''$"), r'search'),
(re.compile(r"""^set-cmd-text ['"](.*) ['"]$"""), r'set-cmd-text -s \1'),
(re.compile(r"""^set-cmd-text ['"](.*)['"]$"""), r'set-cmd-text \1'),
]

View File

@ -98,7 +98,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
@cmdutils.register(instance='status-command', name='set-cmd-text',
scope='window', maxsplit=0)
def set_cmd_text_command(self, text):
def set_cmd_text_command(self, text, space=False):
"""Preset the statusbar to some text.
//
@ -108,6 +108,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
Args:
text: The commandline to set.
space: If given, a space is added to the end.
"""
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=self._win_id)
@ -127,6 +128,8 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
# I'm not sure what's the best thing to do here
# https://github.com/The-Compiler/qutebrowser/issues/123
text = text.replace('{url}', url)
if space:
text += ' '
if not text or text[0] not in modeparsers.STARTCHARS:
raise cmdexc.CommandError(
"Invalid command text '{}'.".format(text))