Emacs的自动补全和IntelliSense与Visual Studio上的相同吗?

8

Linux上的emacs 22.2.1

我正在使用emacs进行C/C++编程。我想知道emacs是否支持自动完成(类似于Visual Studio中的IntelliSense)。

例如,在填写结构时,我希望在输入句点或箭头操作符时看到成员列表。

同样的,函数签名也应该显示传递的类型。


3
请访问以下链接以了解如何在 Emacs 中为 C、C++ 和 Java 配置代码提示:https://dev59.com/K3VC5IYBdhLWcg3w-WWshttps://dev59.com/JHM_5IYBdhLWcg3wp0-l - Laurynas Biveinis
6个回答

6

Meta-/并不是非常智能,但它确实会遍历已知的名称。

这个项目提供了你熟悉的下拉式菜单:

http://ecb.sourceforge.net/


1
+1 表示按下 Meta 键和 / 键。虽然它不太智能,但大多数时候都能完成任务。 - David Webb

5

您需要获取最新版本的CEDET软件包(最好直接从CVS获取)。您可以按照本网站上的文档说明进行设置。


还有一些包(company-mode,auto-complete)也使用CEDET获取完成所需的数据,但实现了不同于CEDET的完成样式。 - Alex Ott

4
我正在使用emacs的cedet。我尝试使用Debian的cedet版本,但它有一些错误,所以我卸载了它,并从http://sourceforge.net/projects/cedet/develop下载了cvs版本。
我在~/tmp/emacs-stuff/目录中编译它,然后将以下行添加到我的~/.emacs.d/custom.el文件中:


;;needed if cedet is in a custom location
(load-file "~/tmp/emacs-stuff/cedet/common/cedet.el")

;; Enable EDE (Project Management) features
(global-ede-mode t)

;;to enable code folding
(global-semantic-tag-folding-mode)

;; Enabling Semantic (code parsing, smart completion) features
;; (select only one)
;;(semantic-load-enable-minimum-features)
;;(semantic-load-enable-code-helpers)
(semantic-load-enable-gaudy-code-helpers)
;;(semantic-load-enable-all-exuberent-ctags-support)

(global-semantic-idle-scheduler-mode 1) ;The idle scheduler with automatically reparse buffers in idle time.
(global-semantic-idle-completions-mode 1) ;Display a tooltip with a list of possible completions near the cursor.
(global-semantic-idle-summary-mode 1) ;Display a tag summary of the lexical token under the cursor.

;;to work with my include files and cedet
(semantic-add-system-include "~/include" 'c++-mode)
(semantic-add-system-include "~/include" 'c-mode)


;;To use additional features for names completion, and displaying of information for tags & classes,
;; you also need to load the semantic-ia package. This could be performed with following command:
(require 'semantic-ia)

;;to work with systme include files and gcc
(require 'semantic-gcc)


;;integrate semantic with Imenu
(defun my-semantic-hook ()
  (imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)

;;load Semanticdb
(require 'semanticdb)
;;(global-semanticdb-minor-mode 1)

;;working with tags
;; gnu global support
(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)

;; ctags
(require 'semanticdb-ectag)
(semantic-load-enable-primary-exuberent-ctags-support)

(defun my-semantic-hook ()
  (imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)


这个文件被我的 ~/.emacs 文件调用,以下是它的一行代码: (load-file "~/.emacs.d/custom.el")

现在当你输入一个变量并按下CTRL+SHIFT+ENTER时,会出现一个包含建议的选择菜单。

此外,如果你已经将semantic-complete-inline-analyzer-idle-displayor-class变量设置为引用semantic-displayor-tooltip,则在一段空闲时间(1或2秒)后还会出现一个带有建议的工具提示。

有关简短介绍,请参见http://xtalk.msk.su/~ott/en/writings/emacs-devenv/EmacsCedet.html

有关Cedet文档,请参见:http://cedet.sourceforge.net/

祝好运。


3

0
如果您想使用原始的emacs来完成从项目和库包含文件的补全,请尝试此答案

0

我在我的.emacs文件中加入了以下内容,这样可以让事情变得更容易一些。

(require 'c-eldoc) (add-hook 'c-mode-hook 'c-turn-on-eldoc-mode)

这样,我就不必查找函数定义了。

虽然我不写那么多代码,但我同意TAGS也是一个非常有用的功能。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接