C-h v company-backends
查看文档( interactive
在 M-x 调用时使用,显而易见)
输入 foo
补全 foobar, foobaz 和 foobarbaz
(defun company-simple-backend (command &optional arg &rest _)
(interactive (list 'interactive))
(pcase command
('interactive (company-begin-backend 'company-simple-backend))
('prefix (when (looking-back (rx "foo" eow))
"foo"))
('candidates '("foobar" "foobaz" "foobarbaz"))))
(company-mode)
(setq-local company-backends '(company-simple-backend))
foobarbaz
C-h v company-frontends
(defun company-M-x (command &optional arg &rest _ignored)
(interactive (list 'interactive))
(pcase command
('interactive (company-begin-backend 'company-M-x))
('prefix (company-grab-symbol))
('candidates (all-completions arg obarray #'commandp))
('post-completion (command-execute (intern arg) 'record))))
(defun company-find-file (command &optional arg &rest _)
(interactive (list 'interactive))
(pcase command
('interactive (company-begin-backend 'company-find-file))
('prefix (catch 'nope
(when-let ((file
(and (looking-back "[-/_.~0-9a-zA-Z]+" (line-beginning-position) t)
(match-string-no-properties 0))))
(let* ((dir (file-name-directory file))
(base (substring file (length dir))))
(when (and dir (not (file-exists-p dir)))
(throw 'nope nil))))))
('candidates (all-completions arg obarray #'commandp))
('post-completion (command-execute (intern arg) 'record))))