From f5aaad220f5fb65e8ed6988a3bc94e0aef1c8c01 Mon Sep 17 00:00:00 2001 From: capitaomorte Date: Sun, 30 Aug 2009 22:16:44 +0000 Subject: [PATCH] Tweaking the TextMate C snippets --- .../imported/c-mode/#ifndef … #define … #endif.yasnippet | 5 +---- .../Declarations/030 for int loop (fori).yasnippet | 6 +++--- extras/imported/c-mode/fprintf ….yasnippet | 5 ++--- extras/imported/c-mode/once with #ifndef.yasnippet | 9 +++++++++ extras/imported/c-mode/printf .. (printf).yasnippet | 6 +++--- extras/imported/c-mode/snprintf.yasnippet | 5 +++++ .../ruby-mode/Blocks/do |obj| .. end (doo).yasnippet | 4 ++-- .../Blocks/lambda { |args| .. } (lam).yasnippet | 3 ++- .../ruby-mode/Blocks/open yield block ({).yasnippet | 3 ++- .../Insert ERb's <% __ %> or <%= __ %>.yasnippet | 3 ++- 10 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 extras/imported/c-mode/once with #ifndef.yasnippet create mode 100644 extras/imported/c-mode/snprintf.yasnippet diff --git a/extras/imported/c-mode/#ifndef … #define … #endif.yasnippet b/extras/imported/c-mode/#ifndef … #define … #endif.yasnippet index 0e8b498..7e96cd5 100644 --- a/extras/imported/c-mode/#ifndef … #define … #endif.yasnippet +++ b/extras/imported/c-mode/#ifndef … #define … #endif.yasnippet @@ -1,8 +1,5 @@ # -*- mode: snippet -*- # key: def -# contributor: Translated from TextMate Snippet # name: #ifndef … #define … #endif # -- -#ifndef ${1/([A-Za-z0-9_]+).*/$1/} -#define ${1:SYMBOL} ${2:value} -#endif \ No newline at end of file +${1:$(if (string= text "") "" (concat "#ifndef " text "\n"))}#define ${1:SYMBOL} ${2:value}${1:$(if (string= text "") "" (concat "\n#endif "))} diff --git a/extras/imported/c-mode/Declarations/030 for int loop (fori).yasnippet b/extras/imported/c-mode/Declarations/030 for int loop (fori).yasnippet index 78b582f..889673d 100644 --- a/extras/imported/c-mode/Declarations/030 for int loop (fori).yasnippet +++ b/extras/imported/c-mode/Declarations/030 for int loop (fori).yasnippet @@ -1,9 +1,9 @@ # -*- mode: snippet -*- # key: for -# contributor: Translated from TextMate Snippet # name: For Loop +# expand-env: ((yas/wrap-around-region t)) # -- -for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++$2}) +for(size_t ${2:i} = 0; $2 < ${1:count}; ${3:++i$(unless yas/modified-p (concat "++" (yas/field-value 2)))}) { - ${0:/* code */} + $0 } \ No newline at end of file diff --git a/extras/imported/c-mode/fprintf ….yasnippet b/extras/imported/c-mode/fprintf ….yasnippet index 660b78a..6f4740e 100644 --- a/extras/imported/c-mode/fprintf ….yasnippet +++ b/extras/imported/c-mode/fprintf ….yasnippet @@ -1,6 +1,5 @@ # -*- mode: snippet -*- # key: fprintf -# contributor: Translated from TextMate Snippet -# name: fprintf … +# name: fprintf (...) # -- -fprintf(${1:stderr}, "${2:%s}\\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|%%)*(%.)?.*/(?2:\);)/} \ No newline at end of file +fprintf (${1:stderr}, "${2:%s}\\n"${2:$(if (string-match "%[^%]" text) "," "\);")}$3${2:$(if (string-match "%" text) "\);" "")} \ No newline at end of file diff --git a/extras/imported/c-mode/once with #ifndef.yasnippet b/extras/imported/c-mode/once with #ifndef.yasnippet new file mode 100644 index 0000000..3398ea4 --- /dev/null +++ b/extras/imported/c-mode/once with #ifndef.yasnippet @@ -0,0 +1,9 @@ +# key:once +# name : #ifndef XXX; #define XXX; #endif +# -- +#ifndef ${1:_`(upcase (file-name-nondirectory (file-name-sans-extension (or (buffer-file-name) (buffer-name)))))`_H_} +#define $1 + +$0 + +#endif /* $1 */ \ No newline at end of file diff --git a/extras/imported/c-mode/printf .. (printf).yasnippet b/extras/imported/c-mode/printf .. (printf).yasnippet index aa6bd48..556590b 100644 --- a/extras/imported/c-mode/printf .. (printf).yasnippet +++ b/extras/imported/c-mode/printf .. (printf).yasnippet @@ -1,6 +1,6 @@ # -*- mode: snippet -*- # key: printf -# contributor: Translated from TextMate Snippet -# name: printf … +# name: printf (...) # -- -printf("${1:%s}\\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/} \ No newline at end of file +printf ("${1:%s}\\n"${1:$(if (string-match "%[^%]" text) "," "\);") +}$2${1:$(if (string-match "%" text) "\);" "")} diff --git a/extras/imported/c-mode/snprintf.yasnippet b/extras/imported/c-mode/snprintf.yasnippet new file mode 100644 index 0000000..acffafb --- /dev/null +++ b/extras/imported/c-mode/snprintf.yasnippet @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# key: sprintf +# name: s(n)printf … +# -- +s${2:$(if (string= text "") "" "n")}printf (${1:string}${2:$(if (string= text "") "" ",")}${2:size}, "${3:%s}\\n"${3:$(if (string-match "%[^%]" text) "," "\);")}$4${3:$(if (string-match "%" text) "\);" "")} \ No newline at end of file diff --git a/extras/imported/ruby-mode/Blocks/do |obj| .. end (doo).yasnippet b/extras/imported/ruby-mode/Blocks/do |obj| .. end (doo).yasnippet index a401ee6..99b2df4 100644 --- a/extras/imported/ruby-mode/Blocks/do |obj| .. end (doo).yasnippet +++ b/extras/imported/ruby-mode/Blocks/do |obj| .. end (doo).yasnippet @@ -3,6 +3,6 @@ # contributor: Translated from TextMate Snippet # name: Insert do |variable| … end # -- -do${1/(^(?\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1: |)/}${1:variable}${1/(^(?\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1:|)/} - $0 +do ${1:$(if (string= yas/text "") "" "|")}${1:variable}${1:$(if (string= yas/text "") "" "|")} + $0 end \ No newline at end of file diff --git a/extras/imported/ruby-mode/Blocks/lambda { |args| .. } (lam).yasnippet b/extras/imported/ruby-mode/Blocks/lambda { |args| .. } (lam).yasnippet index 142fe16..7931eef 100644 --- a/extras/imported/ruby-mode/Blocks/lambda { |args| .. } (lam).yasnippet +++ b/extras/imported/ruby-mode/Blocks/lambda { |args| .. } (lam).yasnippet @@ -2,5 +2,6 @@ # key: lam # contributor: Translated from TextMate Snippet # name: lambda { |args| .. } +# expand-env: ((yas/wrap-around-region t)) # -- -lambda { ${1/(^(?\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1:|)/}${1:args}${1/(^(?\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1:| )/}$0 } \ No newline at end of file +lambda { ${1:$(if (string= yas/text "") "" "|")}${1:variable}${1:$(if (string= yas/text "") "" "|")} $0 } \ No newline at end of file diff --git a/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet b/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet index e34adba..232e052 100644 --- a/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet +++ b/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet @@ -2,5 +2,6 @@ # key: { # contributor: Translated from TextMate Snippet # name: Insert { |variable| … } +# expand-env: ((yas/wrap-around-region t)) # -- -{ ${1/(^(?\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1:|)/}${1:variable}${1/(^(?\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g)*,?\s*$)|.*/(?1:| )/}${2:`yas/selected-text`} \ No newline at end of file +{ ${1:$(if (string= yas/text "") "" "|")}${1:variable}${1:$(if (string= yas/text "") "" "|")} $0 } \ No newline at end of file diff --git a/extras/imported/ruby-mode/Insert ERb's <% __ %> or <%= __ %>.yasnippet b/extras/imported/ruby-mode/Insert ERb's <% __ %> or <%= __ %>.yasnippet index cbecaf5..aaa9005 100644 --- a/extras/imported/ruby-mode/Insert ERb's <% __ %> or <%= __ %>.yasnippet +++ b/extras/imported/ruby-mode/Insert ERb's <% __ %> or <%= __ %>.yasnippet @@ -2,5 +2,6 @@ # contributor: Translated from TextMate Snippet # name: Insert ERb’s <% .. %> or <%= .. %> # binding: "^>" +# expand-env: ((yas/wrap-around-region t)) # -- -<%= `yas/selected-text`$0 %> \ No newline at end of file +<%= $0 %> \ No newline at end of file