help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : Re: Bind two commands to one key to toggle between them


From: Hongyi Zhao
Subject: Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
Date: Sat, 23 Oct 2021 09:45:15 +0800

On Sat, Oct 23, 2021 at 1:38 AM Drew Adams <drew.adams@oracle.com> wrote:
>
> > I tried with the following use-package binding configuration, but
> > it doesn't work:
> >
> >     ("<tab>" . (lamda () (if (company-search-mode) #'company-search-
> > abort
> >                     #'company-search-candidates)))
>
> To start with (I see you corrected these things
> later, but just in case the reminder helps someone):
>
> 1. lambda vs lamda
>
> 2. Your anonymous function isn't a command.
>    It needs `interactive'.

Thank you for your correction. I've tried the following but still
can't get the same effect as using two different keys:

(use-package company
 :bind
 (:map company-active-map
    ;; ("<tab>" . company-search-candidates)
    ;; ("<f1>" . company-search-abort)

    ("<tab>" . (lambda ()
             (interactive)
             (if (company--active-p) #'company-search-abort
               #'company-search-candidates)))

    :map company-search-map
    ;; ("<tab>" . company-search-candidates)
    ;; ("<f1>" . company-search-abort)

    ("<tab>" . (lambda ()
             (interactive)
             (if (company-search-mode) #'company-search-abort
               #'company-search-candidates)))))

Dmitry Gutov told me the following fact [1]:

company-search-candidates is incremental (like isearch), so it's not
going to exit when you call it a second time.

You can write your own command easily enough, though.


But I still can’t find an effective solution that uses only one key to
get exactly the same behavior given by two separate keys.


[1] 
https://github.com/company-mode/company-mode/discussions/1244#discussioncomment-1521667

HZ
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



reply via email to

[Prev in Thread] Current Thread [Next in Thread]