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: Try to understand the ora-company-number function again. Date: Tue, 26 Oct 2021 22:56:22 +0800 Message-ID: References: <8735oomft4.fsf@zoho.eu> 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="28642"; 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 Tue Oct 26 16:59:38 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 1mfNvN-0007Cj-Jr for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 16:59:37 +0200 Original-Received: from localhost ([::1]:47870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfNvJ-0000YK-Oq for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 10:59:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfNsU-0005sD-Ve for help-gnu-emacs@gnu.org; Tue, 26 Oct 2021 10:56:40 -0400 Original-Received: from mail-vk1-xa2d.google.com ([2607:f8b0:4864:20::a2d]:35611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfNsR-0001PR-Cm for help-gnu-emacs@gnu.org; Tue, 26 Oct 2021 10:56:38 -0400 Original-Received: by mail-vk1-xa2d.google.com with SMTP id u130so7068020vku.2 for ; Tue, 26 Oct 2021 07:56:34 -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; bh=2Np2m0vvfcEkrvEc1XaHB/h3onTuJxIEJPQonJKRh5E=; b=aZy8dP6WSTgyyPSG9/c78GVPp2H3A5eE8gt7T+byqIQDz8NCezfkoXjGjEU7sMGQRM JAbfrlTnCssFQTBsP+g8Ijjus7ErO62xJocM+JihHf8a4Xhx2HHSqadAPhj+WSuV5vJ8 Wdmx63Xfhgv8TjDuh3IDD0h8LUZC6rOeg0+oVqyFE7ig483WPTU2kVoa539uBj09oFse o+3HXP+s+JLbbn65FoGYNfKxf1DCB6d8gU+lPokrKAQl/fLFLXwUqLyTsrwuBmiUNeI5 qAf8FW+Dwqqbbt+fCwd8wMB4gl+ExF2P3weFR+Uc4zasHWRDRhVzTgk/DNga09/BobBz +pGw== 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; bh=2Np2m0vvfcEkrvEc1XaHB/h3onTuJxIEJPQonJKRh5E=; b=3SfmcZ5cu+ORzPZ8ee10oTwsCWykt1kMeehjMpqyEEIlTrwSrdLqdxQBYZTsSpfxiw iHLAn35h/TxzLof7RvZ3leDk3o6mfV0US/E0RrBBruftv7B1sPzKIKW4nKMzPwI8xlsH q+oOm/fiSbRPXSUQRRyPcwmsQAnN2BFTCiJd3NQkbt0WQCCAyGR9t6cyeOkuSLy5ShRw o9VrP1YwmhTDsBbAFhX4U5zYwzkFYgfNQ1GEbhoHWmFOe6uVOvIiD4C5A9D89Hhs4EIr imBwXx2Rj1JU/9mx2OvvTXPLFs/bmJM15/3fmLxioQ102skLuzntg4MYyCahNXmNUJ5u TDXw== X-Gm-Message-State: AOAM533pzdQrIIwUjBHtrcOoUDEMP1yyxW0Htx57eFDKEeI3BVLMB1Sp RbQhC1FWaxvEIIilHo+RRsR090IDaKKehotx/O8= X-Google-Smtp-Source: ABdhPJxEcuvuIEzMwhickj+m2hCajKwLDwTPG3QV2wB4yvJ4I3GvT9hS7g8iklVIRZdKc5yHq0XbxieMhcIpGjRNSzo= X-Received: by 2002:a05:6122:1309:: with SMTP id e9mr23425411vkp.11.1635260193191; Tue, 26 Oct 2021 07:56:33 -0700 (PDT) In-Reply-To: <8735oomft4.fsf@zoho.eu> Received-SPF: pass client-ip=2607:f8b0:4864:20::a2d; envelope-from=hongyi.zhao@gmail.com; helo=mail-vk1-xa2d.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:134215 Archived-At: On Tue, Oct 26, 2021 at 4:20 PM Emanuel Berg via Users list for the GNU Emacs text editor wrote: > > Hongyi Zhao wrote: > > > ("" . hz-company-search-toggle) > > ("" . company-abort) > > I write tab "\t" and return "\r" but I don't know what the > difference is, if any ... > > > :config > > (setq company-tooltip-limit 10) > > (defun hz-company-complete-number () > > "Convert the company-quick-access-keys to the candidates' row > > NUMBER visible on the tooltip, > > and then feed it to `company-complete-number' to quickly select > > and insert company candidates. > > If the currently entered character is belongs to > > is/belongs to If the currently entered character is one of the company-quick-access-keys and a part of the candidates at the same time, > > > company-quick-access-keys and a part of the candidate simultaneously, > > append it to the currently entered string to construct > > new company-prefix." > > a new OK. Agree with you. > > > (company-complete-number > > (cond > > ((equal k "1") 1) > > ((equal k "2") 2) > > ((equal k "3") 3) > > ((equal k "4") 4) > > ((equal k "5") 5) > > ((equal k "6") 6) > > ((equal k "7") 7) > > ((equal k "8") 8) > > ((equal k "9") 9) > > ((equal k "0") 10) > > That doesn't look good to me, you can do > `string-to-number wither either > (string-to-number "9") > (string-to-number "0") I guess I forgot to simplify the above section in the case of only using digits as the company-quick-access-keys. The following should be enough [1]: (company-complete-number (if (equal k "0") 10 (string-to-number k))) [1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L36 > > (let ((c-a-map company-active-map) > > (c-s-map company-search-map)) > > (mapc (lambda (x) > > (define-key c-a-map (format "%s" x) #'hz-company-complete-number)) > > '(1 2 3 4 5 6 7 8 9 0)) > > (mapc (lambda (x) > > (define-key c-s-map (format "%s" x) #'hz-company-complete-number)) > > '(1 2 3 4 5 6 7 8 9 0))) > > Cl-loop for with i as an Iterator from 1 to 10 ... > > Also put this in the `let' clause so can be reused by us Tried the following methods, but it didn't work: (let ((c-a-map company-active-map) (c-s-map company-search-map)) (cl-loop for x in (number-sequence 0 9) do ((define-key c-a-map (format "%s" x) #'hz/company-complete-number))) (cl-loop for x in (number-sequence 0 9) do ((define-key c-s-map (format "%s" x) #'hz/company-complete-number))) ) HZ