c.snippets 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # main()
  2. snippet main
  3. int main(int argc, const char *argv[])
  4. {
  5. ${1}
  6. return 0;
  7. }
  8. snippet mainn
  9. int main(void)
  10. {
  11. ${1}
  12. return 0;
  13. }
  14. # #include <...>
  15. snippet inc
  16. #include <${1:stdio}.h>${2}
  17. # #include "..."
  18. snippet Inc
  19. #include "${1:`Filename("$1.h")`}"${2}
  20. # #ifndef ... #define ... #endif
  21. snippet Def
  22. #ifndef $1
  23. #define ${1:SYMBOL} ${2:value}
  24. #endif${3}
  25. snippet def
  26. #define
  27. snippet ifdef
  28. #ifdef ${1:FOO}
  29. ${2:#define }
  30. #endif
  31. snippet #if
  32. #if ${1:FOO}
  33. ${2}
  34. #endif
  35. # Header Include-Guard
  36. snippet once
  37. #ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
  38. #define $1
  39. ${2}
  40. #endif /* end of include guard: $1 */
  41. # If Condition
  42. snippet if
  43. if (${1:/* condition */}) {
  44. ${2:/* code */}
  45. }
  46. snippet el
  47. else {
  48. ${1}
  49. }
  50. # Ternary conditional
  51. snippet t
  52. ${1:/* condition */} ? ${2:a} : ${3:b}
  53. # Do While Loop
  54. snippet do
  55. do {
  56. ${2:/* code */}
  57. } while (${1:/* condition */});
  58. # While Loop
  59. snippet wh
  60. while (${1:/* condition */}) {
  61. ${2:/* code */}
  62. }
  63. # For Loop
  64. snippet for
  65. for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
  66. ${4:/* code */}
  67. }
  68. # Custom For Loop
  69. snippet forr
  70. for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
  71. ${5:/* code */}
  72. }
  73. # Function
  74. snippet fun
  75. ${1:void} ${2:function_name}(${3})
  76. {
  77. ${4:/* code */}
  78. }
  79. # Function Declaration
  80. snippet fund
  81. ${1:void} ${2:function_name}(${3});${4}
  82. # Typedef
  83. snippet td
  84. typedef ${1:int} ${2:MyCustomType};${3}
  85. # Struct
  86. snippet st
  87. struct ${1:`Filename('$1_t', 'name')`} {
  88. ${2:/* data */}
  89. }${3: /* optional variable list */};${4}
  90. # Typedef struct
  91. snippet tds
  92. typedef struct ${2:_$1 }{
  93. ${3:/* data */}
  94. } ${1:`Filename('$1_t', 'name')`};
  95. # Typdef enum
  96. snippet tde
  97. typedef enum {
  98. ${1:/* data */}
  99. } ${2:foo};
  100. # printf
  101. # unfortunately version this isn't as nice as TextMates's, given the lack of a
  102. # dynamic `...`
  103. snippet pr
  104. printf("${1:%s}\n"${2});${3}
  105. # fprintf (again, this isn't as nice as TextMate's version, but it works)
  106. snippet fpr
  107. fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
  108. # This is kind of convenient
  109. snippet .
  110. [${1}]${2}