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

company-active-map not fully working when company-quickhelp-mode is active #17

Closed
Alexander-Miller opened this issue Jun 20, 2015 · 4 comments

Comments

@Alexander-Miller
Copy link

I have a few custom keybinds I use for company mode:

(define-key company-active-map (kbd "C-j") 'company-select-next)
(define-key company-active-map (kbd "C-k") 'company-select-previous)
(define-key company-active-map (kbd "C-ü") 'helm-company)
(define-key company-active-map (kbd "<tab>") 'company-complete-common-or-cycle)

If I activate company-quickhelp-mode the first two keybindings will no longer work and
instead execute their globally bound (evil-mode) actions instead. The latter two keybinds
continue working as inteded. I also tried using C-w, C-s and J, K as well.

The former was equally broken while the latter was working properly.

This issue only appeas if company-quickhelp-mode is active and the popup was visible. I'm able to use C-j and C-k to cycle though the completion candidates if no popup has yet appeared.

I'm using company version 0.9.0-cvs and the newest company-quickhelp installed from github via el-get.

@expez
Copy link
Collaborator

expez commented Jun 20, 2015

There's nothing I can do about this.

Evil is quite aggressive in making sure it's keybindings have top priority. I suggest you move your keybindings into one of evil's own keymaps where they won't get shadowed. If that's not possible, or if you don't want to solve your problem that way, I suggest you open a ticket in the evil repo to figure out why evil-mode is shadowing the keybindings in this situation.

@Alexander-Miller
Copy link
Author

For now I'll go with rebinding then. You can get around the issue if you make the proper keybinds and put them into company-completion-started/finished/cancelled-hook.

@ashiklom
Copy link

Expanding on the previous solution (since I never found an answer that laid it out explicitly), I used code like the following to make this work:

(add-hook 'company-completion-started-hook 'ans/set-company-maps)
(add-hook 'company-completion-finished-hook 'ans/unset-company-maps)
(add-hook 'company-completion-cancelled-hook 'ans/unset-company-maps)

(defun ans/unset-company-maps (&rest unused)
  "Set default mappings (outside of company).
Arguments (UNUSED) are ignored."
  (general-def
    :states 'insert
    :keymaps 'override
    "C-n" nil
    "C-p" nil
    "C-l" nil))

(defun ans/set-company-maps (&rest unused)
  "Set maps for when you're inside company completion.
Arguments (UNUSED) are ignored."
  (general-def
    :states 'insert
    :keymaps 'override
    "C-n" 'company-select-next
    "C-p" 'company-select-previous
    "C-l" 'ans-company-complete-continue))

This uses general.el for key definitions, but any key definition command should work.

To me, this issue seems similar to #63.

@mohkale
Copy link

mohkale commented Aug 31, 2019

building on ashiklom's solution, here's a block of code which'll let you specify the bindings only once.

(let* ((bindings '("C-j" company-select-next
                     "C-k" company-select-previous))
         (unset-bindings (mapcar (lambda (value)
                                   (if (stringp value)
                                       value
                                     nil))
                                 bindings)))
    (defun custom/unset-company-bindings (&rest args)
      (apply 'general-define-key
             :keymaps 'override
             :states  'insert
             unset-bindings))

    (defun custom/set-company-bindings (&rest args)
      (apply 'general-define-key
             :keymaps 'override
             :states  'insert
             bindings)))

(add-hook 'company-completion-started-hook 'custom/set-company-bindings)
(add-hook 'company-completion-finished-hook 'custom/unset-company-bindings)
(add-hook 'company-completion-cancelled-hook 'custom/unset-company-bindings)

duianto added a commit to duianto/spacemacs that referenced this issue Oct 18, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
duianto added a commit to duianto/spacemacs that referenced this issue Oct 18, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
smile13241324 pushed a commit to syl20bnr/spacemacs that referenced this issue Oct 19, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
thanhvg pushed a commit to thanhvg/spacemacs that referenced this issue Nov 4, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
sei40kr pushed a commit to sei40kr/spacemacs that referenced this issue Nov 11, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
fzuellich pushed a commit to fzuellich/spacemacs that referenced this issue Nov 18, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
tgroshon pushed a commit to tgroshon/spacemacs that referenced this issue Nov 22, 2019
Got the idea for the fix from this comment:
company-mode/company-quickhelp#17 (comment)

I simplified it to only un/define C-k, since C-j worked without the fix.
russmatney added a commit to russmatney/dotfiles that referenced this issue Mar 29, 2020
Slightly cleaner impl from a closer-to the source issue:
company-mode/company-quickhelp#17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants