abo-abo / oremacs

My Emacs config
https://oremacs.com/
296 stars 33 forks source link

A little improve of ora-company-number #35

Open carlos-wong opened 3 years ago

carlos-wong commented 3 years ago

@notbandali Hi, Thanks for the function ora-company-number. It is very useful to me. But after months use, I have a little issue when handle situation when input timestamp. the timestamp will conflict with company-number choose.

So I am added a regex to filter the company-prefix start like only number style string。It will ignore number to choose company candidate when company-prefix is number only string style. Here is the code.

(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))
         (is-only-number-re "[0-9\-\/\\]+"))
    (if (or (cl-find-if (lambda (s)
                          (string-match re s))
                        company-candidates)
            (string-match is-only-number-re company-prefix)
            (> (string-to-number k) (length company-candidates)))
        (self-insert-command 1)
      (company-complete-number (string-to-number k)))))