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: Using digits and letters to select company-mode candidates. Date: Wed, 29 Sep 2021 08:57:24 +0800 Message-ID: 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="9775"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 29 02:58:08 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 1mVNvE-0002EH-EQ for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 02:58:08 +0200 Original-Received: from localhost ([::1]:48384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVNv9-0006id-Nh for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 28 Sep 2021 20:58:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVNuk-0006iU-NU for help-gnu-emacs@gnu.org; Tue, 28 Sep 2021 20:57:38 -0400 Original-Received: from mail-vk1-xa32.google.com ([2607:f8b0:4864:20::a32]:38420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVNuj-0005bf-A1 for help-gnu-emacs@gnu.org; Tue, 28 Sep 2021 20:57:38 -0400 Original-Received: by mail-vk1-xa32.google.com with SMTP id g15so400375vke.5 for ; Tue, 28 Sep 2021 17:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=Oc5lpy5UBG93tBAZEWmFrDql1RBixaWJGHXGOqiDWds=; b=VGcO/RHStjM9RBDVoa+Mpyrq5eeqPRFc+QmUvZ8/ZaPssnemu+X5V7SUB0x3fOVmgE 0QLwHIhHisusrPfz8N9Qv82UQ+O2tGgjTKzWphVyf5lsjwRp29VOGnG7x7Uta8SGI+uw ub5DlxeuKgy112MRFBY0QfpdKRHtLEV4Pli1djrwI+GSk/1/ee32rKZ4+m/yhyILaSQj ibaJV8/txhBNkThONsgE9LYywIvMWxXMD1FO9kz/xEZUUpCZsv6ghpjOEHvIdtIy9VsP Y0nRmL3bvm+J6Ac2otrKIrhoiEL/E7HWSr/DLHTGCl60Oz18r4mfF5fIz8yrxZ/7AtZn C/ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Oc5lpy5UBG93tBAZEWmFrDql1RBixaWJGHXGOqiDWds=; b=QJCxIchqePE6hxX2tmZD9a5cVqZSI/1AZ79MMl52Wn1CPqKa10EIb1m7IhTgqGLoys SJ39E7ov8dTgBOR94P4hQa9BWd5Xd5C4bIN2Rl56MWnA3sz5cw+vO4g8N/tVMbDDBeF0 lBgJD/XRDM1A18h+A4RbRtHTiOL7aEcff+PPlgoxRjj6UKJwHSf2Zjzo6vdv6y3EgPaG F/WAfi65Uef8oJj2e/u6N2ULM+2tZfctN/JjWEwXkRwW4jcGTOQbmujdPiAMey3IBWbS 13NcXfWaWhpv4L+BYngGk0smipYIqG0DInmPyTk3kd9o96vX6i6NffkGTmNBgItNkAaY MhpA== X-Gm-Message-State: AOAM532v/I4OXCunSiTqr2Bs1DKDL/3wHs+O375K+umECO8MJ041/6iJ PCZ2EzmWLXay7/b8z7pyXiS2etAtzdFHOZLpSzEFu84Gzzlo/rN4 X-Google-Smtp-Source: ABdhPJxkhT+5HXN4UewmahlyW+WVZxzM0aa3D4wytsrYKEmLux0hKWT7jRhiatsJ6MzllFeCtPM2y1Kv5l26rawSJ38= X-Received: by 2002:a1f:2209:: with SMTP id i9mr7214976vki.14.1632877056103; Tue, 28 Sep 2021 17:57:36 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::a32; envelope-from=hongyi.zhao@gmail.com; helo=mail-vk1-xa32.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:133364 Archived-At: The following code snippet comes here: [1] ;;; (defun ora-company-number () "Forward to `company-complete-number'. Unless the number is potentially part of the candidate. In that case, insert the number." (interactive) (let* ((k (this-command-keys)) (re (concat "^" company-prefix k))) (if (or (cl-find-if (lambda (s) (string-match re s)) company-candidates) (> (string-to-number k) (length company-candidates)) (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position))) (self-insert-command 1) (company-complete-number (if (equal k "0") 10 (string-to-number k)))))) (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) (let ((map company-active-map)) (mapc (lambda (x) (define-key map (format "%d" x) 'ora-company-number)) (number-sequence 0 9)) (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, so that I can select and insert more candidates conveniently. How can the above code be improved to achieve this goal? Any hints will be greatly appreciated. [1] https://github.com/abo-abo/oremacs/blob/github/modes/ora-company.el#L22 Regards, HZ