Merge pull request #132 from abroder/master
Reworked C/CPP snippets files - reorganized and more feature-complete.
This commit is contained in:
commit
a7b8c5365c
1
AUTHORS
1
AUTHORS
@ -1,3 +1,4 @@
|
|||||||
|
Aaron Broder
|
||||||
Adam Folmert
|
Adam Folmert
|
||||||
Alberto Pose
|
Alberto Pose
|
||||||
Angel Alonso
|
Angel Alonso
|
||||||
|
@ -1,38 +1,45 @@
|
|||||||
# main()
|
## Main
|
||||||
|
# main
|
||||||
snippet main
|
snippet main
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
${1}
|
${1}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
# main(void)
|
||||||
snippet mainn
|
snippet mainn
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
${1}
|
${1}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
##
|
||||||
|
## Preprocessor
|
||||||
# #include <...>
|
# #include <...>
|
||||||
snippet inc
|
snippet inc
|
||||||
#include <${1:stdio}.h>${2}
|
#include <${1:stdio}.h>${2}
|
||||||
# #include "..."
|
# #include "..."
|
||||||
snippet Inc
|
snippet Inc
|
||||||
#include "${1:`Filename("$1.h")`}"${2}
|
#include "${1:`Filename("$1.h")`}"${2}
|
||||||
# #ifndef ... #define ... #endif
|
# ifndef...define...endif
|
||||||
snippet Def
|
snippet ndef
|
||||||
#ifndef $1
|
#ifndef $1
|
||||||
#define ${1:SYMBOL} ${2:value}
|
#define ${1:SYMBOL} ${2:value}
|
||||||
#endif${3}
|
#endif${3}
|
||||||
|
# define
|
||||||
snippet def
|
snippet def
|
||||||
#define
|
#define
|
||||||
|
# ifdef...endif
|
||||||
snippet ifdef
|
snippet ifdef
|
||||||
#ifdef ${1:FOO}
|
#ifdef ${1:FOO}
|
||||||
${2:#define }
|
${2:#define }
|
||||||
#endif
|
#endif${3}
|
||||||
|
# if
|
||||||
snippet #if
|
snippet #if
|
||||||
#if ${1:FOO}
|
#if ${1:FOO}
|
||||||
${2}
|
${2}
|
||||||
#endif
|
#endif
|
||||||
# Header Include-Guard
|
# header include guard
|
||||||
snippet once
|
snippet once
|
||||||
#ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
|
#ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
|
||||||
|
|
||||||
@ -41,73 +48,89 @@ snippet once
|
|||||||
${2}
|
${2}
|
||||||
|
|
||||||
#endif /* end of include guard: $1 */
|
#endif /* end of include guard: $1 */
|
||||||
# If Condition
|
##
|
||||||
|
## Control Statements
|
||||||
|
# if
|
||||||
snippet if
|
snippet if
|
||||||
if (${1:/* condition */}) {
|
if (${1:/* condition */}) {
|
||||||
${2:/* code */}
|
${2:/* code */}
|
||||||
}
|
}${3}
|
||||||
|
# else
|
||||||
snippet el
|
snippet el
|
||||||
else {
|
else {
|
||||||
${1}
|
${1}
|
||||||
}
|
}${3}
|
||||||
# Ternary conditional
|
# else if
|
||||||
|
snippet elif
|
||||||
|
else if (${1:/* condition */}) {
|
||||||
|
${2:/* code */}
|
||||||
|
}${3}
|
||||||
|
# ternary
|
||||||
snippet t
|
snippet t
|
||||||
${1:/* condition */} ? ${2:a} : ${3:b}
|
${1:/* condition */} ? ${2:a} : ${3:b}
|
||||||
# Do While Loop
|
##
|
||||||
snippet do
|
## Loops
|
||||||
do {
|
# for
|
||||||
${2:/* code */}
|
|
||||||
} while (${1:/* condition */});
|
|
||||||
# While Loop
|
|
||||||
snippet wh
|
|
||||||
while (${1:/* condition */}) {
|
|
||||||
${2:/* code */}
|
|
||||||
}
|
|
||||||
# For Loop
|
|
||||||
snippet for
|
snippet for
|
||||||
for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
||||||
${4:/* code */}
|
${4:/* code */}
|
||||||
}
|
}${5}
|
||||||
# Custom For Loop
|
# for (custom)
|
||||||
snippet forr
|
snippet forr
|
||||||
for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
|
for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
|
||||||
${5:/* code */}
|
${5:/* code */}
|
||||||
}
|
}${6}
|
||||||
# Function
|
# while
|
||||||
|
snippet wh
|
||||||
|
while (${1:/* condition */}) {
|
||||||
|
${2:/* code */}
|
||||||
|
}${3}
|
||||||
|
# do... while
|
||||||
|
snippet do
|
||||||
|
do {
|
||||||
|
${2:/* code */}
|
||||||
|
} while (${1:/* condition */});${3}
|
||||||
|
##
|
||||||
|
## Functions
|
||||||
|
# function definition
|
||||||
snippet fun
|
snippet fun
|
||||||
${1:void} ${2:function_name}(${3})
|
${1:void} ${2:function_name}(${3})
|
||||||
{
|
{
|
||||||
${4:/* code */}
|
${4:/* code */}
|
||||||
}
|
}${5}
|
||||||
# Function Declaration
|
# function declaration
|
||||||
snippet fund
|
snippet fund
|
||||||
${1:void} ${2:function_name}(${3});${4}
|
${1:void} ${2:function_name}(${3});${4}
|
||||||
# Typedef
|
##
|
||||||
|
## Types
|
||||||
|
# typedef
|
||||||
snippet td
|
snippet td
|
||||||
typedef ${1:int} ${2:MyCustomType};${3}
|
typedef ${1:int} ${2:MyCustomType};${3}
|
||||||
# Struct
|
# struct
|
||||||
snippet st
|
snippet st
|
||||||
struct ${1:`Filename('$1_t', 'name')`} {
|
struct ${1:`Filename('$1_t', 'name')`} {
|
||||||
${2:/* data */}
|
${2:/* data */}
|
||||||
}${3: /* optional variable list */};${4}
|
}${3: /* optional variable list */};${4}
|
||||||
# Typedef struct
|
# typedef struct
|
||||||
snippet tds
|
snippet tds
|
||||||
typedef struct ${2:_$1 }{
|
typedef struct ${2:_$1 }{
|
||||||
${3:/* data */}
|
${3:/* data */}
|
||||||
} ${1:`Filename('$1_t', 'name')`};
|
} ${1:`Filename('$1_t', 'name')`};${4}
|
||||||
# Typdef enum
|
# typedef enum
|
||||||
snippet tde
|
snippet tde
|
||||||
typedef enum {
|
typedef enum {
|
||||||
${1:/* data */}
|
${1:/* data */}
|
||||||
} ${2:foo};
|
} ${2:foo};${3}
|
||||||
|
##
|
||||||
|
## Input/Output
|
||||||
# printf
|
# printf
|
||||||
# unfortunately version this isn't as nice as TextMates's, given the lack of a
|
|
||||||
# dynamic `...`
|
|
||||||
snippet pr
|
snippet pr
|
||||||
printf("${1:%s}\n"${2});${3}
|
printf("${1:%s}\n"${2});${3}
|
||||||
# fprintf (again, this isn't as nice as TextMate's version, but it works)
|
# fprintf (again, this isn't as nice as TextMate's version, but it works)
|
||||||
snippet fpr
|
snippet fpr
|
||||||
fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
|
fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
|
||||||
|
##
|
||||||
|
## Miscellaneous
|
||||||
# This is kind of convenient
|
# This is kind of convenient
|
||||||
snippet .
|
snippet .
|
||||||
[${1}]${2}
|
[${1}]${2}
|
||||||
|
@ -1,18 +1,73 @@
|
|||||||
|
## STL Collections
|
||||||
|
# std::array
|
||||||
|
snippet array
|
||||||
|
std::array<${1:T}, ${2:N}> ${3};${4}
|
||||||
# std::vector
|
# std::vector
|
||||||
snippet vector
|
snippet vector
|
||||||
std::vector<${1:char}> ${2};
|
std::vector<${1:T}> ${2};${3}
|
||||||
|
# std::deque
|
||||||
|
snippet deque
|
||||||
|
std::deque<${1:T}> ${2};${3}
|
||||||
|
# std::forward_list
|
||||||
|
snippet flist
|
||||||
|
std::forward_list<${1:T}> ${2};${3}
|
||||||
|
# std::list
|
||||||
|
snippet list
|
||||||
|
std::list<${1:T}> ${2};${3}
|
||||||
|
# std::set
|
||||||
|
snippet set
|
||||||
|
std::set<${1:T}> ${2};${3}
|
||||||
# std::map
|
# std::map
|
||||||
snippet map
|
snippet map
|
||||||
std::map<${1:key}, ${2:value}> ${3};
|
std::map<${1:Key}, ${2:T}> ${3};${4}
|
||||||
|
# std::multiset
|
||||||
# std::cout
|
snippet mset
|
||||||
snippet cout
|
std::multiset<${1:T}> ${2};${3}
|
||||||
std::cout << ${1} << std::endl;
|
# std::multimap
|
||||||
# std::cin
|
snippet mmap
|
||||||
snippet cin
|
std::multimap<${1:Key}, ${2:T}> ${3};${4}
|
||||||
std::cin >> ${1};
|
# std::unordered_set
|
||||||
|
snippet uset
|
||||||
|
std::unordered_set<${1:T}> ${2};${3}
|
||||||
|
# std::unordered_map
|
||||||
|
snippet umap
|
||||||
|
std::unordered_map<${1:Key}, ${2:T}> ${3};${4}
|
||||||
|
# std::unordered_multiset
|
||||||
|
snippet umset
|
||||||
|
std::unordered_multiset<${1:T}> ${2};${3}
|
||||||
|
# std::unordered_multimap
|
||||||
|
snippet ummap
|
||||||
|
std::unordered_multimap<${1:Key}, ${2:T}> ${3};${4}
|
||||||
|
# std::stack
|
||||||
|
snippet stack
|
||||||
|
std::stack<${1:T}> ${2};${3}
|
||||||
|
# std::queue
|
||||||
|
snippet queue
|
||||||
|
std::queue<${1:T}> ${2};${3}
|
||||||
|
# std::priority_queue
|
||||||
|
snippet pqueue
|
||||||
|
std::priority_queue<${1:T}> ${2};${3}
|
||||||
|
##
|
||||||
|
## Access Modifiers
|
||||||
|
# private
|
||||||
|
snippet pri
|
||||||
|
private
|
||||||
|
# protected
|
||||||
|
snippet pro
|
||||||
|
protected
|
||||||
|
# public
|
||||||
|
snippet pub
|
||||||
|
public
|
||||||
|
# friend
|
||||||
|
snippet fr
|
||||||
|
friend
|
||||||
|
# mutable
|
||||||
|
snippet mu
|
||||||
|
mutable
|
||||||
|
##
|
||||||
|
## Class
|
||||||
# class
|
# class
|
||||||
snippet class
|
snippet cl
|
||||||
class ${1:`Filename('$1', 'name')`}
|
class ${1:`Filename('$1', 'name')`}
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -22,48 +77,55 @@ snippet class
|
|||||||
private:
|
private:
|
||||||
${3:/* data */}
|
${3:/* data */}
|
||||||
};
|
};
|
||||||
|
# member function implementation
|
||||||
# member function implementations
|
|
||||||
snippet mfun
|
snippet mfun
|
||||||
${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
|
${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
|
||||||
${5:return};
|
${5:/* code */}
|
||||||
}
|
}
|
||||||
# namespace
|
# namespace
|
||||||
snippet ns
|
snippet ns
|
||||||
namespace ${1:`Filename('', 'my')`} {
|
namespace ${1:`Filename('', 'my')`} {
|
||||||
${2}
|
${2}
|
||||||
} /* namespace $1 */
|
} /* namespace $1 */
|
||||||
|
##
|
||||||
# for i loop
|
## Input/Output
|
||||||
|
# std::cout
|
||||||
|
snippet cout
|
||||||
|
std::cout << ${1} << std::endl;${2}
|
||||||
|
# std::cin
|
||||||
|
snippet cin
|
||||||
|
std::cin >> ${1};${2}
|
||||||
|
##
|
||||||
|
## Iteration
|
||||||
|
# for i
|
||||||
snippet fori
|
snippet fori
|
||||||
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
||||||
${4:/* code */}
|
${4:/* code */}
|
||||||
}
|
}${5}
|
||||||
|
|
||||||
# foreach
|
# foreach
|
||||||
snippet fore
|
snippet fore
|
||||||
for (${1:auto} ${2:i} : ${3:container}) {
|
for (${1:auto} ${2:i} : ${3:container}) {
|
||||||
${4:/* code */}
|
${4:/* code */}
|
||||||
}
|
}${5}
|
||||||
# iterator
|
# iterator
|
||||||
snippet iter
|
snippet iter
|
||||||
for (${1:std::vector}<${2:type}>::${3:const_iterator} ${4:i} = ${5:container}.begin(); $4 != $5.end(); ++$4) {
|
for (${1:std::vector}<${2:type}>::${3:const_iterator} ${4:i} = ${5:container}.begin(); $4 != $5.end(); ++$4) {
|
||||||
${6}
|
${6}
|
||||||
}
|
}${7}
|
||||||
|
|
||||||
# auto iterator
|
# auto iterator
|
||||||
snippet itera
|
snippet itera
|
||||||
for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) {
|
for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) {
|
||||||
${2:std::cout << *$1 << std::endl;}
|
${2:std::cout << *$1 << std::endl;}
|
||||||
}
|
|
||||||
|
|
||||||
# read file into vector
|
|
||||||
snippet readfile
|
|
||||||
std::vector<char> v;
|
|
||||||
if (FILE *${2:fp} = fopen(${1:"filename"}, "r")) {
|
|
||||||
char buf[1024];
|
|
||||||
while (size_t len = fread(buf, 1, sizeof(buf), $2))
|
|
||||||
v.insert(v.end(), buf, buf + len);
|
|
||||||
fclose($2);
|
|
||||||
}${3}
|
}${3}
|
||||||
|
##
|
||||||
|
## Lambdas
|
||||||
|
# lamda (one line)
|
||||||
|
snippet ld
|
||||||
|
[${1}](${2}){${3:/* code */}}${4}
|
||||||
|
# lambda (multi-line)
|
||||||
|
snippet lld
|
||||||
|
[${1}](${2}){
|
||||||
|
${3:/* code */}
|
||||||
|
}${4}
|
||||||
|
Loading…
Reference in New Issue
Block a user