11priority -50
22
3+ # ###########
4+ # COMMON #
5+ # ###########
6+
7+ # The smart snippets use a global options called
8+ # "g:ultisnips_javascript.{option}" which can control the format
9+ # of trailing semicolon, space before function paren, etc.
10+
11+ global !p
12+ from javascript_snippets import (
13+ semi, space_before_function_paren
14+ )
15+ endglobal
16+
317# ##########################################################################
418# TextMate Snippets #
519# ##########################################################################
@@ -8,13 +22,13 @@ getElement${1/(T)|.*/(?1:s)/}By${1:T}${1/(T)|(I)|.*/(?1:agName)(?2:d)/}('$2')
822endsnippet
923
1024snippet '':f " object method string"
11- '${1: ${2: #thing } :${3: click } } ': function(element) {
25+ '${1: ${2: #thing } :${3: click } } ': function` !p snip.rv = space_before_function_paren(snip) ` (element) {
1226 ${VISUAL}$0
1327}${10: , }
1428endsnippet
1529
1630snippet :f " Object Method"
17- ${1: method_name } : function(${3: attribute } ) {
31+ ${1: method_name } : function` !p snip.rv = space_before_function_paren(snip) ` (${3: attribute } ) {
1832 ${VISUAL}$0
1933}${10: , }
2034endsnippet
@@ -28,40 +42,46 @@ ${1:key}: ${2:"${3:value}"}${4:, }
2842endsnippet
2943
3044snippet proto " Prototype (proto)"
31- ${1: class_name } .prototype.${2: method_name } = function(${3: first_argument } ) {
45+ ${1: class_name } .prototype.${2: method_name } = function` !p snip.rv = space_before_function_paren(snip) ` (${3: first_argument } ) {
3246 ${VISUAL}$0
33- };
47+ }` !p snip.rv = semi(snip) `
3448
3549endsnippet
3650
3751snippet fun " function (fun)" w
38- function ${1: function_name } (${2: argument } ) {
52+ function ${1: function_name } ` !p snip.rv = space_before_function_paren(snip) ` (${2: argument } ) {
3953 ${VISUAL}$0
4054}
4155endsnippet
4256
4357snippet vf " Function assigned to var"
44- ${1: var }${2: function_name } = function $2 ($3 ) {
58+ ${1: var }${2: function_name } = function $2 ` !p snip.rv = space_before_function_paren(snip) ` ($3 ) {
4559 ${VISUAL}$0
46- };
60+ }` !p snip.rv = semi(snip) `
4761endsnippet
4862
4963snippet af " Anonymous Function" i
50- function($1 ) {
64+ function` !p snip.rv = space_before_function_paren(snip) ` ($1 ) {
5165 ${VISUAL}$0
5266}
5367endsnippet
5468
5569snippet iife " Immediately-Invoked Function Expression (iife)"
56- (function(${1: window } ) {
70+ (function` !p snip.rv = space_before_function_paren(snip) ` (${1: window } ) {
5771 ${VISUAL}$0
58- }(${2: $1 } ));
72+ }(${2: $1 } ))`!p snip.rv = semi(snip) `
73+ endsnippet
74+
75+ snippet ;fe " Minify safe iife"
76+ ;(function`!p snip.rv = space_before_function_paren(snip) ` (${1} ) {
77+ ${VISUAL}$0
78+ }(${2} ))
5979endsnippet
6080
6181snippet timeout " setTimeout function"
62- setTimeout(function() {
82+ setTimeout(function` !p snip.rv = space_before_function_paren(snip) ` () {
6383 ${VISUAL}$0
64- }${2: .bind(${3: this } ) } , ${1: 10 } );
84+ }${2: .bind(${3: this } ) } , ${1: 10 } )` !p snip.rv = semi(snip) `
6585endsnippet
6686
6787snippet fi " for prop in obj using hasOwnProperty" b
@@ -72,4 +92,49 @@ for (${1:prop} in ${2:obj}){
7292}
7393endsnippet
7494
95+ snippet if " if (condition) { ... }"
96+ if (${1: true } ) {
97+ ${VISUAL}$0
98+ }
99+ endsnippet
100+
101+ snippet ife " if (condition) { ... } else { ... }"
102+ if (${1: true } ) {
103+ ${VISUAL}$0
104+ } else {
105+ ${2}
106+ }
107+ endsnippet
108+
109+ snippet switch
110+ switch (${VISUAL}${1: expression } ) {
111+ case '${VISUAL}${3: case } ':
112+ ${4}
113+ break`!p snip.rv = semi(snip) `
114+ ${0}
115+ default:
116+ ${2}
117+ }
118+ endsnippet
119+
120+ snippet case " case 'xyz': ... break"
121+ case '${VISUAL}${1: case } ':
122+ ${VISUAL}$0
123+ break`!p snip.rv = semi(snip) `
124+ endsnippet
125+
126+ snippet do " do { ... } while (condition)"
127+ do {
128+ ${VISUAL}$0
129+ } while (${1: /* condition */ } )`!p snip.rv = semi(snip) `
130+ endsnippet
131+
132+ snippet ret " Return statement"
133+ return ${VISUAL}$0 `!p snip.rv = semi(snip) `
134+ endsnippet
135+
136+ snippet us
137+ 'use strict'`!p snip.rv = semi(snip) `
138+ endsnippet
139+
75140# vim:ft=snippets:
0 commit comments