6

I am new to Emacs, and I have the following code as a sample. I have installed GNU Emacs 23.1.1 (i386-mingw-nt6.1.7600), installed cedet-1.0pre7.tar.gz. , installed ELPA, and company. You can find my simple Emacs configuration at the bottom.

The problem is, when I type q[0] in main() and press . (dot), I see the 37 members of the vector, not Person although first_name and last_name are expected. The completion works as expected in the function greet() but it has nothing to do with vector.

My question is, how can I accomplish code completion for vector elements too?

#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!
}

My Emacs configuration:

;;; 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)
Caglar Toklu
  • 576
  • 5
  • 11

2 Answers2

7

This is a known problem with the Semantic analyzer. I currently cannot deal with Template Specialization, which is used in the gcc STL (your problem stems from such a specialization in allocator.h). This has been discussed on the mailing list:

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

pokita
  • 1,241
  • 10
  • 12
3

GCCSense

An example of completion of a C++ code in Emacs:

emacs gccsense screenshot

jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • Thanks, I see that Windows is not supported but I will use it in Ubuntu, that is something. – Caglar Toklu Apr 19 '10 at 12:37
  • i use emacs for programming in C++. I use CEDET and i get one column, how could i get two columns, like in this example? – Eagle Jan 28 '11 at 07:40
  • @Eagle: the screenshot shows GCCSense's capabilities. I don't know whether it is possible to plug GCCSense into CEDET. – jfs Jan 30 '11 at 02:13
  • 2
    Windows version can be found here: http://forums.codeblocks.org/index.php/topic,13812.msg94824.html#msg94824 I have supplied a patch on gcc 4.5.2 and the steps to build the windows version of gccsense – ollydbg23 Feb 19 '11 at 06:24