help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using digits and letters to select company-mode candidates.


From: Hongyi Zhao
Subject: Re: Using digits and letters to select company-mode candidates.
Date: Wed, 29 Sep 2021 18:49:16 +0800

On Wed, Sep 29, 2021 at 2:23 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> 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

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.

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/3809390019a7083c28e8502a82da94ca3a8ebba0/modes/ora-company.el#L22

HZ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]