all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Using digits and letters to select company-mode candidates.
Date: Wed, 29 Sep 2021 08:23:25 +0200	[thread overview]
Message-ID: <87v92jq4rm.fsf@zoho.eu> (raw)
In-Reply-To: CAGP6POLVmnVVV86Pj0oyZE_m8vbnEmePyfcs1YaZ+NOcYCfFkA@mail.gmail.com

Hongyi Zhao wrote:

> (define-key map (kbd "<return>") 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 (>= 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

HIH

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2021-09-29  6:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  0:57 Using digits and letters to select company-mode candidates Hongyi Zhao
2021-09-29  6:23 ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2021-09-29 10:42   ` Hongyi Zhao
2021-09-29 10:49   ` Hongyi Zhao
2021-09-29 18:50     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-04 11:55     ` Hongyi Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v92jq4rm.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.