all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Try to understand the ora-company-number function again.
@ 2021-10-21  6:54 Hongyi Zhao
  2021-10-21  6:59 ` Hongyi Zhao
  2021-10-21  7:11 ` Hongyi Zhao
  0 siblings, 2 replies; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-21  6:54 UTC (permalink / raw)
  To: help-gnu-emacs

I try to understand the  ora-company-number function [1] again:

(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))))))

I've figured out all the intention of the above code snippet except
the following line:

(looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)

I can't understand why the regexp used here must be written in this
form. Any hints will be appreciated.

[1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L22

Regards
-- 
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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-21  6:54 Try to understand the ora-company-number function again Hongyi Zhao
@ 2021-10-21  6:59 ` Hongyi Zhao
  2021-10-21  7:11 ` Hongyi Zhao
  1 sibling, 0 replies; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-21  6:59 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Oct 21, 2021 at 2:54 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> I try to understand the  ora-company-number function [1] again:
>
> (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))))))
>
> I've figured out all the intention of the above code snippet except
> the following line:
>
> (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)
>
> I can't understand why the regexp used here must be written in this
> form. Any hints will be appreciated.

And I also find another version of this function [2] defined as follows:

(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 (cl-find-if (lambda (s) (string-match re s))
company-candidates)
(self-insert-command 1)
(company-complete-number (string-to-number k)))))


[2] https://github.com/opsound/.emacs.d/blob/74d2a8a60d371aa7e5318160f86d14600dfca8e8/init.el#L410


> [1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L22
>
> Regards
> --
> 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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-21  6:54 Try to understand the ora-company-number function again Hongyi Zhao
  2021-10-21  6:59 ` Hongyi Zhao
@ 2021-10-21  7:11 ` Hongyi Zhao
  2021-10-21 10:48   ` Hongyi Zhao
  1 sibling, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-21  7:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Oct 21, 2021 at 2:54 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> I try to understand the  ora-company-number function [1] again:
>
> (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))))))
>
> I've figured out all the intention of the above code snippet except
> the following line:
>
> (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)
>
> I can't understand why the regexp used here must be written in this
> form. Any hints will be appreciated.

Based on my tries, the following code snippet is enough:

  (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 (cl-find-if (lambda (s) (string-match re s))
                      company-candidates)

      (self-insert-command 1)
        (company-complete-number
         (if (equal k "0") 10
           (string-to-number k)))
    )))


> [1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L22
>
> Regards
> --
> 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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-21  7:11 ` Hongyi Zhao
@ 2021-10-21 10:48   ` Hongyi Zhao
  2021-10-21 10:51     ` Hongyi Zhao
  0 siblings, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-21 10:48 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Oct 21, 2021 at 3:11 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Thu, Oct 21, 2021 at 2:54 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >
> > I try to understand the  ora-company-number function [1] again:
> >
> > (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))))))
> >
> > I've figured out all the intention of the above code snippet except
> > the following line:
> >
> > (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)
> >
> > I can't understand why the regexp used here must be written in this
> > form. Any hints will be appreciated.
>
> Based on my tries, the following code snippet is enough:
>
>   (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 (cl-find-if (lambda (s) (string-match re s))
>                       company-candidates)
>
>       (self-insert-command 1)
>         (company-complete-number
>          (if (equal k "0") 10
>            (string-to-number k)))
>     )))
>
>
> > [1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L22

I came up with the following solution that seems to work:

```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" "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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-21 10:48   ` Hongyi Zhao
@ 2021-10-21 10:51     ` Hongyi Zhao
  2021-10-21 14:00       ` Hongyi Zhao
  0 siblings, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-21 10:51 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-21 10:51     ` Hongyi Zhao
@ 2021-10-21 14:00       ` Hongyi Zhao
  2021-10-22  2:33         ` Hongyi Zhao
  0 siblings, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-21 14:00 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Oct 21, 2021 at 6:51 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> 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.

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 = \; \` \' \, \/))))
```



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-21 14:00       ` Hongyi Zhao
@ 2021-10-22  2:33         ` Hongyi Zhao
  2021-10-26  5:19           ` Hongyi Zhao
  0 siblings, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-22  2:33 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-22  2:33         ` Hongyi Zhao
@ 2021-10-26  5:19           ` Hongyi Zhao
  2021-10-26  7:00             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-26  5:19 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Oct 22, 2021 at 10:33 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:

Current version [1]:

```emacs-lisp
(use-package company
   :init
  (defun hz-company-search-toggle ()
    (interactive)
    (if company-search-mode
    (company-search-abort)
      (company-search-candidates)))
   :bind
   (:map company-active-map
    ("<tab>" . hz-company-search-toggle)
    ("<f1>" . company-search-repeat-forward)
    ("<f2>" . company-search-repeat-backward)
    ("SPC" . company-complete-selection)
    ("<return>" . company-abort)

    :map company-search-map
    ("<tab>" . hz-company-search-toggle)
    ("<f1>" . company-search-repeat-forward)
    ("<f2>" . company-search-repeat-backward)
    ("SPC" . company-complete-selection)
    ("<return>" . company-abort)
)

  :config
  (setq company-tooltip-limit 10)
 (defun hz-company-complete-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)
      )
     ))))

  (let ((c-a-map company-active-map)
    (c-s-map company-search-map))
    (mapc (lambda (x)
        (define-key c-a-map (format "%s" x) #'hz-company-complete-number))
      '(1 2 3 4 5 6 7 8 9 0))
    (mapc (lambda (x)
        (define-key c-s-map (format "%s" x) #'hz-company-complete-number))
      '(1 2 3 4 5 6 7 8 9 0)))
)
```

[1] https://github.com/abo-abo/oremacs/issues/38#issuecomment-948472184

HZ



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-26  5:19           ` Hongyi Zhao
@ 2021-10-26  7:00             ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-26 14:56               ` Hongyi Zhao
  0 siblings, 1 reply; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-26  7:00 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

>     ("<tab>"    . hz-company-search-toggle)
>     ("<return>" . company-abort)

I write tab "\t" and return "\r" but I don't know what the
difference is, if any ...

>   :config
>   (setq company-tooltip-limit 10)
>  (defun hz-company-complete-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

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."

a new

>     (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)

That doesn't look good to me, you can do
`string-to-number wither either
(string-to-number "9")
(string-to-number "0") I guess

>   (let ((c-a-map company-active-map)
>     (c-s-map company-search-map))
>     (mapc (lambda (x)
>         (define-key c-a-map (format "%s" x) #'hz-company-complete-number))
>       '(1 2 3 4 5 6 7 8 9 0))
>     (mapc (lambda (x)
>         (define-key c-s-map (format "%s" x) #'hz-company-complete-number))
>       '(1 2 3 4 5 6 7 8 9 0)))

Cl-loop for with i as an Iterator from 1 to 10 ...

Also put this in the `let' clause so can be reused by us

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




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-26  7:00             ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-26 14:56               ` Hongyi Zhao
  2021-10-27 23:08                 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: Hongyi Zhao @ 2021-10-26 14:56 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Tue, Oct 26, 2021 at 4:20 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> >     ("<tab>"    . hz-company-search-toggle)
> >     ("<return>" . company-abort)
>
> I write tab "\t" and return "\r" but I don't know what the
> difference is, if any ...
>
> >   :config
> >   (setq company-tooltip-limit 10)
> >  (defun hz-company-complete-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
>
> is/belongs to

 If the currently entered character is one of the
company-quick-access-keys and a part of the candidates at the same
time,

>
> > company-quick-access-keys and a part of the candidate simultaneously,
> >      append it to the currently entered string to construct
> >      new company-prefix."
>
> a new

OK. Agree with you.

>
> >     (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)
>
> That doesn't look good to me, you can do
> `string-to-number wither either
> (string-to-number "9")
> (string-to-number "0") I guess

I forgot to simplify the above section in the case of only using
digits as the company-quick-access-keys. The following should be
enough [1]:

    (company-complete-number
     (if (equal k "0")
             10
           (string-to-number k)))

[1] https://github.com/abo-abo/oremacs/blob/0c5f3284acedc966948cbb930e779af5189fd54e/modes/ora-company.el#L36


> >   (let ((c-a-map company-active-map)
> >     (c-s-map company-search-map))
> >     (mapc (lambda (x)
> >         (define-key c-a-map (format "%s" x) #'hz-company-complete-number))
> >       '(1 2 3 4 5 6 7 8 9 0))
> >     (mapc (lambda (x)
> >         (define-key c-s-map (format "%s" x) #'hz-company-complete-number))
> >       '(1 2 3 4 5 6 7 8 9 0)))
>
> Cl-loop for with i as an Iterator from 1 to 10 ...
>
> Also put this in the `let' clause so can be reused by us

Tried the following methods, but it didn't work:

  (let ((c-a-map company-active-map)
    (c-s-map company-search-map))

    (cl-loop for x in (number-sequence 0 9)
         do ((define-key c-a-map (format "%s" x) #'hz/company-complete-number)))
    (cl-loop for x in (number-sequence 0 9)
         do ((define-key c-s-map (format "%s" x) #'hz/company-complete-number)))
    )

HZ



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Try to understand the ora-company-number function again.
  2021-10-26 14:56               ` Hongyi Zhao
@ 2021-10-27 23:08                 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-27 23:08 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

>     (company-complete-number
>      (if (equal k "0")
>              10
>            (string-to-number k)))

(mod (string-to-number k) 10)

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




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-10-27 23:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-21  6:54 Try to understand the ora-company-number function again Hongyi Zhao
2021-10-21  6:59 ` Hongyi Zhao
2021-10-21  7:11 ` Hongyi Zhao
2021-10-21 10:48   ` Hongyi Zhao
2021-10-21 10:51     ` Hongyi Zhao
2021-10-21 14:00       ` Hongyi Zhao
2021-10-22  2:33         ` Hongyi Zhao
2021-10-26  5:19           ` Hongyi Zhao
2021-10-26  7:00             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26 14:56               ` Hongyi Zhao
2021-10-27 23:08                 ` Emanuel Berg via Users list for the GNU Emacs text editor

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.