unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: Drew Adams <drew.adams@oracle.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>,
	Emanuel Berg <moasenwood@zoho.eu>
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	[thread overview]
Message-ID: <CAGP6POKzB8tsc5F1PC=-H2TKaZOONAN15sAfbf9SPEG_-LsV7g@mail.gmail.com> (raw)
In-Reply-To: <SJ0PR10MB54884AF1235A3E53AFC59CC1F3809@SJ0PR10MB5488.namprd10.prod.outlook.com>

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	other threads:[~2021-10-23  1:45 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  5:42 Bind two commands to one key to toggle between them for the same local keymap Hongyi Zhao
2021-10-22  6:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22  7:34   ` Hongyi Zhao
2021-10-22  7:39     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22  7:57       ` Hongyi Zhao
2021-10-22  8:33         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22  9:15           ` Hongyi Zhao
2021-10-22  9:25             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22  9:46               ` Hongyi Zhao
2021-10-22  9:52                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 10:02                   ` Hongyi Zhao
2021-10-22 11:04                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 11:22                       ` Hongyi Zhao
2021-10-22 11:30                         ` Hongyi Zhao
2021-10-23 18:01                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24  0:32                           ` Hongyi Zhao
2021-10-24  1:17                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24  2:32                               ` Hongyi Zhao
2021-10-24  5:39                                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24  9:03                             ` Michael Heerdegen
2021-10-25 14:52                               ` Hongyi Zhao
2021-10-25 15:10                                 ` Michael Heerdegen
2021-10-25 17:51                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26  1:44                                     ` Hongyi Zhao
2021-10-25 17:54                                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26  1:49                                   ` Hongyi Zhao
2021-10-22  9:55                 ` Hongyi Zhao
2021-10-22  9:26             ` Hongyi Zhao
2021-10-22  9:32               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22  9:40                 ` Hongyi Zhao
2021-10-22  9:48                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 10:04                     ` Hongyi Zhao
2021-10-22 17:37     ` [External] : " Drew Adams
2021-10-23  1:45       ` Hongyi Zhao [this message]
2021-10-23  8:18         ` Michael Heerdegen
2021-10-23  8:48           ` Hongyi Zhao
2021-10-23  9:20             ` Michael Heerdegen
2021-10-23 11:58               ` Hongyi Zhao
2021-10-23 12:07                 ` Michael Heerdegen
2021-10-23 12:24                   ` Hongyi Zhao
2021-10-23 12:50                     ` Michael Heerdegen
2021-10-23 13:17                       ` Hongyi Zhao
2021-10-23 21:56                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-23  8:57         ` Kevin Vigouroux via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGP6POKzB8tsc5F1PC=-H2TKaZOONAN15sAfbf9SPEG_-LsV7g@mail.gmail.com' \
    --to=hongyi.zhao@gmail.com \
    --cc=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).