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: [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 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="19885"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs , Emanuel Berg To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 23 03:46:25 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 1me677-0004yH-5z for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 03:46:25 +0200 Original-Received: from localhost ([::1]:38844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1me674-0007YJ-Uh for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 22 Oct 2021 21:46:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1me66Q-0007Wz-M1 for help-gnu-emacs@gnu.org; Fri, 22 Oct 2021 21:45:49 -0400 Original-Received: from mail-ua1-x92d.google.com ([2607:f8b0:4864:20::92d]:41524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1me66D-0003XC-6B for help-gnu-emacs@gnu.org; Fri, 22 Oct 2021 21:45:39 -0400 Original-Received: by mail-ua1-x92d.google.com with SMTP id u9so1077138uac.8 for ; Fri, 22 Oct 2021 18:45:27 -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 :cc:content-transfer-encoding; bh=4MKRKiGSHE8z3LaUFUlFANPqJuBO8ZhjQ/+g08iwxPU=; b=qCi8X2zVrQzXNrsqN1Nx+yn2A8FTzd7ykouSzzr3ub6zDI/f9heACc80pw9v50K8q+ xRkowBgLe71FbbvoOX4Vrhp0A/zj5ReZJkyJEWQUmhq29hoA9vMAIpwxhKpphdMI+2V9 kAcURn1WKDcpt3sXevsBunv/kNvr3KzqPmjfdkno6rLN6PQJG0qHNmzv8b1xwhY5SCUY 1P3dI8Tj7ErYvGRAUAXt6S8DNgbniU2fA3aZdgiHVraDKFYB5q87s+AN3rWKo2omBy2r /h+fnwuM8Q/p3o+31KEj3pH0xqzWASsGNgfCNUWPG/AghPWEftgrRnOfoPHU1mOdE6GL Vh3A== 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:cc:content-transfer-encoding; bh=4MKRKiGSHE8z3LaUFUlFANPqJuBO8ZhjQ/+g08iwxPU=; b=uMYgE/PYZhNj/g7XLm51YeqZ9puG95Co/SkgjWWV6fx/eFZ5r4if7BmVsxNfH9ZpRV xZ3te7SWjJE7As+SdP+fAFEEVuz9Nly0wTxcN3euQVBpiK+jI9X1t7GwAnGSLTu+xty7 Fi0FV2lpuFp7lXA3IxscaP+yYe/jIW4sUPNQ3t8ROwwZGx4l1Jomb1R6mCour4tgHSTl YFe9bOyYO2C/oWWX+miBExp8qIO+LaxdzkirxGNeESU7dlLjEFo8fTi1rOo2FJi+N3vy bXRIA9Kj2PH1xHqVaiShjbdedkTR1e2KVibsuJC8dxGJwUOSBpZBiq3ohCY2MpFrfv5W 5FtA== X-Gm-Message-State: AOAM533G6F8LJOE650P7KpOC6s5YbRgVjIei59OZXkpkphjebQdT6wpr W1fOJLWgUpuGS0vQihqB+mxlvrJpy+EyLWYPeg+q8lwSiV7HsxPz X-Google-Smtp-Source: ABdhPJyVutr9TLO/GFMHPJHWeIrVxQW9rR0Vb/TLzlwJYXxyzwT8siNd6rrEoVTJeIjOF2EOiuPOV593EjoQ32bp0s4= X-Received: by 2002:ab0:1623:: with SMTP id k32mr4292577uae.71.1634953526819; Fri, 22 Oct 2021 18:45:26 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::92d; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x92d.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:134032 Archived-At: On Sat, Oct 23, 2021 at 1:38 AM Drew Adams wrote: > > > 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))) > > 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 ;; ("" . company-search-candidates) ;; ("" . company-search-abort) ("" . (lambda () (interactive) (if (company--active-p) #'company-search-abort #'company-search-candidates))) :map company-search-map ;; ("" . company-search-candidates) ;; ("" . company-search-abort) ("" . (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=E2=80=99t 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#discussio= ncomment-1521667 HZ --=20 Assoc. Prof. Hongyi Zhao Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province