jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.39k stars 259 forks source link

Bind two commands with one key to toggle between them for the same company local keymap and simplify the local-keymaps binding. #959

Open hongyi-zhao opened 2 years ago

hongyi-zhao commented 2 years ago

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:

  1. As you can see, they are simply repeat bindings for different local-keymaps. I wonder if I can merge them for simplicity.
  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?

See here and here for some relevant discussions.

Regards, HZ

hongyi-zhao commented 2 years ago

I figured out the solution for the question 2.

Hugo-Heagren commented 2 years ago

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?
Hugo-Heagren commented 2 years ago

In fact, with respect to your first question, there is already a PR which tries to solve this, right? #830

hongyi-zhao commented 2 years ago

Really. But it still hasn't been merged.

skangas commented 1 year ago
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.