Company Backends in GNU Emacs

徘徊边缘 提交于 2019-12-02 00:57:01

A/ From the official doc,

Company is a text completion framework for Emacs. The name stands for "complete anything". It uses pluggable back-ends and front-ends to retrieve and display completion candidates.

That means that "back-ends" are the sources of information (parser,database...) company uses to suggest completion.

As an example, for C/C++ work I use the excellent RTags. Adding this back-end to company is done thanks:

(push 'company-rtags company-backends)

B/ Now for your problem, a minimal company-c-headers working example is:

(package-initialize)

(require 'company)
(require 'company-c-headers)

(add-to-list 'company-backends 'company-c-headers)

;; system dirs (for include <...>)
(add-to-list 'company-c-headers-path-system "/usr/include/c++/6")
;; (add-to-list 'company-c-headers-path-system "ANOTHER_SYSTEM_DIR")
;; -> use "gcc -E -Wp,-v -" to get the complete list

;; You can also define (for include "...")
;;(add-to-list 'company-c-headers-path-user "/home/YOUR_PROJECT")

(add-hook 'c++-mode-hook 'company-mode)
(add-hook 'c-mode-hook 'company-mode)

Save this file testing_init.el and start emacs with

emacs -q --load "testing_init.el" your_prog.cpp

Now if you type

 #include<...

in your_prog.cpp file, company should trigger an auto completion after the third typed char.

There are plenty of good tutorials to configure Emacs as a C++ editor. If think this one is a good starting point.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!