[Top][All Lists]

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

Re: Bind two commands to one key to toggle between them for the same loc

From: Hongyi Zhao
Subject: Re: Bind two commands to one key to toggle between them for the same local keymap.
Date: Fri, 22 Oct 2021 15:34:11 +0800

On Fri, Oct 22, 2021 at 2:20 PM Emanuel Berg via Users list for the
GNU Emacs text editor <> wrote:
> Hongyi Zhao wrote:
> > I installed company with use-package, and want to bind the
> > "<tab>" key to the following commands when the local keymaps
> > are company-search-map or company-active-map to toggle
> > between them:
> >
> >   ("<tab>" . company-search-candidates)
> >
> > and
> >
> >   ("<tab>" . company-search-abort)
> >
> > If the company-search-candidates command is in active, then
> > run company-search-abort when hitting <tab>, and vice versa.
> If you have two (several) keymaps, set the key one by one to
> whatever you want should happen.
> If you have one (1) keymap ... set the key to a function that
> branches on some condition and does different things based
> on that.
> Post the code here ...

`C-h o company-search-mode RET' gives me the following explanation:

company-search-mode is an interactive Lisp closure in ‘company.el’.

(company-search-mode &optional ARG)

Search mode for completion candidates.
Don’t start this directly, use ‘company-search-candidates’ or

This is a minor mode.  If called interactively, toggle the
‘Company-Search mode’ mode.  If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is ‘toggle’.  Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer,
evaluate ‘company-search-mode’.

The mode’s hook is called both when the mode is enabled and when
it is disabled.

So, I tried with the following use-package binding configuration, but
it doesn't work:

    ("<tab>" . (lamda () (if (company-search-mode) #'company-search-abort

What's the problem?


reply via email to

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