From bc0e5b9301d8f6cbbabfde30cea7bdbe81b64c15 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Mon, 27 Aug 2012 19:03:58 -0700 Subject: [PATCH 01/12] Added myself to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 30c65d9..1063d97 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ +Aaron Broder Adam Folmert Alberto Pose Angel Alonso From 32eef65402161c76bf92b97a17ea644416148070 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Mon, 27 Aug 2012 21:24:47 -0700 Subject: [PATCH 02/12] Finished STL container snippets --- snippets/cpp.snippets | 48 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 52a8c4b..f6c19f5 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -1,10 +1,52 @@ +## STL Collections +# std::array +snippet array + std::array<${1:T}, ${2:N}> ${2};${3} # std::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 snippet map - std::map<${1:key}, ${2:value}> ${3}; - + std::map<${1:Key}, ${2:T}> ${3};${4} +# std::multiset +snippet mset + std::multiset<${1:T}> ${2};${3} +# std::multimap +snippet mmap + std::multimap<${1:Key}, ${2:T}> ${3};${4} +# 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}> ${3};${4} +# 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} # std::cout snippet cout std::cout << ${1} << std::endl; From 3b952e73fad5b5d814d1bff57173c4ad3e9484d1 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 09:33:50 -0700 Subject: [PATCH 03/12] [cpp] Added access modifier snippets. --- snippets/cpp.snippets | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index f6c19f5..09d9998 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -47,6 +47,23 @@ snippet queue # std::priority_queue snippet pqueue std::priority_queue<${1:T}> ${2};${3} +## +## Access Modifiers +# private +snippet pr + private +# protected +snippet po + protected +# public +snippet pu + public +# friend +snippet fr + friend +# mutable +snippet mu + mutable # std::cout snippet cout std::cout << ${1} << std::endl; From 4700702ea54472cc37a42cf66e6798d625dd5415 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 09:41:16 -0700 Subject: [PATCH 04/12] [cpp] Created class section --- snippets/cpp.snippets | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 09d9998..ed7be50 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -64,14 +64,10 @@ snippet fr # mutable snippet mu mutable -# std::cout -snippet cout - std::cout << ${1} << std::endl; -# std::cin -snippet cin - std::cin >> ${1}; +## +## Class # class -snippet class +snippet cl class ${1:`Filename('$1', 'name')`} { public: @@ -81,8 +77,7 @@ snippet class private: ${3:/* data */} }; - -# member function implementations +# member function implementation snippet mfun ${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) { ${5:return}; @@ -92,7 +87,12 @@ snippet ns namespace ${1:`Filename('', 'my')`} { ${2} } /* namespace $1 */ - +# std::cout +snippet cout + std::cout << ${1} << std::endl; +# std::cin +snippet cin + std::cin >> ${1}; # for i loop snippet fori for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { From 6518bba15ff54e61a5196b540219ec498bf999a7 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 09:43:20 -0700 Subject: [PATCH 05/12] [cpp] Created input/output section. --- snippets/cpp.snippets | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index ed7be50..1ccdc51 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -87,12 +87,24 @@ snippet ns namespace ${1:`Filename('', 'my')`} { ${2} } /* namespace $1 */ +## +## Input/Output # std::cout snippet cout std::cout << ${1} << std::endl; # std::cin snippet cin std::cin >> ${1}; +# read file into vector +snippet readfile + std::vector 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} + # for i loop snippet fori for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { @@ -116,13 +128,3 @@ snippet itera ${2:std::cout << *$1 << std::endl;} } -# read file into vector -snippet readfile - std::vector 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} - From 260f24cccc271a551173854ac7fffb208844d669 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 09:44:24 -0700 Subject: [PATCH 06/12] [cpp] Added iteration section. --- snippets/cpp.snippets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 1ccdc51..637b249 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -105,7 +105,9 @@ snippet readfile fclose($2); }${3} -# for i loop +## +## Iteration +# for i snippet fori for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { ${4:/* code */} From 06b2e3a1880a90978516024fcde40cc59870b87d Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 10:34:24 -0700 Subject: [PATCH 07/12] [c] Added 'elif' snippet. --- snippets/c.snippets | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/snippets/c.snippets b/snippets/c.snippets index 38e8d9e..e17d064 100644 --- a/snippets/c.snippets +++ b/snippets/c.snippets @@ -50,6 +50,10 @@ snippet el else { ${1} } +snippet elif + else if (${1:/* condition */}) { + ${2:/* code */} + } # Ternary conditional snippet t ${1:/* condition */} ? ${2:a} : ${3:b} From 5ea5d2893a55d71ac9379351cdae0c107830ae98 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 10:56:17 -0700 Subject: [PATCH 08/12] [cpp] Minor bug fixes Fixed broken sequences on a few STL container snippets. Renamed the access modifier snippets to avoid conflicts. --- snippets/cpp.snippets | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 637b249..b14f3d9 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -1,7 +1,7 @@ ## STL Collections # std::array snippet array - std::array<${1:T}, ${2:N}> ${2};${3} + std::array<${1:T}, ${2:N}> ${3};${4} # std::vector snippet vector std::vector<${1:T}> ${2};${3} @@ -16,7 +16,7 @@ snippet list std::list<${1:T}> ${2};${3} # std::set snippet set - std::set<${1:T}> ${2};{$3} + std::set<${1:T}> ${2};${3} # std::map snippet map std::map<${1:Key}, ${2:T}> ${3};${4} @@ -34,7 +34,7 @@ snippet umap std::unordered_map<${1:Key}, ${2:T}> ${3};${4} # std::unordered_multiset snippet umset - std::unordered_multiset<${1:T}> ${3};${4} + std::unordered_multiset<${1:T}> ${2};${3} # std::unordered_multimap snippet ummap std::unordered_multimap<${1:Key}, ${2:T}> ${3};${4} @@ -50,13 +50,13 @@ snippet pqueue ## ## Access Modifiers # private -snippet pr +snippet pri private # protected -snippet po +snippet pro protected # public -snippet pu +snippet pub public # friend snippet fr From 67c276b85dae8f3a16e7937312847b2c98283188 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 11:22:24 -0700 Subject: [PATCH 09/12] [c/cpp] Added postfix tab stop to most snippets This allows for people to quickly tab to the end of the snippet and continue writing code without having to exit insert mode. --- snippets/c.snippets | 24 ++++++++++++------------ snippets/cpp.snippets | 14 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/snippets/c.snippets b/snippets/c.snippets index e17d064..8169614 100644 --- a/snippets/c.snippets +++ b/snippets/c.snippets @@ -27,11 +27,11 @@ snippet def snippet ifdef #ifdef ${1:FOO} ${2:#define } - #endif + #endif${3} snippet #if #if ${1:FOO} ${2} - #endif + #endif${3} # Header Include-Guard snippet once #ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`} @@ -45,15 +45,15 @@ snippet once snippet if if (${1:/* condition */}) { ${2:/* code */} - } + }${3} snippet el else { ${1} - } + }${2} snippet elif else if (${1:/* condition */}) { ${2:/* code */} - } + }${3} # Ternary conditional snippet t ${1:/* condition */} ? ${2:a} : ${3:b} @@ -61,28 +61,28 @@ snippet t snippet do do { ${2:/* code */} - } while (${1:/* condition */}); + } while (${1:/* condition */});${3} # While Loop snippet wh while (${1:/* condition */}) { ${2:/* code */} - } + }${3} # For Loop snippet for for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) { ${4:/* code */} - } + }${5} # Custom For Loop snippet forr for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { ${5:/* code */} - } + }${6} # Function snippet fun ${1:void} ${2:function_name}(${3}) { ${4:/* code */} - } + }${5} # Function Declaration snippet fund ${1:void} ${2:function_name}(${3});${4} @@ -98,12 +98,12 @@ snippet st snippet tds typedef struct ${2:_$1 }{ ${3:/* data */} - } ${1:`Filename('$1_t', 'name')`}; + } ${1:`Filename('$1_t', 'name')`};${4} # Typdef enum snippet tde typedef enum { ${1:/* data */} - } ${2:foo}; + } ${2:foo};${3} # printf # unfortunately version this isn't as nice as TextMates's, given the lack of a # dynamic `...` diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index b14f3d9..9aea849 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -80,7 +80,7 @@ snippet cl # member function implementation snippet mfun ${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) { - ${5:return}; + ${5:/* code */} } # namespace snippet ns @@ -91,10 +91,10 @@ snippet ns ## Input/Output # std::cout snippet cout - std::cout << ${1} << std::endl; + std::cout << ${1} << std::endl;${2} # std::cin snippet cin - std::cin >> ${1}; + std::cin >> ${1};${2} # read file into vector snippet readfile std::vector v; @@ -111,22 +111,22 @@ snippet readfile snippet fori for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { ${4:/* code */} - } + }${5} # foreach snippet fore for (${1:auto} ${2:i} : ${3:container}) { ${4:/* code */} - } + }${5} # iterator snippet iter for (${1:std::vector}<${2:type}>::${3:const_iterator} ${4:i} = ${5:container}.begin(); $4 != $5.end(); ++$4) { ${6} - } + }${7} # auto iterator snippet itera for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) { ${2:std::cout << *$1 << std::endl;} - } + }${3} From e7d5983bfcd8d0bb4234e7597ac3d97bad938a39 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Tue, 28 Aug 2012 11:41:46 -0700 Subject: [PATCH 10/12] [c] Reorganized to match cpp snippets --- snippets/c.snippets | 75 ++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/snippets/c.snippets b/snippets/c.snippets index 8169614..35c87be 100644 --- a/snippets/c.snippets +++ b/snippets/c.snippets @@ -1,38 +1,45 @@ -# main() +## Main +# main snippet main int main(int argc, const char *argv[]) { ${1} return 0; } +# main(void) snippet mainn int main(void) { ${1} return 0; } +## +## Preprocessor # #include <...> snippet inc #include <${1:stdio}.h>${2} # #include "..." snippet Inc #include "${1:`Filename("$1.h")`}"${2} -# #ifndef ... #define ... #endif -snippet Def +# ifndef...define...endif +snippet ndef #ifndef $1 #define ${1:SYMBOL} ${2:value} #endif${3} +# define snippet def #define +# ifdef...endif snippet ifdef #ifdef ${1:FOO} ${2:#define } #endif${3} +# if snippet #if #if ${1:FOO} ${2} - #endif${3} -# Header Include-Guard + #endif +# header include guard snippet once #ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`} @@ -41,77 +48,89 @@ snippet once ${2} #endif /* end of include guard: $1 */ -# If Condition +## +## Control Statements +# if snippet if if (${1:/* condition */}) { ${2:/* code */} }${3} +# else snippet el else { ${1} - }${2} + }${3} +# else if snippet elif else if (${1:/* condition */}) { ${2:/* code */} }${3} -# Ternary conditional +# ternary snippet t ${1:/* condition */} ? ${2:a} : ${3:b} -# Do While Loop -snippet do - do { - ${2:/* code */} - } while (${1:/* condition */});${3} -# While Loop -snippet wh - while (${1:/* condition */}) { - ${2:/* code */} - }${3} -# For Loop +## +## Loops +# for snippet for for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) { ${4:/* code */} }${5} -# Custom For Loop +# for (custom) snippet forr for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { ${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 ${1:void} ${2:function_name}(${3}) { ${4:/* code */} }${5} -# Function Declaration +# function declaration snippet fund ${1:void} ${2:function_name}(${3});${4} -# Typedef +## +## Types +# typedef snippet td typedef ${1:int} ${2:MyCustomType};${3} -# Struct +# struct snippet st struct ${1:`Filename('$1_t', 'name')`} { ${2:/* data */} }${3: /* optional variable list */};${4} -# Typedef struct +# typedef struct snippet tds typedef struct ${2:_$1 }{ ${3:/* data */} } ${1:`Filename('$1_t', 'name')`};${4} -# Typdef enum +# typedef enum snippet tde typedef enum { ${1:/* data */} } ${2:foo};${3} +## +## Input/Output # printf -# unfortunately version this isn't as nice as TextMates's, given the lack of a -# dynamic `...` snippet pr printf("${1:%s}\n"${2});${3} # fprintf (again, this isn't as nice as TextMate's version, but it works) snippet fpr fprintf(${1:stderr}, "${2:%s}\n"${3});${4} +## +## Miscellaneous # This is kind of convenient snippet . [${1}]${2} From a3e5bbed2bfbb26f35b1446e8130482221fb5227 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Fri, 31 Aug 2012 14:53:39 -0700 Subject: [PATCH 11/12] [cpp] Added C++11 lambda snippets --- snippets/cpp.snippets | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 9aea849..59c7749 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -129,4 +129,13 @@ snippet itera for (auto ${1:i} = $1.begin(); $1 != $1.end(); ++$1) { ${2:std::cout << *$1 << std::endl;} }${3} - +## +## Lambdas +# lamda (one line) +snippet ld + [${1}](${2}){${3:/* code */}}${4} +# lambda (multi-line) +snippet lld + [${1}](${2}){ + ${3:/* code */} + }${4} From 03b7d9e98be5723e26a4b2143d09720dfa8b42b4 Mon Sep 17 00:00:00 2001 From: Aaron Broder Date: Fri, 31 Aug 2012 14:56:09 -0700 Subject: [PATCH 12/12] [cpp] Removed readfile snippet. The snippet doesn't use expected C++ practices for reading files and is more of a Textmate legacy. --- snippets/cpp.snippets | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 59c7749..c3e19fe 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -95,16 +95,6 @@ snippet cout # std::cin snippet cin std::cin >> ${1};${2} -# read file into vector -snippet readfile - std::vector 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} - ## ## Iteration # for i