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: Wed, 29 Sep 2021 18:42:10 +0800 Message-ID: References: <87v92jq4rm.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="16733"; 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 Wed Sep 29 12:42: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 1mVX34-0004BV-9z for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 12:42:50 +0200 Original-Received: from localhost ([::1]:52348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVX32-0005Fm-Sw for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 06:42:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVX2d-0005FN-CR for help-gnu-emacs@gnu.org; Wed, 29 Sep 2021 06:42:23 -0400 Original-Received: from mail-vs1-xe36.google.com ([2607:f8b0:4864:20::e36]:33716) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVX2b-0008Qh-Rk for help-gnu-emacs@gnu.org; Wed, 29 Sep 2021 06:42:23 -0400 Original-Received: by mail-vs1-xe36.google.com with SMTP id 188so2418873vsv.0 for ; Wed, 29 Sep 2021 03:42:21 -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=qxEixnVzFSZJQm9+eUW4Yut50SyEnIeOoKKao7htTdQ=; b=GIX5AY6eDVhAqVzJ9RodydgCmXE7gnOI8JzR3C0Y6Dpaad4u+t/IFLzp5FySZhX4Iv IimM90WWJI9Bc+vzQVgp2xhPY2ejv6gWUK6yTrsmJ8cusEvZMtboJSrbbJ92y602FSG7 8y0NS5Ze8QNvJ1/FrmDzkAwlhyS5oZa39TWD77umDgYE6WvzIdz2th1KcqefCvuEWC5L M2lY/iTl0LRBb/FdpEax4aI6lJRgUGp/3VbBxxnkn26uaD/q/rKAjt1cAygKl2mlYtSt EyNDVeIE3m64YYRRGf5Ahy9i6B+xsaW9+LM2Pni4rj57W3ZrfqNPi6xVPnjPsoVD7KZo UMdg== 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=qxEixnVzFSZJQm9+eUW4Yut50SyEnIeOoKKao7htTdQ=; b=BrSfRBZ3EQPnxt6yQX/HEoRxpvMEdCQvpwtguf06Vj1UBzTdJO3EJwatt/Okq0JlCr MBRWVuOtTr31iiuZABMZ+eX5SOpxL9pfYh9LIzJ0bFG/MVvkxqnd5jFHhWDyg4yGMP58 yhOjjV0XzeW8cPg7XaAUVeotCJmAfWQNVu+xqh1E/dDAYht+wxlvf0NOJwfC1e4pQSjw RBaZGZtbPbbDGpc59COTDF21SYPXjMl8qBSUuuwz5fQLKcVhzSHbZsahm1lgqLY25Vlr r8TSfHAzIwzwRnFdr3dOAs6YG1UP/5cjwfgacRQlN6Ff3hlhMRV/XMYbVrtdSes8KOf/ rXAA== X-Gm-Message-State: AOAM53233fFB6u8BE0BjIAfJOF/SYMYlDRSjtBDu0tlNMaPBRNbXPuO8 AkbrOlPcdm5z7//mb8VcJXlvwxQVAxqTXbtPOyxgPkkUnT44/fOZ X-Google-Smtp-Source: ABdhPJyegG1HkNvnnKcyuyz/5XduyTSz1fFAyooFy/1DSACZAOgJMpfC3G7oBR9Vw7NNw6M6xlmv7oGArPZT2FHbQBM= X-Received: by 2002:a05:6102:5f4:: with SMTP id w20mr10187763vsf.55.1632912140920; Wed, 29 Sep 2021 03:42:20 -0700 (PDT) In-Reply-To: <87v92jq4rm.fsf@zoho.eu> Received-SPF: pass client-ip=2607:f8b0:4864:20::e36; envelope-from=hongyi.zhao@gmail.com; helo=mail-vs1-xe36.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:133386 Archived-At: 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? I don't know. In fact, I commented out the following code block when using it: ; (define-key map " " (lambda () ; (interactive) ; (company-abort) ; (self-insert-command 1))) ; (define-key map (kbd "") nil) > > 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 (>= 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 Thank you for your insightful comments/tips. But I still don't know how to interface them with the original code snippets. Ashamed of my superficial knowledge of lisp. HZ