Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't bind Alt-Less #3736

Open
The-Compiler opened this issue Mar 18, 2018 · 6 comments · May be fixed by #4578
Open

Can't bind Alt-Less #3736

The-Compiler opened this issue Mar 18, 2018 · 6 comments · May be fixed by #4578
Labels
bug: behavior Something doesn't work as intended, but doesn't crash. component: config Issues related to configuration. component: keyinput Issues related to processing keypresses. priority: 1 - middle Issues which should be done at some point, but aren't that important.

Comments

@The-Compiler
Copy link
Member

On v1.2.1, :bind <Alt+Less> scroll-to-perc 0 leads to:

22:49:25 DEBUG    commands   command:run:486 command called: bind ['<Alt+Less>', 'scroll-to-perc 0']
22:49:25 DEBUG    commands   command:run:501 Calling qutebrowser.config.configcommands.ConfigCommands.bind(<qutebrowser.config.configcommands.ConfigCommands object at 0x7fe66ed1b828>, 0, '<Alt+Less>', 'scroll-to-perc 0', mode='normal', default=False)
22:49:25 DEBUG    config     config:update_mutables:448 bindings.commands was mutated, updating
22:49:25 DEBUG    message    message:_log_stack:46 Stack for error (from exception) message:
Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configtypes.py", line 1663, in to_py
    return keyutils.KeySequence.parse(value)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/keyutils.py", line 557, in parse
    new._validate(keystr)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/keyutils.py", line 432, in _validate
    raise KeyParseError(keystr, "Got invalid key!")
qutebrowser.keyinput.keyutils.KeyParseError: Could not parse '<Alt+<>': Got invalid key!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configcommands.py", line 47, in _handle_config_error
    yield
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configcommands.py", line 175, in bind
    self._keyconfig.bind(seq, command, mode=mode, save_yaml=True)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/config.py", line 195, in bind
    self._config.update_mutables(save_yaml=save_yaml)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/config.py", line 449, in update_mutables
    self.set_obj(name, new_value, save_yaml=save_yaml)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/config.py", line 393, in set_obj
    self._set_value(opt, value, pattern=pattern)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/config.py", line 281, in _set_value
    opt.typ.to_py(value)  # for validation
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configtypes.py", line 1226, in to_py
    for key, val in value.items()}
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configtypes.py", line 1226, in <dictcomp>
    for key, val in value.items()}
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configtypes.py", line 1226, in to_py
    for key, val in value.items()}
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configtypes.py", line 1226, in <dictcomp>
    for key, val in value.items()}
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configtypes.py", line 1665, in to_py
    raise configexc.ValidationError(value, str(e))
qutebrowser.config.configexc.ValidationError: Invalid value '<Alt+<>' - Could not parse '<Alt+<>': Got invalid key!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/runners.py", line 325, in run_safely
    self.run(text, count)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/runners.py", line 304, in run
    result.cmd.run(self._win_id, args, count=count)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/command.py", line 502, in run
    self.handler(*posargs, **kwargs)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configcommands.py", line 175, in bind
    self._keyconfig.bind(seq, command, mode=mode, save_yaml=True)
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/config/configcommands.py", line 49, in _handle_config_error
    raise cmdexc.CommandError(str(e))
qutebrowser.commands.cmdexc.CommandError: Invalid value '<Alt+<>' - Could not parse '<Alt+<>': Got invalid key!
22:49:25 ERROR    message    message:error:63 Invalid value '<Alt+<>' - Could not parse '<Alt+<>': Got invalid key!
@The-Compiler The-Compiler added component: keyinput Issues related to processing keypresses. component: config Issues related to configuration. priority: 1 - middle Issues which should be done at some point, but aren't that important. bug: behavior Something doesn't work as intended, but doesn't crash. labels Mar 18, 2018
@The-Compiler The-Compiler added this to the v1.2.2 milestone Mar 18, 2018
@The-Compiler
Copy link
Member Author

I think this is happening because of the normalization added in 9941812 for #3699 - it gets normalized to <Alt+<> which then can't be bound. Probably suffices if _key_to_string handles Qt.Key_Greater and Qt.Key_Less.

@The-Compiler The-Compiler removed this from the v1.3.1 milestone May 29, 2018
@rganardi
Copy link

rganardi commented Feb 3, 2019

Hi, can I work on this?

It looks to me like the normalization happens in keyinput.keyutils._parse_special_key.

I've tried patching _key_to_string to handle Qt.Key_Greater and Qt.Key_Less, but all I'm getting is some assertion error

Traceback (most recent call last):
  File "/home/rganardi/git/qutebrowser/qutebrowser/config/configfiles.py", line 598, in read_config_py
    exec(code, module.__dict__)
  File "/home/rganardi/.config/qutebrowser/config.py", line 134, in <module>
    config.bind('<Alt+Less>', 'scroll-to-perc 0')
  File "/home/rganardi/git/qutebrowser/qutebrowser/config/configfiles.py", line 416, in bind
    self._keyconfig.bind(seq, command, mode=mode)
  File "/home/rganardi/git/qutebrowser/qutebrowser/config/config.py", line 212, in bind
    "Adding binding {} -> {} in mode {}.".format(key, command, mode))
  File "/home/rganardi/git/qutebrowser/qutebrowser/keyinput/keyutils.py", line 409, in __str__
    parts.append(str(info))
  File "/home/rganardi/git/qutebrowser/qutebrowser/keyinput/keyutils.py", line 331, in __str__
    assert len(key_string) == 1, key_string
AssertionError: Less

Do you have any pointers on how to proceed?
What's the intended output of _parse_keystring?

@toofar
Copy link
Member

toofar commented Feb 4, 2019

I'm not familiar with that part of the codebase but there is a test that has some expected output.

rganardi added a commit to rganardi/qutebrowser that referenced this issue Feb 14, 2019
rganardi added a commit to rganardi/qutebrowser that referenced this issue Feb 15, 2019
@rganardi rganardi linked a pull request Feb 15, 2019 that will close this issue
rganardi added a commit to rganardi/qutebrowser that referenced this issue Feb 27, 2019
@The-Compiler
Copy link
Member Author

From #5965:

  • <<<: still, a single < moves the tab left
  • <<><<>: crashes qutebrowser because the key sequence cannot be parsed

@The-Compiler
Copy link
Member Author

In a similar vein, <Less><Less> also gets translated to a single (rather than double) <.

@genomorro
Copy link

Hi. I just installed QB 2.0.2 with an Emacs-like config. I've tried keybindings such as:

config.bind('<Alt-<>','scroll-to-perc 0')
config.bind('<Alt->>','scroll-to-perc')

It doesn't work. I also tried:

config.bind('<Alt-Less>','scroll-to-perc 0')
config.bind('<Alt-Greater>','scroll-to-perc')

With those bindings QB just stop working:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1972, in to_py
    return keyutils.KeySequence.parse(value)
  File "/usr/lib/python3.8/site-packages/qutebrowser/keyinput/keyutils.py", line 655, in parse
    new._validate(keystr)
  File "/usr/lib/python3.8/site-packages/qutebrowser/keyinput/keyutils.py", line 537, in _validate
    raise KeyParseError(keystr, "Got invalid key!")
qutebrowser.keyinput.keyutils.KeyParseError: Could not parse '<Alt+<>': Got invalid key!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.8/qutebrowser", line 33, in <module>
    sys.exit(load_entry_point('qutebrowser==2.0.2', 'gui_scripts', 'qutebrowser')())
  File "/usr/lib/python3.8/site-packages/qutebrowser/qutebrowser.py", line 208, in main
    return app.run(args)
  File "/usr/lib/python3.8/site-packages/qutebrowser/app.py", line 92, in run
    configinit.early_init(args)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configinit.py", line 65, in early_init
    configfiles.read_config_py(config_file, warn_autoconfig=True)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configfiles.py", line 890, in read_config_py
    api.finalize()
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configfiles.py", line 641, in finalize
    self._config.update_mutables()
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 514, in update_mutables
    self.set_obj(name, new_value, save_yaml=save_yaml)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 452, in set_obj
    self._set_value(opt, value, pattern=pattern,
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 312, in _set_value
    opt.typ.to_py(value)  # for validation
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in to_py
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in <dictcomp>
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in toTraceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1972, in to_py
    return keyutils.KeySequence.parse(value)
  File "/usr/lib/python3.8/site-packages/qutebrowser/keyinput/keyutils.py", line 655, in parse
    new._validate(keystr)
  File "/usr/lib/python3.8/site-packages/qutebrowser/keyinput/keyutils.py", line 537, in _validate
    raise KeyParseError(keystr, "Got invalid key!")
qutebrowser.keyinput.keyutils.KeyParseError: Could not parse '<Alt+<>': Got invalid key!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.8/qutebrowser", line 33, in <module>
    sys.exit(load_entry_point('qutebrowser==2.0.2', 'gui_scripts', 'qutebrowser')())
  File "/usr/lib/python3.8/site-packages/qutebrowser/qutebrowser.py", line 208, in main
    return app.run(args)
  File "/usr/lib/python3.8/site-packages/qutebrowser/app.py", line 92, in run
    configinit.early_init(args)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configinit.py", line 65, in early_init
    configfiles.read_config_py(config_file, warn_autoconfig=True)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configfiles.py", line 890, in read_config_py
    api.finalize()
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configfiles.py", line 641, in finalize
    self._config.update_mutables()
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 514, in update_mutables
    self.set_obj(name, new_value, save_yaml=save_yaml)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 452, in set_obj
    self._set_value(opt, value, pattern=pattern,
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 312, in _set_value
    opt.typ.to_py(value)  # for validation
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in to_py
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in <dictcomp>
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in to_py
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in <dictcomp>
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1974, in to_py
    raise configexc.ValidationError(value, str(e))
qutebrowser.config.configexc.ValidationError: Invalid value '<Alt+<>' - Could not parse '<Alt+<>': Got invalid key!
_py
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1446, in <dictcomp>
    d = {self.keytype.to_py(key): self.valtype.to_py(val)
  File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1974, in to_py
    raise configexc.ValidationError(value, str(e))
qutebrowser.config.configexc.ValidationError: Invalid value '<Alt+<>' - Could not parse '<Alt+<>': Got invalid key!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: behavior Something doesn't work as intended, but doesn't crash. component: config Issues related to configuration. component: keyinput Issues related to processing keypresses. priority: 1 - middle Issues which should be done at some point, but aren't that important.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants