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: Using digits and letters to select company-mode candidates. Date: Mon, 4 Oct 2021 19:55:18 +0800 Message-ID: References: <87v92jq4rm.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="33068"; 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 Mon Oct 04 13:56:50 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 1mXMaP-0008NO-SX for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 04 Oct 2021 13:56:49 +0200 Original-Received: from localhost ([::1]:45122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXMaN-0005j3-8H for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 04 Oct 2021 07:56:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXMZE-0005hJ-N0 for help-gnu-emacs@gnu.org; Mon, 04 Oct 2021 07:55:41 -0400 Original-Received: from mail-ua1-x92d.google.com ([2607:f8b0:4864:20::92d]:36596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mXMZA-0000Sg-Qz for help-gnu-emacs@gnu.org; Mon, 04 Oct 2021 07:55:35 -0400 Original-Received: by mail-ua1-x92d.google.com with SMTP id u11so12073636uaw.3 for ; Mon, 04 Oct 2021 04:55:31 -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=scrPAWQRLbGRCIVSUSWJKzhkTWvXZbiXLa1absSLqAQ=; b=cUzCoH121MHAlhuW7Jso+IutEWC1Xkp4DvU9ojVqXNIReOamhnjeAPNmITWm8iQlOJ Syn2zmCkXOcxdurviUoXKYjFPcwZ3+H8uWiCgAMchTX/HqXAYkKLX8Hkbn+EIG/zmB8j RJPwzSs5R0G7MxuSZNTt4oMSDgB+Od/mM224v5174NpBA0QgG9CFcDFxKZ2wZ548jTQr LzA255nHrPgRKGGjQ8A1xtVBFwUmR9BLZ5mAkYNC8Wev7rxDfeyYpx42F0ir0E7FYYG3 whrkhwY5cK+yWmkLoOewUkWxKyiN43ZRlPfOf9+toufu4SOr9IH8uRASwW51mKCUgA1C lnbQ== 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=scrPAWQRLbGRCIVSUSWJKzhkTWvXZbiXLa1absSLqAQ=; b=YiuNcWV1hXGA/acvouTucZp0V5bBDIZ+skQHeQCTsR8ysAlq6bnJnlTcyLlPMeRyXA RJANujCjiKUiA+s5Kt9noAEV+CGO0KLFiwRvkaBhtwu8Z6p/0+110XtoxVL2q+OOPrs0 6KxWlPct4r7+6mvoQOEfCSj4G5vxzLxd6viyh+OEuxz5MgbgXvrI5SFGFV14j9Xex7tv g0WncknOXtXSnYR1lY8jjKiecDdzJJ8wdbzNKkYNY1tCkxGo08DmCD8P3wJbYL3joNwk LsIXsr4HRc21IJNDlEWTRpWjPEltyf4hDa5w6U5xBFROxSsEsV4r4Ys7eRBE7uju6Syr Zw8A== X-Gm-Message-State: AOAM530I9gyeW3pCTU9nYyYayK7WzQDqx4IA3G/IoAnZ/nPROEoGUobD U3a79K/ykI8BnTNLpS/X/WQ/RG3C3NZNpeexRWE= X-Google-Smtp-Source: ABdhPJwkwukNrxOlkUE/HXJLHlY1UTA0TWohsuruR9e3vbEuI9uXwX/T5Hm5aYi+Qw7+10mRkf+GSSn1GYYzu5ElQWE= X-Received: by 2002:ab0:6556:: with SMTP id x22mr4661050uap.71.1633348529956; Mon, 04 Oct 2021 04:55:29 -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:133536 Archived-At: On Wed, Sep 29, 2021 at 6:49 PM Hongyi Zhao wrote: > > On Wed, Sep 29, 2021 at 2:23 PM Emanuel Berg via Users list for the > GNU Emacs text editor wrote: > > > > Hongyi Zhao wrote: > > > > > (define-key map (kbd "") nil)) > > > > I've heard one should put keys to #'ignore if one wants them > > to do nothing, is that what you want here? > > > > > The above code enables to select and insert company-mode > > > candidates using digits without modifier. But it can only > > > support 10 candidates, numbered 0-9. I want to extend this > > > feature to support more candidates bumbered with a single > > > digit or letter, e.g., 0-9, q, w, e, r, t, y > > > > Hm ... maybe something like this? > > > > (defun letter-to-pos (l) > > (let ((fst ?a)) > > (when (>=3D l fst) > > (+ 10 (- l fst) )))) > > > > ;; (letter-to-pos ?a) ; 10 > > ;; (letter-to-pos ?b) ; 11 > > ;; .. ; .. > > ;; (letter-to-pos ?z) ; 35 > > > > Or this? > > > > (require 'cl-lib) > > > > (defun letter-to-index (l &optional offset) > > (let*((letters (list ?q ?w ?e ?r ?t ?y)) > > (pos (cl-position l letters)) > > (offs (or offset 10)) ) > > (when pos > > (+ offs pos) ))) > > > > ;; (letter-to-index ?a) ; nil > > ;; (letter-to-index ?q) ; 10 > > ;; (letter-to-index ?w) ; 11 > > ;; (letter-to-index ?e) ; 12 > > ;; (letter-to-index ?r) ; 13 > > ;; (letter-to-index ?t) ; 14 > > ;; (letter-to-index ?y) ; 15 > > ;; (letter-to-index ?u) ; nil > > Just as the original author abo-abo has mentioned there [1]: > > Unless the number is potentially part of the candidate. > In that case, insert the number. > > > In the extended version, the corresponding problems should also be > handled correctly, i.e.: > > Unless the number or letter is potentially part of the candidate. > In that case, insert the number or letter. Hongyi Zhao wrote: > Unless the number is potentially part of the candidate. > In that case, insert the number. Make a list of candidates, then use `cl-find-if' and `string-match'. Thank you for your advice and tips. I will try to see if I can solve this problem. I=E2=80=99ve just seen your reply in the archive here[1]. Sin= ce you only reply to the list, not including my email address, which led to all your replies to be deleted by my filter. [1] https://lists.gnu.org/archive/html/help-gnu-emacs/2021-09/msg00548.html BTW, the code snippet that confuses me the most is the following part [2]: (defun ora--company-good-prefix-p (orig-fn prefix) (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix)) (funcall orig-fn prefix))) (ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-= p) According to my tries, even I commented them out, the method suggested there still works smoothly. https://github.com/abo-abo/oremacs/blob/3809390019a7083c28e8502a82da94ca3a8= ebba0/modes/ora-company.el#L41-L44 Best, HZ > I'm afraid that the above suggested code doesn't include the > corresponding manipulation for this problem. > > [1] https://github.com/abo-abo/oremacs/blob/3809390019a7083c28e8502a82da9= 4ca3a8ebba0/modes/ora-company.el#L22 > > HZ