From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help 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 Message-ID: References: <87y26lporl.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19455"; mail-complaints-to="usenet@ciao.gmane.io" To: Emanuel Berg , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 22 09:34:57 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdp4r-0004p2-68 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 22 Oct 2021 09:34:57 +0200 Original-Received: from localhost ([::1]:48214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdp4p-0004Sp-Mh for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 22 Oct 2021 03:34:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdp4K-0004Sb-RE for help-gnu-emacs@gnu.org; Fri, 22 Oct 2021 03:34:24 -0400 Original-Received: from mail-vk1-xa34.google.com ([2607:f8b0:4864:20::a34]:33381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mdp4J-0006FD-Do for help-gnu-emacs@gnu.org; Fri, 22 Oct 2021 03:34:24 -0400 Original-Received: by mail-vk1-xa34.google.com with SMTP id r26so1079900vkq.0 for ; Fri, 22 Oct 2021 00:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=6EfbJLov94A5sSFVrNm4382UZWlXfEg4tqAUVPeUumk=; b=de04nGeX24MLmFvfCdEevR9us+LwDlSZuMz0x+sdG3iuBcL1Uimg7i8Yhvy0jfkYGe YTuKrltxmwB6KX1X2GFqsQok3B9MSl2HqS2bL/BNmnhsmqn/Ct36hB7s4bGXiOSaxHQn KOEnOJGp5oS6aNjNnOAlMwmtPk8mED2OjXrl9hp7ILlCb0j5tVx+MZQRMqWmnbc5/3V1 Zkgza6XApIv3okHe/8/bIRosuR6vY/Wi+DMynUinaEeb0l5hOmkmdPGwq1+EHQKwTAWN SVqSBJ1m/Ae9nsgQc0r9npnU0fxavvQeOJH8fo9AdmwTc8A2nQwD1WlDE3U9CzUmSUIo DQXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=6EfbJLov94A5sSFVrNm4382UZWlXfEg4tqAUVPeUumk=; b=W71fnaLozGDPWy5UbNMsuqRO1UpaoG/0oUsDw6l5Repmnhr5ViqQJSbp0Az4KlEPUh g+sv6ZRooHhIp24JeQJUDP+gpgGBgy3WuUAccg4HbexmHmsy9kJrPBcx2qrwRVPNCCsB mIhG6IEXrNetuy9prTj8fVoWBtj4h6iKb5mZw2A4seztyHPMxvHjZGyJi1/cHh7PyZYY s2SUeNSFm3T8/0fG9m3PWrHccMhmmgVGxxoZRFllmm+Mnrbsdnwm37Ht1s8Hn0OVhBVm d4qtD7NuCGcN3C9PKHeMGdx0LlT6O3LPjOgyN7QXTCinGSyOyoP6aO5Fzt7PQu168LgH bAFA== X-Gm-Message-State: AOAM533ovyZzkbX3IAIdJZ74HurEw3V5u74SD5NWSWAfpG1Ic2p2rd6O Mq6VShZTbAY/+J3nejoDWX7e0aDz8z6tA62IDroCqy/BfxbFsFVu X-Google-Smtp-Source: ABdhPJxv+7/4EeZAKsoMV6riVX1Lrt5X+TnZdUuAyoIh+UGU7KF+XhU7dPa5VzkyipBddrxXRPqEe12OooeR4NP5xLE= X-Received: by 2002:a05:6122:a10:: with SMTP id 16mr12103507vkn.1.1634888062347; Fri, 22 Oct 2021 00:34:22 -0700 (PDT) In-Reply-To: <87y26lporl.fsf@zoho.eu> Received-SPF: pass client-ip=2607:f8b0:4864:20::a34; envelope-from=hongyi.zhao@gmail.com; helo=mail-vk1-xa34.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133995 Archived-At: 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 > > "" key to the following commands when the local keymaps > > are company-search-map or company-active-map to toggle > > between them: > > > > ("" . company-search-candidates) > > > > and > > > > ("" . company-search-abort) > > > > If the company-search-candidates command is in active, then > > run company-search-abort when hitting , 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 =E2=80=98company.el= =E2=80=99. (company-search-mode &optional ARG) Search mode for completion candidates. Don=E2=80=99t start this directly, use =E2=80=98company-search-candidates= =E2=80=99 or =E2=80=98company-filter-candidates=E2=80=99. This is a minor mode. If called interactively, toggle the =E2=80=98Company-Search mode=E2=80=99 mode. If the prefix argument is posi= tive, enable the mode, and if it is zero or negative, disable the mode. If called from Lisp, toggle the mode if ARG is =E2=80=98toggle=E2=80=99. E= nable 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 =E2=80=98company-search-mode=E2=80=99. The mode=E2=80=99s 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: ("" . (lamda () (if (company-search-mode) #'company-search-abort #'company-search-candidates))) What's the problem? Regards, HZ