Vim c++ generate source file based on header file
Asked Answered
P

2

9

I do a lot of c++ programming in vim and I was wondering if there are any plugins or snippets out there that can generate a source file depending on the contents of the header file.

I.E: test.h

class test {
public:
  test();
};

and then going into the test.cpp file and typing "src" and expanding it (using some sort of snippet plugin like UltiSnips) it would look in the test.h file for the funcions and (in this case) make:

test::test() {
  //code
}

I got this idea from Derek Wyatt's blog and he does this using XPTemplate so I thought it would be great to do the same in UltiSnips.

Presidium answered 15/8, 2013 at 2:35 Comment(1)
I don't know of any such a plugin.Fonzie
P
1

Use the xptemplate plugin.

Examples:
http://www.derekwyatt.org/wp-content/uploads/2009/08/my.cpp.xpt.vim http://www.derekwyatt.org/vim/working-with-vim-and-cpp/cpp-snippets

Partiality answered 16/8, 2013 at 3:51 Comment(2)
Isn't this exactly what the OP already mentioned in his question?Bolick
Yes I had mentioned this and I thought about just using XPTemplates with his plugin but I would have preferred using UltiSnips or maybe an actual plugin. But I think I'm going to try using XPTemplates and UltiSnips but only use XPTemplates for Derek Wyatt's snippet.Presidium
S
1

lh-cpp offers a :GOTOIMPL function that analyses the prototype of a given function, and either jumps to the associated definition or generates it on-the-fly. [NB: it knows what to do with virtual, static, namespace/embedded classes, return type, modifiers, and so on (except templates yet)]

Regarding how to parse a header file and generate all associated functions, the exact same question has been asked on vim mailing list 2-3 weeks ago where another solution has been given (protodef, that you have read about).

Spatula answered 16/8, 2013 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.