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 14:59:13 +0800

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



reply via email to

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