gvim中c++编程的不足之处(希望有高人解答)

Vim、Emacs配置和使用
回复
nick811125
帖子: 11
注册时间: 2008-01-06 19:58
送出感谢: 0
接收感谢: 0

gvim中c++编程的不足之处(希望有高人解答)

#1

帖子 nick811125 » 2008-02-12 9:31

如很多帖子所说现生成tags
我用的命令是:
ctags -R --c++-kinds=+px --fields=+iamKlnzS --extra=+fq --language-force=c++
同样在~/.gvimrc中
let Tlist_Ctags_Cmd='ctags -R --c++-kinds=+px --fields=+iamKlnzS --extra=+fq --language-force=c++'

我的问题是:
首先是taglist的不足
如果你用一个.h文件定义下面的东东
#ifndef _CHECKCLASS_H__INC
#define _CHECKCLASS_H__INC
namespace hello{
class check{
private:
int jj;
protected:
int xiaojj;
public:
int a;
int b;
int c;
public:
check();
void hehe();
void haha();
void hoho();
};
}
#endif
然后再用一个.cpp进行实现
#include "checkclass.h"
#include <iostream>

check::check():a(1),b(2),c(3){};

void check::hehe(){
cout<<"hehe"<<endl;
}

void check::haha(){
cout<<"haha"<<endl;
}

void check::hoho(){
cout<<"hoho"<<endl;
}
这个时候你用Taglist打开taglist浏览上面的.h文件的时候不能看到hehe,haha,hoho等方法和成员,如附件里的taglist图一样,我感觉这是不爽的地方


然后是补全,我用的是omnicppcomplete
#include <iostream>
#include <string>
using namespace std;
using namespace _GLIBCXX_STD;


int main(){
int x=30, y=300, z=1024;
cout<<x<<' '<<y<<' '<<z<<endl;
string a;
a. //这个时候是找不到string的成员的,不能弹出menu
//如果换成下面的代码
basi_string<char> a;
a. //这个时候是完全能找到成员的,能弹出menu
}
原因是stl在定义string的时候用了一个typedef
typedef basic_string<char> string;
这样就导致了omnicppcomplete的失效

以上两个问题不知有高人可以解决?????
附件
taglist.jpg
头像
Strange
帖子: 1823
注册时间: 2006-05-19 9:54
来自: Shanghai
送出感谢: 2 次
接收感谢: 10 次

#2

帖子 Strange » 2008-02-12 13:02

这两个其实都不是vim,是ctags的问题

*假定我们用的ctags都是Exuberant Ctags*

问题一貌似无解...?
Exuberant Ctags貌似就是只能从defination抓tag而不是declaration
尝试一下其他ctags的clone或许能行

问题二的话
要看ctags的版本了,vim文档里面也有提到
For version 5.5.4 you should add a patch that adds the "typename:" field:
ftp://ftp.vim.org/pub/vim/unstable/patc ... .5.4.patch
用新版本的话,应该没有问题了,或者就直接用他那个补丁过的版本
nick811125
帖子: 11
注册时间: 2008-01-06 19:58
送出感谢: 0
接收感谢: 0

#3

帖子 nick811125 » 2008-02-12 14:24

ctags-exuberant --version
Exuberant Ctags 5.6, Copyright (C) 1996-2004 Darren Hiebert
Compiled: Aug 2 2006, 01:53:15
Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex

这是我的ctags的信息
首先是ctags-exuberant
然后是版本是5.6的

2楼你所说的clone的版本是指哪些???能否告知一二??
头像
Strange
帖子: 1823
注册时间: 2006-05-19 9:54
来自: Shanghai
送出感谢: 2 次
接收感谢: 10 次

#4

帖子 Strange » 2008-02-12 14:49

5.6的话,看一下生成的tags文件里面有没有 typename 这一项?

Exuberant ctags本身就是一个ctags的clone,只不过实在太常用,导致其他ctags反而不知名了
稍微搜了一下,etags,elvis的ctags好像有从defination抓tag的功能,具体当然是没有试过

或许lz有兴趣帮Exuberant ctags加上这个功能 :D
nick811125
帖子: 11
注册时间: 2008-01-06 19:58
送出感谢: 0
接收感谢: 0

#5

帖子 nick811125 » 2008-02-12 15:02

还有我不觉得是ctags的问题,我觉得是taglist的问题我把我生成的tag文件帖出来
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.6 //
_CHECKCLASS_H__INC checkclass.h 21;" kind:macro line:21 language:C++
a checkclass.h 29;" kind:member line:29 language:C++ class:hello::check access:public
a main.cpp 22;" kind:local line:22 language:C++
b checkclass.h 30;" kind:member line:30 language:C++ class:hello::check access:public
c checkclass.h 31;" kind:member line:31 language:C++ class:hello::check access:public
check checkclass.cpp 22;" kind:function line:22 language:C++ class:check signature:()
check checkclass.h 23;" kind:class line:23 language:C++ namespace:hello
check checkclass.h 33;" kind:prototype line:33 language:C++ class:hello::check access:public signature:()
check::check checkclass.cpp 22;" kind:function line:22 language:C++ class:check signature:()
check::hehe checkclass.cpp 24;" kind:function line:24 language:C++ class:check signature:()
checkclass.cpp checkclass.cpp 1;" kind:file line:1 language:C++
checkclass.h checkclass.h 1;" kind:file line:1 language:C++
cout.cpp cout.cpp 1;" kind:file line:1 language:C++
haha checkclass.h 35;" kind:prototype line:35 language:C++ class:hello::check access:public signature:()
hehe checkclass.cpp 24;" kind:function line:24 language:C++ class:check signature:()
hehe checkclass.h 34;" kind:prototype line:34 language:C++ class:hello::check access:public signature:()
hello checkclass.h 22;" kind:namespace line:22 language:C++
hello::check checkclass.h 23;" kind:class line:23 language:C++ namespace:hello
hello::check::a checkclass.h 29;" kind:member line:29 language:C++ class:hello::check access:public
hello::check::b checkclass.h 30;" kind:member line:30 language:C++ class:hello::check access:public
hello::check::c checkclass.h 31;" kind:member line:31 language:C++ class:hello::check access:public
hello::check::check checkclass.h 33;" kind:prototype line:33 language:C++ class:hello::check access:public signature:()
hello::check::haha checkclass.h 35;" kind:prototype line:35 language:C++ class:hello::check access:public signature:()
hello::check::hehe checkclass.h 34;" kind:prototype line:34 language:C++ class:hello::check access:public signature:()
hello::check::hoho checkclass.h 36;" kind:prototype line:36 language:C++ class:hello::check access:public signature:()
hello::check::jj checkclass.h 25;" kind:member line:25 language:C++ class:hello::check access:private
hello::check::xiaojj checkclass.h 27;" kind:member line:27 language:C++ class:hello::check access:protected
hoho checkclass.h 36;" kind:prototype line:36 language:C++ class:hello::check access:public signature:()
jj checkclass.h 25;" kind:member line:25 language:C++ class:hello::check access:private
main cout.cpp 26;" kind:function line:26 language:C++ signature:()
main main.cpp 21;" kind:function line:21 language:C++ signature:()
main.cpp main.cpp 1;" kind:file line:1 language:C++
x cout.cpp 27;" kind:local line:27 language:C++
xiaojj checkclass.h 27;" kind:member line:27 language:C++ class:hello::check access:protected
y cout.cpp 27;" kind:local line:27 language:C++
z cout.cpp 27;" kind:local line:27 language:C++
tag文件生成得很完整,但是taglist并没有完整的显示tag里面的列容
头像
Strange
帖子: 1823
注册时间: 2006-05-19 9:54
来自: Shanghai
送出感谢: 2 次
接收感谢: 10 次

#6

帖子 Strange » 2008-02-12 16:50

你有一个基本问题没搞清,taglist使用的tag是他自己生成的,而不是你在外面生成的tags文件
let Tlist_Ctags_Cmd 只是用来设置命令位置,而不是用来设置参数的
事实上,ctags执行中会自动加入很多参数,结果就是,那些declaration并没有被taglist调用的ctags显示出来

或许问题1的答案应该纠正成这样,taglist不支持这样的功能。
nick811125
帖子: 11
注册时间: 2008-01-06 19:58
送出感谢: 0
接收感谢: 0

#7

帖子 nick811125 » 2008-02-12 22:15

Strange 写了:你有一个基本问题没搞清,taglist使用的tag是他自己生成的,而不是你在外面生成的tags文件
let Tlist_Ctags_Cmd 只是用来设置命令位置,而不是用来设置参数的
事实上,ctags执行中会自动加入很多参数,结果就是,那些declaration并没有被taglist调用的ctags显示出来

或许问题1的答案应该纠正成这样,taglist不支持这样的功能。
确实是如你说的一样,这个是taglist不支持………………

但是还有一个问题也是让我不甘心的地方,那就是typedef的问题
上面的.h和.cpp文件照旧不变,现在我加一个checktype.h文件,里面自己定义了一个typedef

#ifndef _CHECKTYPE_H__INC
#define _CHECKTYPE_H__INC
#include "xxxx.h" //class check的头文件
typedef check mycheck;
#endif /* ----- #ifndef _CHECKTYPE_H__INC ----- */

然后主cpp:
#include "checktype.h"

int main(){
mycheck a;
a. //这个时候还是不能进行补全,omnicppcomplete告知不知道补全模式,不知道你的是不是这样??
}

我生成的tag文件里面却有这个typedef,如下:
!#ifndef _CHECKTYPE_H__INC
#define _CHECKTYPE_H__INC
typedef check mycheck;
#endif /* ----- #ifndef _CHECKTYPE_H__INC ----- */_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.6 //
.checkclass.cpp.swp .checkclass.cpp.swp 1;" kind:file line:1 language:C++
.checkclass.h.swp .checkclass.h.swp 1;" kind:file line:1 language:C++
.checktags.swp .checktags.swp 1;" kind:file line:1 language:C++
.checktype.h.swp .checktype.h.swp 1;" kind:file line:1 language:C++
.cout.cpp.swp .cout.cpp.swp 1;" kind:file line:1 language:C++
.main.cpp.swp .main.cpp.swp 1;" kind:file line:1 language:C++
_CHECKCLASS_H__INC checkclass.h 21;" kind:macro line:21 language:C++
_CHECKTYPE_H__INC checktype.h 21;" kind:macro line:21 language:C++
a checkclass.h 29;" kind:member line:29 language:C++ class:hello::check access:public
a main.cpp 23;" kind:local line:23 language:C++
b checkclass.h 30;" kind:member line:30 language:C++ class:hello::check access:public
c checkclass.h 31;" kind:member line:31 language:C++ class:hello::check access:public
check checkclass.cpp 22;" kind:function line:22 language:C++ class:check signature:()
check checkclass.h 23;" kind:class line:23 language:C++ namespace:hello
check checkclass.h 33;" kind:prototype line:33 language:C++ class:hello::check access:public signature:()
check::check checkclass.cpp 22;" kind:function line:22 language:C++ class:check signature:()
check::hehe checkclass.cpp 24;" kind:function line:24 language:C++ class:check signature:()
checkclass.cpp checkclass.cpp 1;" kind:file line:1 language:C++
checkclass.h checkclass.h 1;" kind:file line:1 language:C++
checktags checktags 1;" kind:file line:1 language:C++
checktype.h checktype.h 1;" kind:file line:1 language:C++
cout.cpp cout.cpp 1;" kind:file line:1 language:C++
cppcomplete.tags cppcomplete.tags 1;" kind:file line:1 language:C++
format checktags 1;" kind:variable line:1 language:C++
format cppcomplete.tags 1;" kind:variable line:1 language:C++
format jjtags 1;" kind:variable line:1 language:C++
format xinjjtags 1;" kind:variable line:1 language:C++
haha checkclass.h 35;" kind:prototype line:35 language:C++ class:hello::check access:public signature:()
hehe checkclass.cpp 24;" kind:function line:24 language:C++ class:check signature:()
hehe checkclass.h 34;" kind:prototype line:34 language:C++ class:hello::check access:public signature:()
hello checkclass.h 22;" kind:namespace line:22 language:C++
hello::check checkclass.h 23;" kind:class line:23 language:C++ namespace:hello
hello::check::a checkclass.h 29;" kind:member line:29 language:C++ class:hello::check access:public
hello::check::b checkclass.h 30;" kind:member line:30 language:C++ class:hello::check access:public
hello::check::c checkclass.h 31;" kind:member line:31 language:C++ class:hello::check access:public
hello::check::check checkclass.h 33;" kind:prototype line:33 language:C++ class:hello::check access:public signature:()
hello::check::haha checkclass.h 35;" kind:prototype line:35 language:C++ class:hello::check access:public signature:()
hello::check::hehe checkclass.h 34;" kind:prototype line:34 language:C++ class:hello::check access:public signature:()
hello::check::hoho checkclass.h 36;" kind:prototype line:36 language:C++ class:hello::check access:public signature:()
hello::check::jj checkclass.h 25;" kind:member line:25 language:C++ class:hello::check access:private
hello::check::xiaojj checkclass.h 27;" kind:member line:27 language:C++ class:hello::check access:protected
hoho checkclass.h 36;" kind:prototype line:36 language:C++ class:hello::check access:public signature:()
jj checkclass.h 25;" kind:member line:25 language:C++ class:hello::check access:private
jjtags .checktags.swp 8;" kind:variable line:8 language:C++
jjtags jjtags 1;" kind:file line:1 language:C++
main cout.cpp 26;" kind:function line:26 language:C++ signature:()
main main.cpp 22;" kind:function line:22 language:C++ signature:()
main.cpp main.cpp 1;" kind:file line:1 language:C++
mycheck checktype.h 23;" kind:typedef line:23 language:C++
x cout.cpp 27;" kind:local line:27 language:C++
xiaojj checkclass.h 27;" kind:member line:27 language:C++ class:hello::check access:protected
xinjjtags checktags 10;" kind:variable line:10 language:C++
xinjjtags xinjjtags 1;" kind:file line:1 language:C++
y cout.cpp 27;" kind:local line:27 language:C++
z cout.cpp 27;" kind:local line:27 language:C++
头像
Strange
帖子: 1823
注册时间: 2006-05-19 9:54
来自: Shanghai
送出感谢: 2 次
接收感谢: 10 次

#8

帖子 Strange » 2008-02-13 9:46

checktype.h连namespace都没有,怎么叫ctags抓tag啊...
还有,顺便升级ctags到5.7吧
nick811125
帖子: 11
注册时间: 2008-01-06 19:58
送出感谢: 0
接收感谢: 0

#9

帖子 nick811125 » 2008-02-13 11:04

好了好了!!!!!!
这下好了!!!!!!!!!

确实是我自己不小心!!!!!!
strange,非常感谢你!!!!!!!!!!!谢谢你这么有耐心!!!!!!!!谢谢!!!!!!!!
头像
openware
帖子: 173
注册时间: 2009-02-22 14:15
送出感谢: 0
接收感谢: 0
联系:

Re: gvim中c++编程的不足之处(希望有高人解答)

#10

帖子 openware » 2009-04-03 23:03

学习了.
Desire Freedom, Love Beauty, Keep Hacking。
回复

回到 “Vim和Emacs”