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

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

Re: Try to understand the ora-company-number function again.


From: Hongyi Zhao
Subject: Re: Try to understand the ora-company-number function again.
Date: Thu, 21 Oct 2021 18:51:53 +0800

On Thu, Oct 21, 2021 at 6:48 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> I came up with the following solution that seems to work:
>
> ```emacs-lisp
> (use-package comany

use-package company

>   :config
>   (setq company-tooltip-limit 16
>       company-quick-access-keys '("1" "2" "3" "4" "5" "6" "7" "8" "9"
> "0" "q" "w" "e" "r" "t" "y"))
>
>   (defun hz-company-number ()
>     "Convert the company-quick-access-keys to the candidates' row
> NUMBER visible on the tooltip,
>      and then feed it to `company-complete-number' to quickly select
> and insert company candidates.
>      If the currently entered character is belongs to
> company-quick-access-keys and a part of the candidate simultaneously,
>      append it to the currently entered string to construct new 
> company-prefix."
>     (interactive)
>     (let* ((k (this-command-keys))
>            (re (concat "^" company-prefix k)))
>       (if (cl-find-if (lambda (s) (string-match re s))
>                       company-candidates)
>
>       (self-insert-command 1)
>         (company-complete-number
>      (cond
>       ((equal k "1") 1)
>       ((equal k "2") 2)
>       ((equal k "3") 3)
>       ((equal k "4") 4)
>       ((equal k "5") 5)
>       ((equal k "6") 6)
>       ((equal k "7") 7)
>       ((equal k "8") 8)
>       ((equal k "9") 9)
>       ((equal k "0") 10)
>       ((equal k "q") 11)
>       ((equal k "w") 12)
>       ((equal k "e") 13)
>       ((equal k "r") 14)
>       ((equal k "t") 15)
>       ((equal k "y") 16))
>      ))))
>
>   (let ((map company-active-map))
>     (mapc (lambda (x) (define-key map (format "%s" x) 'hz-company-number))
>       '(0 1 2 3 4 5 6 7 8 9 q w e r t y))))
> ```
>
> Please refer to the following related discussions for some more
> related information:
>
> [1] https://github.com/abo-abo/oremacs/issues/38#issuecomment-948472184
> [2] https://lists.gnu.org/archive/html/help-gnu-emacs/2021-09/msg00527.html
>
> Any enhancements/suggestions are welcome.
>
> HZ



-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



reply via email to

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