all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Using digits and letters to select company-mode candidates.
Date: Wed, 29 Sep 2021 08:57:24 +0800	[thread overview]
Message-ID: <CAGP6POLVmnVVV86Pj0oyZE_m8vbnEmePyfcs1YaZ+NOcYCfFkA@mail.gmail.com> (raw)

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 "<return>") 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



             reply	other threads:[~2021-09-29  0:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  0:57 Hongyi Zhao [this message]
2021-09-29  6:23 ` Using digits and letters to select company-mode candidates Emanuel Berg via Users list for the GNU Emacs text editor
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=CAGP6POLVmnVVV86Pj0oyZE_m8vbnEmePyfcs1YaZ+NOcYCfFkA@mail.gmail.com \
    --to=hongyi.zhao@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.