【问题标题】:Emacs, C++ code completion for vectorsEmacs,向量的 C++ 代码完成
【发布时间】:2010-03-12 17:20:15
【问题描述】:

我是 Emacs 新手,并且 我有以下代码作为示例。 我已经安装了GNU Emacs 23.1.1 (i386-mingw-nt6.1.7600),安装了cedet-1.0pre7.tar.gz. ,安装了ELPA,和company。 你可以在底部找到我的简单 Emacs 配置。

问题是,当我在 ma​​in() 中键入 q[0] 并按 .(点)时,我看到了 37向量的成员,而不是 Person,尽管需要 first_namelast_name。完成在函数 greet() 中按预期工作,但它与向量无关。

我的问题是,我怎样才能完成矢量元素的代码完成?

#include <iostream>
#include <vector>
using namespace std;

class Person
{
  public:
    string first_name;
    string last_name;
};

void greet(Person a_person)
{
  // a_person.first_name is completed as expected!
  cout << a_person.first_name << "|";
  cout << a_person.last_name << endl;
};

int main()
{
  vector<Person> q(2);

  Person guy1;
  guy1.first_name = "foo";
  guy1.last_name = "bar";

  Person guy2;
  guy2.first_name = "stack";
  guy2.last_name = "overflow";

  q[0] = guy1;
  q[1] = guy2;
  greet(guy1);
  greet(guy2);
  // cout q[0]. I want to see first_name or last_name here!
}

我的 Emacs 配置:

;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
    (load
     (expand-file-name "~/.emacs.d/elpa/package.el"))
  (package-initialize))

(load-file "~/.emacs.d/cedet/common/cedet.el")
(semantic-load-enable-excessive-code-helpers)
(require 'semantic-ia)

(global-srecode-minor-mode 1)
(semantic-add-system-include "/gcc/include/c++/4.4.2" 'c++-mode)
(semantic-add-system-include "/gcc/i386-pc-mingw32/include" 'c++-mode)
(semantic-add-system-include "/gcc/include" 'c++-mode)


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

【问题讨论】:

    标签: emacs intellisense customization stdvector cedet


    【解决方案1】:

    这是语义分析器的一个已知问题。我目前无法处理 gcc STL 中使用的Template Specialization(您的问题源于 allocator.h 中的这种专业化)。这已在邮件列表中讨论过:

    http://thread.gmane.org/gmane.emacs.semantic/2137/focus=2147

    【讨论】:

    • 感谢 pokita,至少现在我知道这不是我缺乏 Emacs 和 CEDET 知识。
    【解决方案2】:

    GCCSense

    在 Emacs 中完成一个 C++ 代码的示例:

    【讨论】:

    • 谢谢,我看到不支持 Windows 但我会在 Ubuntu 中使用它,就是这样。
    • 我使用 emacs 进行 C++ 编程。我使用 CEDET,我得到一列,我怎么能得到两列,就像在这个例子中一样?
    • @Eagle:截图展示了 GCCSense 的能力。我不知道是否可以将 GCCSense 插入 CEDET。
    • Windows 版本可以在这里找到:forums.codeblocks.org/index.php/…我已经提供了 gcc 4.5.2 的补丁和构建 gccsense 的 windows 版本的步骤
    猜你喜欢
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2011-10-12
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 2011-05-04
    相关资源
    最近更新 更多