-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. update some code block snippet for C. 2. add some code snippets for CPP.
- Loading branch information
Showing
3 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
priority -50 | ||
|
||
extends c | ||
|
||
# We want to overwrite everything in parent ft. | ||
priority -48 | ||
########################################################################### | ||
# Global functions # | ||
########################################################################### | ||
|
||
global !p | ||
def write_docstring_args(arglist, snip): | ||
args = str(arglist).split(',') | ||
if len(args) > 1: | ||
c = 0 | ||
for arg in args: | ||
if c == 0: | ||
snip.rv += arg | ||
c = 1 | ||
else: | ||
snip += '* : %s' % arg.strip() | ||
else: | ||
snip.rv = args[0] | ||
endglobal | ||
|
||
########################################################################### | ||
# TextMate Snippets # | ||
########################################################################### | ||
snippet beginend "$1.begin(), $1.end() (beginend)" | ||
${1:v}${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}begin(), $1${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}end() | ||
endsnippet | ||
|
||
snippet cl "class .. (class)" | ||
class ${1:`!p snip.rv = snip.basename or "name"`} | ||
{ | ||
public: | ||
${1/(\w+).*/$1/} (${2:arguments}); | ||
virtual ~${1/(\w+).*/$1/} (); | ||
|
||
private: | ||
${0:/* data */} | ||
}; | ||
endsnippet | ||
|
||
snippet ns "namespace .. (namespace)" | ||
namespace${1/.+/ /m}${1:`!p snip.rv = snip.basename or "name"`} | ||
{ | ||
${VISUAL}$0 | ||
}${1/.+/ \/* /m}$1${1/.+/ *\/ /m} | ||
endsnippet | ||
|
||
snippet readfile "read file (readF)" | ||
vector<char> v; | ||
if (FILE *fp = fopen(${1:"filename"}, "r")) | ||
{ | ||
char buf[1024]; | ||
while(size_t len = fread(buf, 1, sizeof(buf), fp)) | ||
v.insert(v.end(), buf, buf + len); | ||
fclose(fp); | ||
} | ||
endsnippet | ||
|
||
snippet map "map (map)" | ||
map<${1:key}, ${2:value}> map$0; | ||
endsnippet | ||
|
||
snippet vector "vector (v)" | ||
vector<${1:char}> v$0; | ||
endsnippet | ||
|
||
snippet vector "vector (v)" | ||
vector<${1:char}> v$0; | ||
endsnippet | ||
|
||
snippet list "list (v)" | ||
list<${1:char}> v$0; | ||
endsnippet | ||
|
||
snippet set "set (v)" | ||
set<${1:char}> v$0; | ||
endsnippet | ||
|
||
snippet tp "template <typename ..> (template)" | ||
template <typename ${1:_InputIter}> | ||
endsnippet | ||
|
||
snippet cla "An entire .h generator" b | ||
#ifndef ${2:`!v substitute(vim_snippets#Filename('$1_H','ClassName'),'.*','\U&\E','')`} | ||
#define $2 | ||
|
||
class ${1:`!v substitute(substitute(vim_snippets#Filename('$1','ClassName'),'^.','\u&',''), '_\(\w\)', '\u\1', 'g')`} | ||
{ | ||
private: | ||
$3 | ||
|
||
public: | ||
$1(); | ||
virtual ~$1(); | ||
}; | ||
|
||
#endif /* $2 */ | ||
endsnippet | ||
|
||
|
||
snippet fnc "Basic c++ doxygen function template" b | ||
/** | ||
* @brief: ${4:brief} | ||
* | ||
* @param: `!p write_docstring_args(t[3],snip)` | ||
* | ||
* @return: `!p snip.rv = t[1]` | ||
*/ | ||
${1:ReturnType} ${2:FunctionName}(${3:param}) | ||
{ | ||
${0:FunctionBody} | ||
} | ||
endsnippet | ||
# vim:ft=snippets: |