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: Mon, 25 Oct 2021 22:52:28 +0800 Message-ID: References: <87y26lporl.fsf@zoho.eu> <87pmrxpky4.fsf@zoho.eu> <87lf2lpig4.fsf@zoho.eu> <87h7d9pg14.fsf@zoho.eu> <871r4dpesl.fsf@zoho.eu> <87sfwtnwwj.fsf@zoho.eu> <87a6izzkln.fsf@zoho.eu> <87mtmyre09.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38595"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 25 16:55:01 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 1mf1NM-0009lV-UM for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 25 Oct 2021 16:55:00 +0200 Original-Received: from localhost ([::1]:57644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mf1NL-0006Vt-6f for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 25 Oct 2021 10:54:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mf1L9-0004Q4-TI for help-gnu-emacs@gnu.org; Mon, 25 Oct 2021 10:52:43 -0400 Original-Received: from mail-vk1-xa2e.google.com ([2607:f8b0:4864:20::a2e]:38725) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mf1L7-0007HQ-IW for help-gnu-emacs@gnu.org; Mon, 25 Oct 2021 10:52:43 -0400 Original-Received: by mail-vk1-xa2e.google.com with SMTP id o64so561828vke.5 for ; Mon, 25 Oct 2021 07:52:40 -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; bh=zyTGsTwGciKlkEDPpcGUlg1B9xIxs3ETW1sOVfM96vE=; b=REgwQiLtbo3ZfcibHDlLzYvvmH9wwDNg5FgD4akyATm0gBDkC6TcdybetSOCXydALh vjXntPtOsdvzctFg2j66Fhhm+K8TOpFGO1Fv6FKyTvzy1HhT1uGXtoWi/k9nhM1sPMCe e2/yr5TwfHiG/WzKwbK9KhbYrDisWMg+L3luGhWsMHD2xuO+2ir2xIPwtUWzsWbMycER 6swLL+/qWTCIpRDSmsuvl/UQP7Ktmd78UoLEThvxm1uo6TRLqIMEL7eCMgVLDYa47w2r 3BekA6DXnlSS1i+VUJP5OWFW/RS4Jq67urRmdRmmOaiAun+1Q6z7dv6Qbe+xk/UojVa/ wWbQ== 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; bh=zyTGsTwGciKlkEDPpcGUlg1B9xIxs3ETW1sOVfM96vE=; b=XNAAycJ6ZBMsd0TZG/T4jJiddYwjo1cETQ9HGCW5bTbCH1axV4YK2Lrd/537wv6oyX hmw9d4Qpf5zxYpGg7XSezric6MqALcEX1o1tVbNFXKCcEDEnNoz78qFGK8xgIQJoYS4D ElLoSraWYcJY3X9vlM+f9JAZsR43dgUG2kHbmLRANTI1PBm/vifrmL66NPRokCySSfcw 6vyzIUBD4tRJJX/NsmcLPwEZNAWeoT6cIuhuICJxQIMAZ3NuW2gFmsk7Gx6i8oNVlIXo CGJG3tzO9yTmR5vRgjhjzPduV68UiogOLWG02cqRjcNtzU94zAZkImXSo585zBCN1ViJ qekQ== X-Gm-Message-State: AOAM531zIN/1+r0AHZU7TmwcE4idGL+GgXrrzq8M2AEh98sYCZU14Igx Szg6TPxV+efduA8b66pIee5VBKrVyf/TLOvDqhDKrzes/AWi4ZI0 X-Google-Smtp-Source: ABdhPJxWnwtx7BU42J9v73ao7xQy3pijtPqHNV3gvEbApDTPU9lUpuGrgM/jX5bTdqKF8ghOrUHoCW/5HsbWW1BhuE0= X-Received: by 2002:a05:6122:1812:: with SMTP id ay18mr15135845vkb.14.1635173559810; Mon, 25 Oct 2021 07:52:39 -0700 (PDT) In-Reply-To: <87mtmyre09.fsf@web.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::a2e; envelope-from=hongyi.zhao@gmail.com; helo=mail-vk1-xa2e.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:134147 Archived-At: On Sun, Oct 24, 2021 at 5:03 PM Michael Heerdegen wrote: > > Hongyi Zhao writes: > > > > > (defun hz-company-search () > > > > (interactive) > > > > (if (company-search-abort) > > > > (company-search-abort) > > > > (company-search-candidates))) > > Your test obviously raises an error. Find one that works. Thank you for your comment. I checked the definitions of these two functions: ```emacs-lisp (defun company-search-abort () "Abort searching the completion candidates." (interactive) (company--search-assert-enabled) (company-search-mode 0) (company-set-selection company--search-old-selection t) (setq company-selection-changed company--search-old-changed)) (defun company-search-candidates () "Start searching the completion candidates incrementally. \\Search can be controlled with the commands: - `company-search-repeat-forward' (\\[company-search-repeat-forward]) - `company-search-repeat-backward' (\\[company-search-repeat-backward]) - `company-search-abort' (\\[company-search-abort]) - `company-search-delete-char' (\\[company-search-delete-char]) Regular characters are appended to the search string. Customize `company-search-regexp-function' to change how the input is interpreted when searching. The command `company-search-toggle-filtering' (\\[company-search-toggle-filtering]) uses the search string to filter the completion candidates." (interactive) (company-search-mode 1)) ``` And figured out the following solution: ```emacs-lisp (use-package company :bind ( :map company-active-map ("" . (lambda () (interactive) (if company-search-mode (company-search-abort) (company-search-candidates)))) :map company-search-map ("" . (lambda () (interactive) (if company-search-mode (company-search-abort) (company-search-candidates)))) ) ``` HZ