use-package icon indicating copy to clipboard operation
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.

Open hongyi-zhao opened this issue 3 years ago • 5 comments

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 avatar Oct 22 '21 01:10 hongyi-zhao

I figured out the solution for the question 2.

hongyi-zhao avatar Oct 25 '21 14:10 hongyi-zhao

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 avatar Jan 13 '22 12:01 Hugo-Heagren

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

Hugo-Heagren avatar Jan 14 '22 15:01 Hugo-Heagren

Really. But it still hasn't been merged.

hongyi-zhao avatar Jan 14 '22 23:01 hongyi-zhao

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.

skangas avatar Nov 29 '22 21:11 skangas