diff options
author | Ratakor <ratakor@disroot.org> | 2023-06-07 16:14:26 +0200 |
---|---|---|
committer | Ratakor <ratakor@disroot.org> | 2023-06-07 16:14:26 +0200 |
commit | a0085af24cc8591daffdc210448f5703b2fd1c2a (patch) | |
tree | 39615ab920cabe05722d6c4e46d95fb7e8172cd6 | |
parent | a3302c407a7fd46d19b2ee92854c7411a0fb2b7c (diff) |
Add zig snippets and update C snippets
-rw-r--r-- | snippets/c.snippets | 204 | ||||
-rw-r--r-- | snippets/zig.snippets | 44 |
2 files changed, 83 insertions, 165 deletions
diff --git a/snippets/c.snippets b/snippets/c.snippets index eeea378..805d31a 100644 --- a/snippets/c.snippets +++ b/snippets/c.snippets @@ -13,7 +13,7 @@ snippet mainn { ${0} } -## + ## Preprocessor # #include <...> snippet #inc @@ -52,7 +52,7 @@ snippet once ${0} - #endif /* end of include guard: $1 */ + #endif /* $1 */ # Disable C++ name mangling in C headers snippet nocxx #ifdef __cplusplus @@ -64,15 +64,15 @@ snippet nocxx #ifdef __cplusplus } /* extern "C" */ #endif -## + ## Control Statements # if snippet if - if (${1:true}) { + if (${1:1}) { ${0:${VISUAL}} } snippet ife - if (${1:true}) { + if (${1:1}) { ${2:${VISUAL}} } else { ${0} @@ -84,14 +84,14 @@ snippet el } # else if snippet elif - else if (${1:true}) { + else if (${1:1}) { ${0:${VISUAL}} } # ifi snippet ifi - if (${1:true}) ${0}; + if (${1:1}) ${0}; # ternary -snippet t Ternary: `condition ? true : false` +snippet t Ternary: `condition ? 1 : 0` $1 ? $2 : $0 # switch snippet switch @@ -118,16 +118,16 @@ snippet ret return ${0}; snippet ex exit($0); -## + ## Loops # for snippet for - for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { + for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) { ${4} } # for (custom) snippet forr - for (int ${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { + for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { ${5} } # while @@ -135,17 +135,16 @@ snippet wh while (${1:1}) { ${0:${VISUAL}} } -snippet wht - while (true) { - ${0:${VISUAL}} - } # do... while snippet do do { ${0:${VISUAL}} - } while ($1); -## + } while (${1:1}); + ## Functions +# function declaration +snippet fund + ${1:void} ${2:function_name}(${3:void}); # function definition snippet fun ${1:void} @@ -153,137 +152,67 @@ snippet fun { ${4} } -# function definition with zero parameters -snippet fun0 - ${1:void} - ${2:function_name}(void) - { - ${3} - } -# function definition with Doxygen documentation -snippet dfun0 - /*! \brief ${1:Brief function description here} +# function definition with one parameter with Doxygen documentation +snippet funD + /** + * @brief ${1:Brief function description here} * * ${2:Detailed description of the function} * - * \return ${3:Return parameter description} - */ - ${4:void} - ${5:function_name}(${6:void}) - { - ${7} - } -# function definition with one parameter -snippet fun1 - ${1:void} - ${2:function_name}(${3:Type} ${4:Parameter}) - { - ${5} - } -# function definition with one parameter with Doxygen documentation -snippet dfun1 - /*! \brief ${1:Brief function description here} - * - * ${2:Detailed description of the function} - * - * \param $3 ${4:Parameter description} - * \return ${5:Return parameter description} + * @param $3 ${4:Parameter description} + * @return ${5:Return parameter description} */ ${6:void} ${7:function_name}(${8:Type} ${3:Parameter}) { ${9} } -# function definition with two parameters -snippet fun2 - ${1:void} - ${2:function_name}(${3:Type} ${4:Parameter}, ${5:Type} ${6:Parameter}) - { - ${7} - } -# function definition with two parameters with Doxygen documentation -snippet dfun2 - /*! \brief ${1:Brief function description here} - * - * ${2:Detailed description of the function} - * - * \param $3 ${4:Parameter description} - * \param $5 ${6:Parameter description} - * \return ${7:Return parameter description} - */ - ${8:void} - ${9:function_name}(${10:Type} ${3:Parameter}, ${11:Type} ${5:Parameter}) - { - ${12} - } -# function definition with three parameters -snippet fun3 - ${1:void} - ${2:function_name}(${3:Type} ${4:Parameter}, ${5:Type} ${6:Parameter}, ${7:Type} ${8:Parameter}) - { - ${9} - } -# function definition with three parameters with Doxygen documentation -snippet dfun3 - /*! \brief ${1:Brief function description here} - * - * ${2:Detailed description of the function} - * - * \param $3 ${4:Parameter description} - * \param $5 ${6:Parameter description} - * \param $7 ${8:Parameter description} - * \return ${9:Return parameter description} - */ - ${10:void} - ${11:function_name}(${12:Type} ${3:Parameter}, ${13:Type} ${5:Parameter}, ${14:Type} ${7:Parameter}) - { - ${15} - } -# function declaration -snippet fund - ${1:void} ${2:function_name}(${3:void}); -## + ## Types # typedef snippet td typedef ${1:int} ${2:MyCustomType}; # struct snippet st - /*! \struct $1 - * \brief ${3:Brief struct description} + /** + * @struct $1 + * @brief ${3:Brief struct description} * - * ${4:Detailed description} + * ${4:Detailed description} */ struct ${1:`vim_snippets#Filename('$1_t', 'name')`} { ${2:Data} /*!< ${4:Description} */ }${5: /* optional variable list */}; # typedef struct snippet tds - /*! \struct $2 - * \brief ${5:Brief struct description} + /** + * @struct $2 + * @brief ${5:Brief struct description} * - * ${6:Detailed description} + * ${6:Detailed description} */ typedef struct ${2:_$1 }{ m_${3:Data} /*!< ${4:Description} */ } ${1:`vim_snippets#Filename('$1_t', 'name')`}; snippet enum - /*! \enum $1 + /** + * @enum $1 * - * ${2:Detailed description} + * ${2:Detailed description} */ enum ${1:name} { ${0} }; # typedef enum snippet tde - /*! \enum $2 + /** + * @enum $2 * - * ${4:Detailed description} + * ${4:Detailed description} */ typedef enum { ${1:Data} /*!< ${3:Description} */ } ${2:foo}; -## + ## Input/Output # printf snippet pr @@ -305,64 +234,9 @@ snippet err err(${1:1}, "${2:%s}"$0); snippet errx errx(${1:1}, "${2:%s}"$0); -# getopt -snippet getopt - int choice; - while (1) { - static struct option long_options[] = - { - /* Use flags like so: - {"verbose", no_argument, &verbose_flag, 'V'} - Argument styles: no_arg, required_arg, optional_arg */ - {"version", no_argument, 0, 'v'}, - {"help", no_argument, 0, 'h'}, - ${1} - {0,0,0,0} - }; - - int option_index = 0; - - /* Argument parameters: - no_argument: " " - required_argument: ":" - optional_argument: "::" */ - - choice = getopt_long( argc, argv, "vh", - long_options, &option_index); - - if (choice == -1) - break; - - switch(choice) { - case 'v': - ${2} - break; - - case 'h': - ${3} - break; - - case '?': - /* getopt_long will have already printed an error */ - break; - - default: - /* Not sure how to get here... */ - return EXIT_FAILURE; - } - } - - /* Deal with non-option arguments here */ - if (optind < argc) { - while (optind < argc) { - ${0} - } - } - ## Assertions snippet asr assert($1); - snippet anl assert(${1:ptr} != NULL); @@ -385,7 +259,7 @@ snippet clcd snippet fre free(${1:ptr}); -## + # TODO section snippet todo /*! TODO: ${1:Todo description here} diff --git a/snippets/zig.snippets b/snippets/zig.snippets new file mode 100644 index 0000000..b604601 --- /dev/null +++ b/snippets/zig.snippets @@ -0,0 +1,44 @@ +snippet import + const ${1:std} = @import("${1:std}"); + ${0} +snippet main + pub fn main() void { + ${0} + } +snippet if + if (${1:true}) { + ${0}} + } +snippet ife + if (${1:true}) { + ${2}} + } else { + ${0} + } +snippet el + else { + ${0}} + } +snippet elif + else if (${1:true}) { + ${0}} + } +snippet switch + switch (${1:var}) { + ${0} + } +snippet ret + return ${0}; +#snippet for +# for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) { +# ${4} +# } +## for (custom) +#snippet forr +# for (int ${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) { +# ${5} +# } +snippet wh + while (${1:true}) { + ${0}} + } |