-
Notifications
You must be signed in to change notification settings - Fork 33
/
ora-company.el
55 lines (48 loc) · 1.79 KB
/
ora-company.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(use-package company)
(require 'company-elisp)
(csetq company-idle-delay 0.4)
(csetq company-show-numbers t)
(csetq company-elisp-detect-function-context nil)
(diminish 'company-mode " ❋")
(setq company-minimum-prefix-length 3)
(setq company-frontends
'(company-pseudo-tooltip-unless-just-one-frontend
company-preview-if-just-one-frontend))
(setq company-backends
'(company-elisp
;; company-semantic
company-capf
(company-dabbrev-code company-gtags company-etags
company-keywords)
company-files
company-dabbrev))
(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))))))
(defun ora--company-good-prefix-p (orig-fn prefix)
(unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
(funcall orig-fn prefix)))
(ora-advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)
(let ((map company-active-map))
(mapc (lambda (x) (define-key map (format "%d" x) 'ora-company-number))
(number-sequence 0 9))
(define-key map " " (lambda ()
(interactive)
(company-abort)
(self-insert-command 1)))
(define-key map (kbd "<return>") nil))
(provide 'ora-company)