Loading ...
Sorry, an error occurred while loading the content.

76477Re: automatic code completion in vim

Expand Messages
  • Zheng Da
    Jan 4, 2007
    • 0 Attachment
      On 1/4/07, Vissale NEANG <fromtonrouge@...> wrote:
      > There is also an "autotag" plugin (just found it):
      >
      > http://www.vim.org/scripts/script.php?script_id=1343
      >
      > But I have not yet try it. It seems you need to compile vim with python.
      >
      > 2007/1/4, Zheng Da <zhengda1936@...>:
      > > On 1/4/07, Vissale NEANG <fromtonrouge@...> wrote:
      > > > You can use the vim sort command (:help sort) instead of gnu sort.
      > > > Moreover it's portable.
      > > >
      > > > 2007/1/4, Zheng Da <zhengda1936@...>:
      > > > > On 1/4/07, Vissale NEANG <fromtonrouge@...> wrote:
      > > > > > It's because your tag file is not sorted correctly, the last tag
      > > > > > "main" should be the first tag in the file. The script does a tag
      > > > > > binary search and the tags file must be sorted to work properly (:help
      > > > > > tag-binary-search).
      > > > > >
      > > > > > Best regards,
      > > > > >
      > > > > > Vissale
      > > > > >
      > > > > > 2007/1/3, zhengda <zhengda1936@...>:
      > > > > > > Vissale NEANG wrote:
      > > > > > > > What is you ctags command?
      > > > > > > > Could you send me your tag file?
      > > > > > > >
      > > > > > > > Just for comparison I give you my tag file
      > > > > > > >
      > > > > > > > 2007/1/3, Zheng Da <zhengda1936@...>:
      > > > > > > >> On 1/3/07, Vissale NEANG <fromtonrouge@...> wrote:
      > > > > > > >> > Hello,
      > > > > > > >> >
      > > > > > > >> > I am the maintainer of the script and I can reproduce the problem:
      > > > > > > >> >
      > > > > > > >> > 1 int main(){
      > > > > > > >> > 2 hello h;
      > > > > > > >> > 3 hello::hello();
      > > > > > > >> > 4 h.
      > > > > > > >> > 5 hello::<C-x><C-o> <--------- the popup menu only appear here
      > > > > > > >> > 6 tmp1 t1;
      > > > > > > >> > 7 t1.
      > > > > > > >> > 8 }
      > > > > > > >> >
      > > > > > > >> > At line 4, the popup menu doesn't appear because of the brace at line
      > > > > > > >> > 1. Internally the script use the vim function "searchdecl" (same
      > > > > > > >> > behaviour as the command "gd") to search the declaration line of your
      > > > > > > >> > object "h". But "gd" works properly only if your brace starts a new
      > > > > > > >> > line because it uses internally the command "[[" (:help gd and :help
      > > > > > > >> > [[). So if you want to see the popup menu at line 4 you have to write
      > > > > > > >> > your code like this :
      > > > > > > >> >
      > > > > > > >> > 1 int main()
      > > > > > > >> > 2 { // This brace must starts the line
      > > > > > > >> > 3 hello h;
      > > > > > > >> > 4 hello::hello();
      > > > > > > >> > 5 h. // The popup menu should appear here
      > > > > > > >> > 6 hello::
      > > > > > > >> > 7 tmp1 t1;
      > > > > > > >> > 8 t1.
      > > > > > > >> > 9 }
      > > > > > > >> >
      > > > > > > >> > At line 8, the popup menu doesn't appear because, after the command
      > > > > > > >> > "gd", the script tokenizes the source code from line 5 to 7 and the
      > > > > > > >> > resulting code in our case is :
      > > > > > > >> >
      > > > > > > >> > h.hello::tmp1 t1;
      > > > > > > >> >
      > > > > > > >> > so the script found that the type of the object "t1" is
      > > > > > > >> > "h.hello::tmp1", this is not correct.
      > > > > > > >> > If you want to see the popup menu you have to, at least, terminate the
      > > > > > > >> > instruction at line 6 with ";"
      > > > > > > >> >
      > > > > > > >> > 1 int main()
      > > > > > > >> > 2 { // This brace must starts the line
      > > > > > > >> > 3 hello h;
      > > > > > > >> > 4 hello::hello();
      > > > > > > >> > 5 h.print(); // The popup menu should appear here
      > > > > > > >> > 6 hello::hello(); // you have to terminate properly your
      > > > > > > >> > // instruction with ";" before the next
      > > > > > > >> declaration
      > > > > > > >> > 7 tmp1 t1;
      > > > > > > >> > 8 t1. // the popup menu should appear here
      > > > > > > >> > 9 }
      > > > > > > >> >
      > > > > > > >> > If you have other questions, I am there :)
      > > > > > > >> >
      > > > > > > >> > Best regards,
      > > > > > > >> >
      > > > > > > >> > Vissale
      > > > > > > >> >
      > > > > > > >> > 2007/1/2, zhengda <zhengda1936@...>:
      > > > > > > >> > > Mikolaj Machowski wrote:
      > > > > > > >> > > > On pon sty 1 2007, Mikolaj Machowski wrote:
      > > > > > > >> > > >
      > > > > > > >> > > >> This won't work: you need a different variable name, see
      > > > > > > >> ":help E706".
      > > > > > > >> > > >>
      > > > > > > >> > > >
      > > > > > > >> > > > Yeah, I forgot (not only about that).
      > > > > > > >> > > >
      > > > > > > >> > > > This is complete solution::
      > > > > > > >> > > >
      > > > > > > >> > > > function! UpdateTags()
      > > > > > > >> > > > call writefile(getline(1, '$'), '.tmp.cc', 'b')
      > > > > > > >> > > > let tags = system('ctags --c++-kinds=+p --fields=+iaS
      > > > > > > >> --extra=+q -f
      > > > > > > >> > > > - .tmp.cc')
      > > > > > > >> > > > " Note: whitespaces around expand are tab chars.
      > > > > > > >> > > > let alltags = system('grep -v " '.expand('%').' "
      > > > > > > >> tags')
      > > > > > > >> > > > let tagstable = split(alltags, '\n')
      > > > > > > >> > > > call add(tagstable, tags)
      > > > > > > >> > > > call writefile(tagstable, 'tags', 'b')
      > > > > > > >> > > > redraw!
      > > > > > > >> > > > return ';'
      > > > > > > >> > > > endfunction
      > > > > > > >> > > > inoremap <expr> ; UpdateTags()
      > > > > > > >> > > >
      > > > > > > >> > > > Note: this is untested in real life, it doesn't return any errors.
      > > > > > > >> > > >
      > > > > > > >> > > > In good conditions execution of whole function takes 0.46s on
      > > > > > > >> big tags
      > > > > > > >> > > > file (KMail source, tags size over 4MB, 10000 lines). Delay
      > > > > > > >> noticeable
      > > > > > > >> > > > on my computer Sempron 2200, 512M RAM, old HD 5400rpm. In worse
      > > > > > > >> conditions
      > > > > > > >> > > > it was taking up to 0.75s::
      > > > > > > >> > > >
      > > > > > > >> > > > FUNCTION UpdateTags()
      > > > > > > >> > > > Called 1 time
      > > > > > > >> > > > Total time: 0.527128
      > > > > > > >> > > > Self time: 0.401542
      > > > > > > >> > > >
      > > > > > > >> > > > count total (s) self (s)
      > > > > > > >> > > > 1 0.000551 call writefile(getline(1,
      > > > > > > >> '$'), '.tmp.cc', 'b')
      > > > > > > >> > > > 1 0.026373 0.000298 let tags = system('ctags
      > > > > > > >> --c++-kinds=+p
      > > > > > > >> > > > --fields=+iaS --extra=+q -f - .tmp.cc')
      > > > > > > >> > > > 1 0.000091 let stags = split(tags,
      > > > > > > >> '\n')
      > > > > > > >> > > > 1 0.130731 0.031220 let alltags =
      > > > > > > >> system('grep -v " '.expand('%').' "
      > > > > > > >> > > > tags')
      > > > > > > >> > > > 1 0.128909 let tagstable =
      > > > > > > >> split(alltags, '\n')
      > > > > > > >> > > > 1 0.000043 call extend(tagstable,
      > > > > > > >> stags)
      > > > > > > >> > > > 1 0.240341 call writefile(tagstable,
      > > > > > > >> 'tags', 'b')
      > > > > > > >> > > > 1 0.000033 return ';'
      > > > > > > >> > > >
      > > > > > > >> > > > FUNCTIONS SORTED ON TOTAL TIME
      > > > > > > >> > > > count total (s) self (s) function
      > > > > > > >> > > > 1 0.527128 0.401542 UpdateTags()
      > > > > > > >> > > >
      > > > > > > >> > > > FUNCTIONS SORTED ON SELF TIME
      > > > > > > >> > > > count total (s) self (s) function
      > > > > > > >> > > > 1 0.527128 0.401542 UpdateTags()
      > > > > > > >> > > >
      > > > > > > >> > > > Note however I've made one fatal mistake. ``ctags fname`` will
      > > > > > > >> point to
      > > > > > > >> > > > tags in file .tmp.cc not our real current file! Filtering tags
      > > > > > > >> in Vim is
      > > > > > > >> > > > possible and on small sample quite fast but still 0.5s is long.
      > > > > > > >> Maybe we
      > > > > > > >> > > > should put that strain to the system::
      > > > > > > >> > > >
      > > > > > > >> > > > function! UpdateTags()
      > > > > > > >> > > > call writefile(getline(1, '$'), '.tmp.cc', 'b')
      > > > > > > >> > > > call system('grep -v " '.expand('%').' " tags >
      > > > > > > >> tags2 && mv -f tags2
      > > > > > > >> > > > tags')
      > > > > > > >> > > > let tags = system('ctags --c++-kinds=+p --fields=+iaS
      > > > > > > >> --extra=+q -f
      > > > > > > >> > > > - .tmp.cc | sed "s/\t\.tmp\.cc\t/\t'.expand('%').'\t/" >> tags')
      > > > > > > >> > > > return ';'
      > > > > > > >> > > > endfunction
      > > > > > > >> > > > inoremap <expr> ; UpdateTags()
      > > > > > > >> > > >
      > > > > > > >> > > > And here we have the winner::
      > > > > > > >> > > >
      > > > > > > >> > > > FUNCTION UpdateTags()
      > > > > > > >> > > > Called 1 time
      > > > > > > >> > > > Total time: 0.145700
      > > > > > > >> > > > Self time: 0.001068
      > > > > > > >> > > >
      > > > > > > >> > > > count total (s) self (s)
      > > > > > > >> > > > 1 0.000523 call writefile(getline(1,
      > > > > > > >> '$'), '.tmp.cc', 'b')
      > > > > > > >> > > > 1 0.096118 0.000195 call system('grep -v "
      > > > > > > >> '.expand('%').' " tags >
      > > > > > > >> > > > tags2 && mv -f tags2 tags')
      > > > > > > >> > > > 1 0.049003 0.000294 call system('ctags
      > > > > > > >> --c++-kinds=+p --fields=+iaS
      > > > > > > >> > > > --extra=+q -f - .tmp.cc | sed
      > > > > > > >> "s/\t\.tmp\.cc\t/\t'.expand('%').'\t/" >>
      > > > > > > >> > > > tags')
      > > > > > > >> > > > 1 0.000029 return ';'
      > > > > > > >> > > >
      > > > > > > >> > > > FUNCTIONS SORTED ON TOTAL TIME
      > > > > > > >> > > > count total (s) self (s) function
      > > > > > > >> > > > 1 0.145700 0.001068 UpdateTags()
      > > > > > > >> > > >
      > > > > > > >> > > > FUNCTIONS SORTED ON SELF TIME
      > > > > > > >> > > > count total (s) self (s) function
      > > > > > > >> > > > 1 0.145700 0.001068 UpdateTags()
      > > > > > > >> > > >
      > > > > > > >> > > >
      > > > > > > >> > > > Below 0.15s (and even in worse conditions only up to 0.25s)!
      > > > > > > >> This is
      > > > > > > >> > > > less then one keystroke of good touchtyper. This is for the
      > > > > > > >> price of
      > > > > > > >> > > > portability but you can find grep/sed/mv for other systems so
      > > > > > > >> situation
      > > > > > > >> > > > isn't hopeless.
      > > > > > > >> > > >
      > > > > > > >> > > > HTH
      > > > > > > >> > > >
      > > > > > > >> > > > m.
      > > > > > > >> > > >
      > > > > > > >> > > >
      > > > > > > >> > > >
      > > > > > > >> > > Thank you for your script. It doesn't work so fast in my computer.
      > > > > > > >> > > There is another problem when I use omnicppcomplete plugin.
      > > > > > > >> > > I don't know if it is its bug.
      > > > > > > >> > > For example, there are two files:
      > > > > > > >> > > --------tmp1.h--------------------
      > > > > > > >> > > class tmp1{
      > > > > > > >> > > public:
      > > > > > > >> > > void print1(){}
      > > > > > > >> > > };
      > > > > > > >> > > --------hello.cc-----------------
      > > > > > > >> > > #include "tmp1.h"
      > > > > > > >> > >
      > > > > > > >> > > class hello{
      > > > > > > >> > > public:
      > > > > > > >> > > void print(){}
      > > > > > > >> > > static void hello(){}
      > > > > > > >> > > static int h;
      > > > > > > >> > > };
      > > > > > > >> > >
      > > > > > > >> > > int main(){
      > > > > > > >> > > hello h;
      > > > > > > >> > > hello::hello();
      > > > > > > >> > > h.
      > > > > > > >> > > hello::<C-x><C-o> <--------- the popup menu only appear here
      > > > > > > >> > > tmp1 t1;
      > > > > > > >> > > t1.
      > > > > > > >> > > }
      > > > > > > >> > >
      > > > > > > >> > > I'm sure tags has been created correctly. The popup menu sometimes
      > > > > > > >> > > appears, sometimes doesn't when I type '.' or '->'.
      > > > > > > >> > > I tried many times, but still didn't find the rule: when it appears,
      > > > > > > >> > > when it doesn't.
      > > > > > > >> > > Does anyone meet the similar program? Or has some ideas?
      > > > > > > >> > >
      > > > > > > >> > > Zheng Da
      > > > > > > >> > >
      > > > > > > >> >
      > > > > > > >>
      > > > > > > >> Thank you for your reply.
      > > > > > > >> It does work in "h." in my case, when I changed the code like
      > > > > > > >> int main()
      > > > > > > >> {
      > > > > > > >> hello h;
      > > > > > > >> hello::hello();
      > > > > > > >> h.
      > > > > > > >> }
      > > > > > > >> But for class tmp1, it still doesn't work. For this code,
      > > > > > > >> ----------tmp1.h--------------
      > > > > > > >> class tmp1
      > > > > > > >> {
      > > > > > > >> public:
      > > > > > > >> void print1(){}
      > > > > > > >> };
      > > > > > > >> ----------hello.cc------------
      > > > > > > >> #include "tmp1.h"
      > > > > > > >>
      > > > > > > >> int main()
      > > > > > > >> {
      > > > > > > >> tmp1 t1;
      > > > > > > >> t1. <-----no popup menu appears
      > > > > > > >> }
      > > > > > > >> It seems it only works for the class in the same file.
      > > > > > > >> If the class is in the header file, it doesn't.
      > > > > > > >>
      > > > > > > >> --
      > > > > > > >> With regards
      > > > > > > >> Zheng Da
      > > > > > > >>
      > > > > > > These are my tags file and code files
      > > > > > >
      > > > > > >
      > > > > > > print1 tmp1.h /^ void print1(){}$/;" f class:tmp1 access:public signature:()
      > > > > > > tmp1 tmp1.h /^class tmp1$/;" c
      > > > > > > tmp1::print1 tmp1.h /^ void print1(){}$/;" f class:tmp1 access:public signature:()
      > > > > > > main test.cpp /^int main()$/;" f signature:()
      > > > > > >
      > > > > > >
      > > > > > >
      > > > > > >
      > > > > >
      > > > >
      > > > > Thank.
      > > > > But there will be a problem if I use the above script to update the tags file.
      > > > > I tried to use sort command, but it still doesn't work.
      > > > > If I have the code file as follow:
      > > > > ---------tmp1.h-----------
      > > > > class tmp1
      > > > > {
      > > > > public:
      > > > > void print1(){}
      > > > > };
      > > > > ---------test.cpp----------
      > > > > #include "tmp1.h"
      > > > >
      > > > > class world{
      > > > > public:
      > > > > void worldprint(){}
      > > > > };
      > > > >
      > > > > int main()
      > > > > {
      > > > > tmp1 t1;
      > > > > t1.
      > > > > }
      > > > >
      > > > > If I use the following function,
      > > > > function! SaveUpdateTags()
      > > > > write
      > > > > call system('grep -v "'.expand('%').'" tags > tags2')
      > > > > let tags = system('ctags --c++-kinds=+p --fields=+iaS --extra=+q -f -
      > > > > '.expand('%').' | sort >> tags2')
      > > > > call system('sort tags2>tags')
      > > > > call system('mv -f tags2 tags')
      > > > > return ''
      > > > > endfunc
      > > > >
      > > > > The tags file will be like this:
      > > > > main test.cpp /^int main()$/;" f signature:()
      > > > > print1 tmp1.h /^ void print1(){}$/;" f class:tmp1
      > > > > access:public signature:()
      > > > > tmp1::print1 tmp1.h /^ void print1(){}$/;" f class:tmp1
      > > > > access:public signature:()
      > > > > tmp1 tmp1.h /^class tmp1$/;" c
      > > > > worldprint test.cpp /^ void worldprint(){}$/;" f class:world
      > > > > access:public signature:()
      > > > > world test.cpp /^class world{$/;" c file:
      > > > > world::worldprint test.cpp /^ void worldprint(){}$/;" f
      > > > > class:world access:public signature:()
      > > > >
      > > > > How do I sort will make
      > > > > worldprint test.cpp /^ void worldprint(){}$/;" f class:world
      > > > > access:public signature:()
      > > > > below
      > > > > world test.cpp /^class world{$/;" c file:
      > > > >
      > > > >
      > > > > --
      > > > > With regards
      > > > > Zheng Da
      > > > >
      > > >
      > >
      > > The function is like this
      > > function! SaveUpdateTags()
      > > write
      > > call system('touch tags')
      > > let othertags=system('grep -v "'.expand('%').'" tags')
      > > let currenttags = system('ctags --c++-kinds=+p --fields=+iaS
      > > --extra=+q -f - '.expand('%').'')
      > > let newtags=split(othertags , "\n")+split(currenttags , "\n")
      > > let sortedtags=sort(newtags)
      > > call delete('tags')
      > > call writefile(newtags , 'tags' , "b")
      > > return ''
      > > endfunc
      > >
      > > It seems to work correctly, but I'm afraid it doesn't run fast for the
      > > big project
      > >
      > > --
      > > With regards
      > > Zheng Da
      > >
      >

      Thank you for your help.
      By the way, how to compile vim with python.
      I run ./configure --enable-pythoninterp
      After I compiled vim and installed it,
      "vim --version|grep python" still shows
      -python +quickfix +reltime -rightleft -ruby +scrollbind +signs +smartindent

      --
      With regards
      Zheng Da
    • Show all 27 messages in this topic