公司后台在GNU Emacs [英] Company Backends in GNU Emacs
问题描述
在Emacs中,我已经安装了MELPA company-irony-c-header
包。然后我在网络上做了一些研究,显然为了配置包,我用的是激活它,我不得不补充说:
In Emacs, I have installed the MELPA company-irony-c-header
package. I then did some research on the web, and apparently in order to configure the package, what I took to mean "activating" it, I had to add this:
(defun company-my-backend (command &optional arg &rest ignored)
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-my-backend))
(prefix (when (looking-back "foo\\>") (match-string 0)))
(candidates (when (equal arg "foo") (list "foobar" "foobaz" "foobarbaz")))
(meta (format "This value is named %s" arg))))
被称为后端(含 foo
代表我的文件名)我绝对不知道后端是什么,或者如何使用它。任何帮助将不胜感激。
into something called a "back-end" (with foo
standing for whatever my filename was). I have absolutely no idea what a back-end is, or how to use it. Any help would be greatly appreciated.
推荐答案
A /从官方文档,
公司是Emacs的文本完成框架。这个名字代表
完成任何事情。它使用可插拔的后端和前端
检索并显示完成候选人。
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.
作为一个例子,对于C / C ++工作,我使用优秀的<一个href =https://github.com/Andersbakken/rtags =nofollow noreferrer> RTags 。将此后端添加到公司已经完成了:
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 / 现在为了您的问题,最小公司c-headers工作示例是: / p>
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)
保存此文件 testing_init.el 并启动emacs与
Save this file testing_init.el and start emacs with
emacs -q --load "testing_init.el" your_prog.cpp
现在,如果你键入
#include<...
$ your_prog.cpp 文件中的b
$ b
公司应在第三个类型的字符之后触发自动完成。
in your_prog.cpp file, company should trigger an auto completion after the third typed char.
有很多很好的教程将Emacs配置为C ++编辑器。如果认为这一个是一个很好的起点。
There are plenty of good tutorials to configure Emacs as a C++ editor. If think this one is a good starting point.
这篇关于公司后台在GNU Emacs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!