Skip to content

Latest commit

 

History

History
68 lines (53 loc) · 2.09 KB

company.org

File metadata and controls

68 lines (53 loc) · 2.09 KB

简单的补全后端

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

Resources

company-M-x

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

company-find-file (not working)

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