Hello all,
I'd like to propose two additions to the C bundle.
First, an easy snippet: typedef.
I know I can never remember how typedef works, so I propose this snippet:
typedef ${1:WhatItIs} ${2:NowCallIt}
Second, a modification on an old favorite: the class snippet.
Most of the classes I write are subclasses of something else. Except the class snippet echos my colon and subclass declaration.
Meaning, I end up with class declarations like:
class Customer : public Person { public: Customer : public Person (arguments); virtual ~Customer : public Person ();
private: /* data */ };
(Note the ": public Person" echoed on both the constructor line, and the deconstructor like).
I suggest modifying the class snippet like so:
class ${1:name}${2: : public } $3 { public: ${1:name} (${4:arguments}); virtual ~${1:name} ();
private: ${0:/* data */} };
There are a few things I don't like about this, mainly that if you don't inherit from something you know have to type "'class', tab, delete, tab, arguments. It also might handle multiple inheritance poorly, or protected/private inheritance. Maybe some TextMate snippet wizards (or people with more involved C++ classes than I) can revisit my snippet to make it work better with these cases.
Hope this helps, _Ryan Wilcox
On 22. Dec 2006, at 03:06, Ryan Wilcox wrote:
I'd like to propose two additions to the C bundle.
First, an easy snippet: typedef. [...]
Second, a modification on an old favorite: the class snippet.
Most of the classes I write are subclasses of something else. Except the class snippet echos my colon and subclass declaration. Meaning, I end up with class declarations like: [...]
I just did this checkin:
• add typedef snippet (with tab trigger ‘td’) • change tab trigger for class and struct to ‘cl’ and ‘st’ respectively (semi-consistent with ‘ns’ and ‘td’) • make the class snippet strip potential “ : public base_class” from first placeholder when mirroring it down in the constructor/ destructor name
Since most of the classes I write are not derived classes, I went for the “strip the public bit in the constructor” rather than make a placeholder for the base class (which I would then always have to delete).