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: Fri, 22 Oct 2021 10:33:27 +0800

On Thu, Oct 21, 2021 at 10:00 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> I have adopted the following method, which seems to be more efficient
>
> ```emacs-lisp
> (use-package comany
>   :config
>   (setq company-tooltip-limit 16
>            company-quick-access-keys '("1" "2" "3" "4" "5" "6" "7" "8"
> "9" "0" "=" "\;" "\`" "\'" "\," "\/")
>   (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 "=") 11)
>       ((equal k "\;") 12)
>       ((equal k "\`") 13)
>       ((equal k "\'") 14)
>       ((equal k "\,") 15)
>       ((equal k "\/") 16))
>      ))))
>
>   (let ((map company-active-map))
>     (mapc (lambda (x) (define-key map (format "%s" x) 'hz-company-number))
>       '(1 2 3 4 5 6 7 8 9 0 = \; \` \' \, \/))))
> ```

Further improvement is the following configuration:

```emacs-lisp
(use-package company
   :bind
   (:map company-active-map
    ("<tab>" . company-search-candidates)
    ("<backtab>" . company-search-abort)
    ("SPC" . company-complete-selection)
    ("<return>" . company-abort)

    :map company-search-map
    ("<tab>" . company-search-candidates)
    ("<backtab>" . company-search-abort)
    ("SPC" . company-complete-selection)
    ("<return>" . company-abort))

  :config
  (setq company-tooltip-limit 15
      company-quick-access-keys '("1" "2" "3" "4" "5" "6" "7" "8" "9"
"0" "=" "\;" "\`" "\," "\/"))

   (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 "=") 11)
      ((equal k "\;") 12)
      ((equal k "\`") 13)
      ((equal k "\,") 14)
      ((equal k "\/") 15))
     ))))

  (let ((map company-active-map))
    (mapc (lambda (x) (define-key map (format "%s" x) 'hz-company-number))
      '(1 2 3 4 5 6 7 8 9 0 = \; \` \, \/))))
```

HZ



reply via email to

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