use-package
use-package copied to clipboard
Bind two commands with one key to toggle between them for the same company local keymap and simplify the local-keymaps binding.
I've the following binding-within-local-keymaps configuration for company package:
(use-package company
:bind
(:map company-active-map
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort)
("SPC" . company-complete-selection)
("<return>" . company-abort)
:map company-search-map
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort)
("SPC" . company-complete-selection)
("<return>" . company-abort))
))
As far as the above configuration is concerned, I have the following questions:
- As you can see, they are simply repeat bindings for different local-keymaps. I wonder if I can merge them for simplicity.
- OTOH, with the above configuration,
<tab>
and<f1>
will call the corresponding interactive Lisp closure correctly, but I have to use two different keys. So, I want to bind these two commands to one key, say,<tab>
, to toggle between them. Any hints for achieving this aim?
See here and here for some relevant discussions.
Regards, HZ
I figured out the solution for the question 2.
I too would find a solution to your question 1 useful. I think probably the best way would be to allow :map
to take either a keymap symbol (as it does currently) or a list of such symbols (similar to the behaviour of many of the top-level keywords). Given a list, it would just apply whatever configuration to everything in the list, so that the following would be exactly equivalent:
(use-package company
:bind
(:map company-active-map
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort)
("SPC" . company-complete-selection)
("<return>" . company-abort)
:map company-search-map
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort)
("SPC" . company-complete-selection)
("<return>" . company-abort))))
(use-package company
:bind
(:map (company-active-map company-search-map)
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort)
("SPC" . company-complete-selection)
("<return>" . company-abort)))
If you think this would be good, I would be happy to have a stab at a PR?
In fact, with respect to your first question, there is already a PR which tries to solve this, right? #830
Really. But it still hasn't been merged.
2. OTOH, with the above configuration, `<tab>` and `<f1>` will call the corresponding interactive Lisp closure correctly, but I have to use two different keys. So, I want to bind these two commands to one key, say, `<tab>`, to toggle between them. Any hints for achieving this aim?
IIUC, this question is more related to company-mode
, and I think you found a solution here: https://github.com/company-mode/company-mode/discussions/1244#discussioncomment-1521875
The PR #830 was merged, but we had to revert the change while waiting for a copyright assignment. That is in the works, however. See #1090.