From 20c12eda3a79032e9fc24b3f8d43f11ca10d67c3 Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Sun, 29 Dec 2013 22:03:34 +0000 Subject: [PATCH 01/35] Added if snippets and update of coding style to most common --- UltiSnips/c.snippets | 47 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index e0cc7fd..2a346ce 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -18,12 +18,12 @@ ${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}} #endif endsnippet -snippet inc "#include local header (inc)" -#include "${1:`!p snip.rv = snip.basename + '.h'`}" +snippet #inc "#include <> (Inc)" +#include <${1:.h}> endsnippet -snippet Inc "#include <> (Inc)" -#include <${1:.h}> +snippet #Inc "#include local header (inc)" +#include "${1:`!p snip.rv = snip.basename + '.h'`}" endsnippet snippet mark "#pragma mark (mark)" @@ -44,15 +44,13 @@ int main(int argc, char *argv[]) endsnippet snippet for "for loop (for)" -for (${2:i} = 0; $2 < ${1:count}; ${3:++$2}) -{ +for (${2:i} = 0; $2 < ${1:count}; ${3:++$2}){ ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet -snippet fori "for int loop (fori)" -for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}) -{ +snippet fori "for int loop (with declaration)" +for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}){ ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet @@ -99,26 +97,35 @@ fprintf(${1:stderr}, "${2:%s}\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|% endsnippet snippet if "if .. (if)" -if (${1:/* condition */}) -{ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +if (${1:/* condition */}){ + ${0:/* code */} } endsnippet snippet el "else .. (else)" else { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${0:/* code */} } endsnippet -snippet ife "if .. else (ife)" -if (${1:/* condition */}) -{ - ${2:/* code */} +snippet eli "else if .. (else if)" +else if (${1:/* condition */}) { + ${0:/* code */} } -else -{ - ${3:/* else */} +endsnippet + +snippet ifeli "if..else.if .. (ifeli)" +if (${1:/* condition */}) { + ${2:/* code */} +} else if (${3:/* condition */}) { + ${0:/* code */} +} + +snippet ife "if .. else (ife)" +if (${1:/* condition */}){ + ${2:/* code */} +} else{ + ${0:/* else */} } endsnippet From bc5e3bdb45dc3e9037edc0187ef355b125bbaded Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Tue, 31 Dec 2013 18:28:07 +0000 Subject: [PATCH 02/35] Added if snippets following general snippet style and triggers --- UltiSnips/c.snippets | 82 ++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index 2a346ce..7b40728 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -18,12 +18,12 @@ ${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}} #endif endsnippet -snippet #inc "#include <> (Inc)" -#include <${1:.h}> +snippet inc "#include local header (inc)" +#include "${1:`!p snip.rv = snip.basename + '.h'`}" endsnippet -snippet #Inc "#include local header (inc)" -#include "${1:`!p snip.rv = snip.basename + '.h'`}" +snippet Inc "#include <> (Inc)" +#include <${1:.h}> endsnippet snippet mark "#pragma mark (mark)" @@ -38,20 +38,22 @@ endsnippet snippet main "main() (main)" int main(int argc, char *argv[]) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} - return 0; + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + return 0; } endsnippet snippet for "for loop (for)" -for (${2:i} = 0; $2 < ${1:count}; ${3:++$2}){ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +for (${2:i} = 0; $2 < ${1:count}; ${3:++$2}) +{ + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet -snippet fori "for int loop (with declaration)" -for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}){ - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +snippet fori "for int loop (fori)" +for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}) +{ + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet @@ -62,10 +64,10 @@ endsnippet snippet once "Include header once only guard" #ifndef ${1:`!p if not snip.c: - import random, string - name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper() - rand = ''.join(random.sample(string.ascii_letters+string.digits, 8)) - snip.rv = ('%s_%s' % (name,rand)).upper() + import random, string + name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper() + rand = ''.join(random.sample(string.ascii_letters+string.digits, 8)) + snip.rv = ('%s_%s' % (name,rand)).upper() else: snip.rv = snip.c`} #define $1 @@ -82,13 +84,13 @@ endsnippet snippet wh "while loop" while(${1:/* condition */}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet snippet do "do...while loop (do)" do { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } while(${1:/* condition */}); endsnippet @@ -97,35 +99,47 @@ fprintf(${1:stderr}, "${2:%s}\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|% endsnippet snippet if "if .. (if)" -if (${1:/* condition */}){ - ${0:/* code */} +if (${1:/* condition */}) +{ + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet snippet el "else .. (else)" else { - ${0:/* code */} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet -snippet eli "else if .. (else if)" +snippet eli "else if .. (eli)" else if (${1:/* condition */}) { - ${0:/* code */} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet -snippet ifeli "if..else.if .. (ifeli)" -if (${1:/* condition */}) { - ${2:/* code */} -} else if (${3:/* condition */}) { - ${0:/* code */} -} - snippet ife "if .. else (ife)" -if (${1:/* condition */}){ +if (${1:/* condition */}) +{ + ${2:/* code */} +} +else +{ + ${3:/* else */} +} +endsnippet + +snippet ifee "if .. else if .. else (ifee)" +if (${1:/* condition */}) +{ ${2:/* code */} -} else{ - ${0:/* else */} +} +else if (${3:/* condition */}) +{ + ${4:/* code */} +} +else +{ + ${5:/* code */} } endsnippet @@ -136,14 +150,14 @@ endsnippet snippet st "struct" struct ${1:`!p snip.rv = (snip.basename or "name") + "_t"`} { - ${0:/* data */} + ${0:/* data */} }; endsnippet snippet fun "function" b ${1:void} ${2:function_name}(${3}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet From ccbefbc209e20ec6d4006d3e7d61e26748b9d11b Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Fri, 3 Jan 2014 23:08:29 -0800 Subject: [PATCH 03/35] Fixed search order detection for symlinked vim dir --- plugin/UltiSnips/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 2caf000..bfcf5bc 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -32,18 +32,19 @@ def _snippets_dir_is_before_plugin_dir(): """ Returns True if the snippets directory comes before the plugin directory in Vim's runtime path. False otherwise. """ - paths = [ os.path.expanduser(p).rstrip(os.path.sep) + paths = [ os.path.realpath(os.path.expanduser(p)).rstrip(os.path.sep) for p in _vim.eval("&runtimepath").split(',') ] home = _vim.eval("$HOME") def vim_path_index(suffix): - path = os.path.join(home, suffix).rstrip(os.path.sep) + path = os.path.realpath(os.path.join(home, suffix)).rstrip(os.path.sep) try: return paths.index(path) except ValueError: return -1 try: real_vim_path_index = max(vim_path_index(".vim"), vim_path_index("vimfiles")) - return paths.index(_plugin_dir()) < real_vim_path_index + plugin_path_index = paths.index(_plugin_dir()) + return plugin_path_index < real_vim_path_index except ValueError: return False From b9cdc97ef91f475d3f56222c5f3f78c64b0eb13e Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Sun, 5 Jan 2014 07:38:47 -0800 Subject: [PATCH 04/35] Alphabetize JavaScript console snippets Ordering these snippets alphabetically based on their descriptions makes it easier to find what you are looking for and to notice any snippets that may be missing from the list. --- UltiSnips/javascript.snippets | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index 546e5d4..2dce575 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -79,28 +79,24 @@ endsnippet # Snippets for Console Debug Output -snippet cl "console.log" -console.log(${1:"${2:value}"}); -endsnippet - -snippet cw "console.warn" -console.warn(${1:"${2:value}"}); +snippet ca "console.assert" +console.assert(${1:assertion}, ${2:"${3:message}"}); endsnippet snippet ce "console.error" console.error(${1:"${2:value}"}); endsnippet -snippet ca "console.assert" -console.assert(${1:assertion}, ${2:"${3:message}"}); -endsnippet - snippet cgroup "console.group" console.group("${1:label}"); ${VISUAL}$0 console.groupEnd(); endsnippet +snippet cl "console.log" +console.log(${1:"${2:value}"}); +endsnippet + snippet ctime "console.time" console.time("${1:label}"); ${VISUAL}$0 @@ -115,6 +111,10 @@ snippet ctrace "console.trace" console.trace(); endsnippet +snippet cw "console.warn" +console.warn(${1:"${2:value}"}); +endsnippet + # AMD (Asynchronous Module Definition) snippets snippet def "define an AMD module" From bf0965fb6e0935706f79f379c095f4c5bf957ffb Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Sun, 5 Jan 2014 07:35:35 -0800 Subject: [PATCH 05/35] Add missing console API methods to JS snippets This commit adds snippets for the following console API methods that were missing: - console.clear - console.dir - console.dirxml - console.groupCollapsed - console.info - console.profile - console.table I left out console.debug and console.exception since they are simply aliases for console.log and console.error. Information about the console API can be found at: https://developers.google.com/chrome-developer-tools/docs/console-api https://developer.mozilla.org/en-US/docs/Web/API/console --- UltiSnips/javascript.snippets | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index 2dce575..e3d7c68 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -83,6 +83,18 @@ snippet ca "console.assert" console.assert(${1:assertion}, ${2:"${3:message}"}); endsnippet +snippet cclear "console.clear" +console.clear(); +endsnippet + +snippet cdir "console.dir" +console.dir(${1:object}); +endsnippet + +snippet cdirx "console.dirxml" +console.dirxml(${1:object}); +endsnippet + snippet ce "console.error" console.error(${1:"${2:value}"}); endsnippet @@ -93,10 +105,30 @@ ${VISUAL}$0 console.groupEnd(); endsnippet +snippet cgroupc "console.groupCollapsed" +console.groupCollapsed("${1:label}"); +${VISUAL}$0 +console.groupEnd(); +endsnippet + +snippet ci "console.info" +console.info(${1:"${2:value}"}); +endsnippet + snippet cl "console.log" console.log(${1:"${2:value}"}); endsnippet +snippet cprof "console.profile" +console.profile("${1:label}"); +${VISUAL}$0 +console.profileEnd(); +endsnippet + +snippet ctable "console.table" +console.table(${1:"${2:value}"}); +endsnippet + snippet ctime "console.time" console.time("${1:label}"); ${VISUAL}$0 From 3c461925b9d40ed7b2a05c5000461a0876b2c489 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Sun, 5 Jan 2014 08:01:00 -0800 Subject: [PATCH 06/35] Improve console.timeStamp snippet The console.timeStamp method is camelCased, so I made the description match the contents. Additionally, there was a missing semicolon at the end of the line that I added. --- UltiSnips/javascript.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index e3d7c68..ee97c09 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -135,8 +135,8 @@ ${VISUAL}$0 console.timeEnd("$1"); endsnippet -snippet ctimestamp "console.timestamp" -console.timeStamp("${1:label}") +snippet ctimestamp "console.timeStamp" +console.timeStamp("${1:label}"); endsnippet snippet ctrace "console.trace" From 43a78a8273b734075e70189c68d973d5313a6e26 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 07:46:16 -0800 Subject: [PATCH 07/35] Add "b" trigger option to JS console snippets The "b" trigger option will require that the snippet be expanded only if it is at the "beginning of the line", that is, only whitespace may precede the tab trigger. As suggested by @SirVer[1], this commit adds the "b" tab trigger option to all of the JavaScript console API snippets. [1]: https://github.com/SirVer/ultisnips/pull/122/files#r8665940 --- UltiSnips/javascript.snippets | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index ee97c09..bc530e9 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -79,71 +79,71 @@ endsnippet # Snippets for Console Debug Output -snippet ca "console.assert" +snippet ca "console.assert" b console.assert(${1:assertion}, ${2:"${3:message}"}); endsnippet -snippet cclear "console.clear" +snippet cclear "console.clear" b console.clear(); endsnippet -snippet cdir "console.dir" +snippet cdir "console.dir" b console.dir(${1:object}); endsnippet -snippet cdirx "console.dirxml" +snippet cdirx "console.dirxml" b console.dirxml(${1:object}); endsnippet -snippet ce "console.error" +snippet ce "console.error" b console.error(${1:"${2:value}"}); endsnippet -snippet cgroup "console.group" +snippet cgroup "console.group" b console.group("${1:label}"); ${VISUAL}$0 console.groupEnd(); endsnippet -snippet cgroupc "console.groupCollapsed" +snippet cgroupc "console.groupCollapsed" b console.groupCollapsed("${1:label}"); ${VISUAL}$0 console.groupEnd(); endsnippet -snippet ci "console.info" +snippet ci "console.info" b console.info(${1:"${2:value}"}); endsnippet -snippet cl "console.log" +snippet cl "console.log" b console.log(${1:"${2:value}"}); endsnippet -snippet cprof "console.profile" +snippet cprof "console.profile" b console.profile("${1:label}"); ${VISUAL}$0 console.profileEnd(); endsnippet -snippet ctable "console.table" +snippet ctable "console.table" b console.table(${1:"${2:value}"}); endsnippet -snippet ctime "console.time" +snippet ctime "console.time" b console.time("${1:label}"); ${VISUAL}$0 console.timeEnd("$1"); endsnippet -snippet ctimestamp "console.timeStamp" +snippet ctimestamp "console.timeStamp" b console.timeStamp("${1:label}"); endsnippet -snippet ctrace "console.trace" +snippet ctrace "console.trace" b console.trace(); endsnippet -snippet cw "console.warn" +snippet cw "console.warn" b console.warn(${1:"${2:value}"}); endsnippet From bd0c576bff9a9d289aebfef86b4d59bcfa3c8096 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 08:10:37 -0800 Subject: [PATCH 08/35] Use length caching in JS `for` snippet The previous version of this snippet referenced the object's length on each iteration of the loop. This adds unnecessary overhead, causing the loop to be slower. While this will not make much of a difference in many cases, if the for loop was to be used on a large object or in a tight loop, it would degrade performance. Perhaps more importantly, if you were to not cache the length of a live query, such as DOM queries, you would see significant performance degradation. If nothing else, this adjustment to the snippet sets things up for success in more scenarios. --- UltiSnips/javascript.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index bc530e9..d458750 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -39,8 +39,8 @@ for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2--) { endsnippet snippet for "for (...) {...}" -for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) { - ${3:$1[$2]}${VISUAL}$0 +for (var ${1:i} = 0, ${2:len} = ${3:Things}.length; $1 < $2; $1++) { + ${4:${3}[$1]}${VISUAL}$0 } endsnippet From 98f88de9768a6f6a32180827ec9938ff3eaff983 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 08:22:54 -0800 Subject: [PATCH 09/35] Increase scope of JS `for` snippet placeholder The `Things.length` part of the JS `for` snippet previously did not include the `.length` portion. Using some regex replacement, we can include this bit in the placeholder while still only using the `Things` bit inside the `for` loop. This should make the snippet slightly more pleasant to use. --- UltiSnips/javascript.snippets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index d458750..b866903 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -33,14 +33,14 @@ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { endsnippet snippet for "for (...) {...} (faster)" -for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2--) { - ${3:$1[$2]}${VISUAL}$0 +for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { + ${3:${1/([^.]+).*/$1/}[$2]}${VISUAL}$0 } endsnippet snippet for "for (...) {...}" -for (var ${1:i} = 0, ${2:len} = ${3:Things}.length; $1 < $2; $1++) { - ${4:${3}[$1]}${VISUAL}$0 +for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { + ${4:${3/([^.]+).*/$1/}[$1]}${VISUAL}$0 } endsnippet From 6fa064468542ee5f3a86e32bc19d2108f7d820cd Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 08:18:33 -0800 Subject: [PATCH 10/35] Improve descriptions of JS `for` snippets More specifically than "faster" and not faster, these snippets count down and count up, respectively. Adding this information to the descriptions will help people make the correct decision. --- UltiSnips/javascript.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index b866903..ffc9e36 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -32,13 +32,13 @@ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { endsnippet -snippet for "for (...) {...} (faster)" +snippet for "for (...) {...} (counting down, faster)" for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { ${3:${1/([^.]+).*/$1/}[$2]}${VISUAL}$0 } endsnippet -snippet for "for (...) {...}" +snippet for "for (...) {...} (counting up)" for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { ${4:${3/([^.]+).*/$1/}[$1]}${VISUAL}$0 } From 1545b8327d4c4a9fd90e741568e6323985c698ee Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Tue, 7 Jan 2014 07:01:52 +0100 Subject: [PATCH 11/35] Do not use xrange since py3 does not define it. --- plugin/UltiSnips/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 16ec41d..575eae6 100755 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -22,7 +22,7 @@ def _plugin_dir(): be updated if the code moves. """ d = __file__ - for i in xrange(10): + for i in range(10): d = os.path.dirname(d) if os.path.isdir(os.path.join(d, "plugin")) and os.path.isdir(os.path.join(d, "doc")): return d @@ -1173,4 +1173,3 @@ class SnippetManager(object): UltiSnips_Manager = SnippetManager() - From 5c36a8945cd6c83c814b8ea45ab834f3a25391df Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 22:14:00 -0800 Subject: [PATCH 12/35] Change JS `for` counting down trigger from for to ford As suggested by @SirVer[1], this commit changes the trigger of the JavaScript `for` snippet that counts down from "for" to "ford". Since "for" is used pretty often, this will prevent people from needing to select which one they want from the menu each time. [1]: https://github.com/SirVer/ultisnips/pull/123/files#r8686514 --- UltiSnips/javascript.snippets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index ffc9e36..1dff6b1 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -32,7 +32,7 @@ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { endsnippet -snippet for "for (...) {...} (counting down, faster)" +snippet ford "for (...) {...} (counting down, faster)" for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { ${3:${1/([^.]+).*/$1/}[$2]}${VISUAL}$0 } From 983d494752839e7cbd9c75a42da4bfd392047037 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 22:16:05 -0800 Subject: [PATCH 13/35] Add "b" options to JS `for` and `ford` snippets `for` loops usually appear at the beginning of the line. This commit makes these snippets more context-aware by adding the "b" option that prevents them from being triggered if they are preceded with something other than whitespace, as suggested by @SirVer[1]. [1]: https://github.com/SirVer/ultisnips/pull/123/files#r8686514 --- UltiSnips/javascript.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index 1dff6b1..8389156 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -32,13 +32,13 @@ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { endsnippet -snippet ford "for (...) {...} (counting down, faster)" +snippet ford "for (...) {...} (counting down, faster)" b for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { ${3:${1/([^.]+).*/$1/}[$2]}${VISUAL}$0 } endsnippet -snippet for "for (...) {...} (counting up)" +snippet for "for (...) {...} (counting up)" b for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { ${4:${3/([^.]+).*/$1/}[$1]}${VISUAL}$0 } From 23d7ded7546d0621d05c0ef6c727b43352471368 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 22:19:25 -0800 Subject: [PATCH 14/35] Simplify JS `for` snippet bodies As suggested by @SirVer[1], having `Things[i]` be pre-populated in the body of the `for` loop snippets is not very useful given the merits of autocompletion. This commit simplifies these bodies by simply using `${VISUAL}$0`. [1]: https://github.com/SirVer/ultisnips/pull/123/files#r8686533 --- UltiSnips/javascript.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index 8389156..b36ef71 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -34,13 +34,13 @@ endsnippet snippet ford "for (...) {...} (counting down, faster)" b for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { - ${3:${1/([^.]+).*/$1/}[$2]}${VISUAL}$0 + ${VISUAL}$0 } endsnippet snippet for "for (...) {...} (counting up)" b for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { - ${4:${3/([^.]+).*/$1/}[$1]}${VISUAL}$0 + ${VISUAL}$0 } endsnippet From 2f66a3fc2bc076f46d23a0cd87b5a1bf139b36bb Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 6 Jan 2014 22:21:50 -0800 Subject: [PATCH 15/35] Re-order JS `for` snippets Now that we have separated the two `for` loop snippet triggers by changing the one that counts down from "for" to "ford", it feels more and more like "ford" is a variant of "for" so I am moving it after it in the file. Also, alphabetical. --- UltiSnips/javascript.snippets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index b36ef71..95f96c8 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -32,14 +32,14 @@ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { endsnippet -snippet ford "for (...) {...} (counting down, faster)" b -for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { +snippet for "for (...) {...} (counting up)" b +for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { ${VISUAL}$0 } endsnippet -snippet for "for (...) {...} (counting up)" b -for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) { +snippet ford "for (...) {...} (counting down, faster)" b +for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) { ${VISUAL}$0 } endsnippet From ace6150fac52ebc5d8e9c2275f433ca5df99da35 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 7 Jan 2014 22:41:21 -0800 Subject: [PATCH 16/35] Add snippets for scss files This commit adds a lot of the basic Sass directives used in Sass script. Documentation can be found at: http://sass-lang.com/documentation/file.SASS_REFERENCE.html I decided to use regular expressions for the triggers, since typing the `@` may be too cumbersome to require it to always be included, but is likely happening due to muscle memory too often to leave it out. Regular expressions give us the flexibility to have it both ways in this case. --- UltiSnips/scss.snippets | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 UltiSnips/scss.snippets diff --git a/UltiSnips/scss.snippets b/UltiSnips/scss.snippets new file mode 100644 index 0000000..6d34ef3 --- /dev/null +++ b/UltiSnips/scss.snippets @@ -0,0 +1,49 @@ +snippet /@?inc/ "@include mixin(...);" br +@include ${1:mixin}(${2:arguments}); +endsnippet + +snippet /@?ext?/ "@extend %placeholder;" br +@extend %${1:placeholder}; +endsnippet + +snippet /@?mixin/ "@mixin (...) { ... }" br +@mixin ${1:name}(${2:arguments}) { + ${VISUAL}$0 +} +endsnippet + +snippet /@?fun/ "@function (...) { ... }" br +@function ${1:name}(${2:arguments}) { + ${VISUAL}$0 +} +endsnippet + +snippet /@?if/ "@if (...) { ... }" br +@if ${1:condition} { + ${VISUAL}$0 +} +endsnippet + +snippet /(} )?@?else/ "@else { ... }" br +@else ${1:condition} { + ${VISUAL}$0 +} +endsnippet + +snippet /@?for/ "@for loop" br +@for ${1:$i} from ${2:1} through ${3:3} { + ${VISUAL}$0 +} +endsnippet + +snippet /@?each/ "@each loop" br +@each ${1:$item} in ${2:item, item, item} { + ${VISUAL}$0 +} +endsnippet + +snippet /@?while/ "@while loop" br +@while ${1:$i} ${2:>} ${3:0} { + ${VISUAL}$0 +} +endsnippet From 9b02aaf865a3e4b91a0c64b3bd326ffd9429e1db Mon Sep 17 00:00:00 2001 From: Jesper Skovgaard Nielsen Date: Wed, 8 Jan 2014 10:14:28 +0100 Subject: [PATCH 17/35] Make construct snippet PSR compliant. --- UltiSnips/php.snippets | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UltiSnips/php.snippets b/UltiSnips/php.snippets index 9e48930..6d8b138 100644 --- a/UltiSnips/php.snippets +++ b/UltiSnips/php.snippets @@ -230,9 +230,10 @@ endsnippet snippet construct "__construct()" b /** - * @param $2mixed ${1/, /\n * \@param mixed /g} + * @param $2mixed ${1/, /\n * \@param mixed /g} */ -public function __construct(${1:$dependencies}) {${1/\$(\w+)(, )*/\n\t$this->$1 = $$1;/g} +public function __construct(${1:$dependencies}) +{${1/\$(\w+)(, )*/\n $this->$1 = $$1;/g} } $0 endsnippet From 76327d17c641a7e065904cf862f8a2aadace1bdc Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Fri, 10 Jan 2014 21:23:46 +0000 Subject: [PATCH 18/35] Updated space problem- added 'if' --- UltiSnips/c.snippets | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index 7b40728..bace3a5 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -112,8 +112,20 @@ else { endsnippet snippet eli "else if .. (eli)" -else if (${1:/* condition */}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +else if (${1:/* condition */}) +{ + ${2:/* else.i */} +} +endsnippet + +snippet elie "else if.. else (elie)" +else if (${1:/* condition */}) +{ + ${2:/* else.i */} +} +else +{ + ${3:/* else */} } endsnippet @@ -131,15 +143,15 @@ endsnippet snippet ifee "if .. else if .. else (ifee)" if (${1:/* condition */}) { - ${2:/* code */} + ${2:/* code */} } else if (${3:/* condition */}) { - ${4:/* code */} + ${4:/* else.i */} } else { - ${5:/* code */} + ${5:/* else */} } endsnippet From eb5f4946ad7e7cb87e2474ad3c400224070f1be0 Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Fri, 10 Jan 2014 21:49:13 +0000 Subject: [PATCH 19/35] Dynamic tab solve - added if statem' --- UltiSnips/c.snippets | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index bace3a5..0b474a9 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -38,22 +38,22 @@ endsnippet snippet main "main() (main)" int main(int argc, char *argv[]) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} - return 0; + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + return 0; } endsnippet snippet for "for loop (for)" for (${2:i} = 0; $2 < ${1:count}; ${3:++$2}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet snippet fori "for int loop (fori)" for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet @@ -64,10 +64,10 @@ endsnippet snippet once "Include header once only guard" #ifndef ${1:`!p if not snip.c: - import random, string - name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper() - rand = ''.join(random.sample(string.ascii_letters+string.digits, 8)) - snip.rv = ('%s_%s' % (name,rand)).upper() + import random, string + name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper() + rand = ''.join(random.sample(string.ascii_letters+string.digits, 8)) + snip.rv = ('%s_%s' % (name,rand)).upper() else: snip.rv = snip.c`} #define $1 @@ -84,13 +84,13 @@ endsnippet snippet wh "while loop" while(${1:/* condition */}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet snippet do "do...while loop (do)" do { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } while(${1:/* condition */}); endsnippet @@ -101,13 +101,13 @@ endsnippet snippet if "if .. (if)" if (${1:/* condition */}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet snippet el "else .. (else)" else { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet @@ -132,22 +132,22 @@ endsnippet snippet ife "if .. else (ife)" if (${1:/* condition */}) { - ${2:/* code */} + ${2:/* code */} } else { - ${3:/* else */} + ${3:/* else */} } endsnippet snippet ifee "if .. else if .. else (ifee)" if (${1:/* condition */}) { - ${2:/* code */} + ${2:/* code */} } else if (${3:/* condition */}) { - ${4:/* else.i */} + ${4:/* else.i */} } else { @@ -162,14 +162,14 @@ endsnippet snippet st "struct" struct ${1:`!p snip.rv = (snip.basename or "name") + "_t"`} { - ${0:/* data */} + ${0:/* data */} }; endsnippet snippet fun "function" b ${1:void} ${2:function_name}(${3}) { - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet From 5b3aa799e4b4702c2a38a3975f41ac5cb6be5bd0 Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Sat, 11 Jan 2014 20:44:11 +0000 Subject: [PATCH 20/35] added 'if ..else' snippet --- UltiSnips/c.snippets | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index 0b474a9..f6a5ca5 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -112,23 +112,11 @@ else { endsnippet snippet eli "else if .. (eli)" -else if (${1:/* condition */}) -{ +else if (${1:/* condition */}) { ${2:/* else.i */} } endsnippet -snippet elie "else if.. else (elie)" -else if (${1:/* condition */}) -{ - ${2:/* else.i */} -} -else -{ - ${3:/* else */} -} -endsnippet - snippet ife "if .. else (ife)" if (${1:/* condition */}) { @@ -140,21 +128,6 @@ else } endsnippet -snippet ifee "if .. else if .. else (ifee)" -if (${1:/* condition */}) -{ - ${2:/* code */} -} -else if (${3:/* condition */}) -{ - ${4:/* else.i */} -} -else -{ - ${5:/* else */} -} -endsnippet - snippet printf "printf .. (printf)" printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/} endsnippet From b0f5f6acf087f331234918ab9084e010aebeac70 Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Sat, 11 Jan 2014 20:44:11 +0000 Subject: [PATCH 21/35] added 'if else ..' snippet --- UltiSnips/c.snippets | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index 0b474a9..f6a5ca5 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -112,23 +112,11 @@ else { endsnippet snippet eli "else if .. (eli)" -else if (${1:/* condition */}) -{ +else if (${1:/* condition */}) { ${2:/* else.i */} } endsnippet -snippet elie "else if.. else (elie)" -else if (${1:/* condition */}) -{ - ${2:/* else.i */} -} -else -{ - ${3:/* else */} -} -endsnippet - snippet ife "if .. else (ife)" if (${1:/* condition */}) { @@ -140,21 +128,6 @@ else } endsnippet -snippet ifee "if .. else if .. else (ifee)" -if (${1:/* condition */}) -{ - ${2:/* code */} -} -else if (${3:/* condition */}) -{ - ${4:/* else.i */} -} -else -{ - ${5:/* else */} -} -endsnippet - snippet printf "printf .. (printf)" printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/} endsnippet From 9b9235d40fdcf3c711da49ebe3ca9baf6efd2740 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 14 Jan 2014 10:27:09 -0800 Subject: [PATCH 22/35] Add `@import` to scss snippets Following the local pattern, this snippet is triggered by either `@imp` or `imp`. --- UltiSnips/scss.snippets | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UltiSnips/scss.snippets b/UltiSnips/scss.snippets index 6d34ef3..b7e9b88 100644 --- a/UltiSnips/scss.snippets +++ b/UltiSnips/scss.snippets @@ -1,3 +1,7 @@ +snippet /@?imp/ "@import '...';" br +@import '${1:file}'; +endsnippet + snippet /@?inc/ "@include mixin(...);" br @include ${1:mixin}(${2:arguments}); endsnippet From 2b66c77695ff7f34d99bad6bb7adc78f81021d88 Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Thu, 16 Jan 2014 21:42:55 +0000 Subject: [PATCH 23/35] Added .. else if (eli) .. snippet --- UltiSnips/c.snippets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index f6a5ca5..1b13928 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -112,8 +112,8 @@ else { endsnippet snippet eli "else if .. (eli)" + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} else if (${1:/* condition */}) { - ${2:/* else.i */} } endsnippet From 3426be5654e93e24095592f52820d7918fd1a691 Mon Sep 17 00:00:00 2001 From: rudfol <33jhkim@gmail.com> Date: Thu, 16 Jan 2014 21:44:28 +0000 Subject: [PATCH 24/35] added .. else if (eli) .. snippet --- UltiSnips/c.snippets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index 1b13928..9fd1615 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -112,8 +112,8 @@ else { endsnippet snippet eli "else if .. (eli)" - ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} else if (${1:/* condition */}) { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} } endsnippet From be1577b058e568bfb2e64f42c46db640b5ab678d Mon Sep 17 00:00:00 2001 From: Vital Kudzelka Date: Sat, 31 Aug 2013 15:08:12 +0300 Subject: [PATCH 25/35] Add snippets to write JSDoc documentation --- UltiSnips/javascript_jsdoc.snippets | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 UltiSnips/javascript_jsdoc.snippets diff --git a/UltiSnips/javascript_jsdoc.snippets b/UltiSnips/javascript_jsdoc.snippets new file mode 100644 index 0000000..a796f8b --- /dev/null +++ b/UltiSnips/javascript_jsdoc.snippets @@ -0,0 +1,47 @@ +################################################################################ +# JSDoc snippets # +################################################################################ + +snippet /* "A JSDoc comment" b +/** + * ${1}${VISUAL}$0 + */ +endsnippet + +snippet "@aut(h(o(r)?)?)?" "@author email (First Last)" r +@author ${1:`!v g:snips_author_email`} (${2:`!v g:snips_author`}) +endsnippet + +snippet "@li(c(e(n(s(e)?)?)?)?)?" "@license Description" r +@license ${1:MIT}${VISUAL}$0 +endsnippet + +snippet "@fileo(verview)?" "@fileoverview Description" br +/** + * @fileoverview ${1}${VISUAL}$0 + */ +endsnippet + +snippet "@constr(uctor)?" "@constructor" r +@constructor +endsnippet + +snippet "@p(a(r(a(m)?)?)?)?" "@param {Type} varname Description" r +@param {${1:Type}} ${2:varname} ${3:Description} +endsnippet + +snippet "@r(e(t(u(r(n)?)?)?)?)?" "@return {Type} Description" r +@return {${1:Type}} ${2:Description} +endsnippet + +snippet "@pri(v(a(t(e)?)?)?)?" "@private" r +@private +endsnippet + +snippet "@ov(e(r(r(i(d(e)?)?)?)?)?)?" "@override" r +@override +endsnippet + +snippet "@(pt|pro(t(e(c(t(e(d)?)?)?)?)?)?)" "@protected" r +@protected +endsnippet From faa19dff0f74697794edc479d63cb8536f9f3253 Mon Sep 17 00:00:00 2001 From: Vital Kudzelka Date: Fri, 24 Jan 2014 13:40:31 +0300 Subject: [PATCH 26/35] Remove comment box in header --- UltiSnips/javascript_jsdoc.snippets | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UltiSnips/javascript_jsdoc.snippets b/UltiSnips/javascript_jsdoc.snippets index a796f8b..a935534 100644 --- a/UltiSnips/javascript_jsdoc.snippets +++ b/UltiSnips/javascript_jsdoc.snippets @@ -1,6 +1,4 @@ -################################################################################ -# JSDoc snippets # -################################################################################ +# JSDoc snippets snippet /* "A JSDoc comment" b /** From c60814ced80979032f1e005f00fc203069d941b6 Mon Sep 17 00:00:00 2001 From: Vital Kudzelka Date: Fri, 24 Jan 2014 14:30:14 +0300 Subject: [PATCH 27/35] Fix some visual placeholders --- UltiSnips/javascript_jsdoc.snippets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UltiSnips/javascript_jsdoc.snippets b/UltiSnips/javascript_jsdoc.snippets index a935534..5d5578e 100644 --- a/UltiSnips/javascript_jsdoc.snippets +++ b/UltiSnips/javascript_jsdoc.snippets @@ -2,7 +2,7 @@ snippet /* "A JSDoc comment" b /** - * ${1}${VISUAL}$0 + * ${1:${VISUAL}}$0 */ endsnippet @@ -11,12 +11,12 @@ snippet "@aut(h(o(r)?)?)?" "@author email (First Last)" r endsnippet snippet "@li(c(e(n(s(e)?)?)?)?)?" "@license Description" r -@license ${1:MIT}${VISUAL}$0 +@license ${1:MIT}$0 endsnippet snippet "@fileo(verview)?" "@fileoverview Description" br /** - * @fileoverview ${1}${VISUAL}$0 + * @fileoverview ${1:${VISUAL:A description of the file}}$0 */ endsnippet From 9bb0dfb3dbf9dfa08c246ee8950afdfb3b4b06db Mon Sep 17 00:00:00 2001 From: Vital Kudzelka Date: Fri, 24 Jan 2014 14:34:12 +0300 Subject: [PATCH 28/35] Do not use regexp in snippet triggers --- UltiSnips/javascript_jsdoc.snippets | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/UltiSnips/javascript_jsdoc.snippets b/UltiSnips/javascript_jsdoc.snippets index 5d5578e..3b7abfe 100644 --- a/UltiSnips/javascript_jsdoc.snippets +++ b/UltiSnips/javascript_jsdoc.snippets @@ -6,40 +6,40 @@ snippet /* "A JSDoc comment" b */ endsnippet -snippet "@aut(h(o(r)?)?)?" "@author email (First Last)" r +snippet @au "@author email (First Last)" @author ${1:`!v g:snips_author_email`} (${2:`!v g:snips_author`}) endsnippet -snippet "@li(c(e(n(s(e)?)?)?)?)?" "@license Description" r +snippet @li "@license Description" @license ${1:MIT}$0 endsnippet -snippet "@fileo(verview)?" "@fileoverview Description" br +snippet @fileo "@fileoverview Description" b /** * @fileoverview ${1:${VISUAL:A description of the file}}$0 */ endsnippet -snippet "@constr(uctor)?" "@constructor" r +snippet @constr "@constructor" @constructor endsnippet -snippet "@p(a(r(a(m)?)?)?)?" "@param {Type} varname Description" r +snippet @p "@param {Type} varname Description" @param {${1:Type}} ${2:varname} ${3:Description} endsnippet -snippet "@r(e(t(u(r(n)?)?)?)?)?" "@return {Type} Description" r +snippet @ret "@return {Type} Description" @return {${1:Type}} ${2:Description} endsnippet -snippet "@pri(v(a(t(e)?)?)?)?" "@private" r +snippet @pri "@private" @private endsnippet -snippet "@ov(e(r(r(i(d(e)?)?)?)?)?)?" "@override" r +snippet @over "@override" @override endsnippet -snippet "@(pt|pro(t(e(c(t(e(d)?)?)?)?)?)?)" "@protected" r +snippet @pro "@protected" @protected endsnippet From b11a021397472706bccb2a264e46a6af1b6d7f54 Mon Sep 17 00:00:00 2001 From: Vital Kudzelka Date: Fri, 24 Jan 2014 14:49:24 +0300 Subject: [PATCH 29/35] Add snippet for the @version tag --- UltiSnips/javascript_jsdoc.snippets | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UltiSnips/javascript_jsdoc.snippets b/UltiSnips/javascript_jsdoc.snippets index 3b7abfe..fe979eb 100644 --- a/UltiSnips/javascript_jsdoc.snippets +++ b/UltiSnips/javascript_jsdoc.snippets @@ -14,6 +14,10 @@ snippet @li "@license Description" @license ${1:MIT}$0 endsnippet +snippet @ver "@version Semantic version" +@version ${1:0.1.0}$0 +endsnippet + snippet @fileo "@fileoverview Description" b /** * @fileoverview ${1:${VISUAL:A description of the file}}$0 From 2fca23830bb67c1f7d1c576f22a9206dbc46fc12 Mon Sep 17 00:00:00 2001 From: Maarten Slagter Date: Thu, 23 Jan 2014 14:54:19 +0100 Subject: [PATCH 30/35] Added bunch of snippets to tex.snippets --- UltiSnips/tex.snippets | 65 ++++++++++++------------------------------ doc/UltiSnips.txt | 1 + 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/UltiSnips/tex.snippets b/UltiSnips/tex.snippets index eddd614..3006584 100644 --- a/UltiSnips/tex.snippets +++ b/UltiSnips/tex.snippets @@ -1,39 +1,26 @@ extends texmath -########################################################################### -# LATEX SNIPPETS # -########################################################################### - -snippet r "\\ref{}" w -\ref{$1} -endsnippet - -########################################################################### -# TEXTMATE SNIPPETS # -########################################################################### - -################# -# GENERAL STUFF # -################# snippet "b(egin)?" "begin{} / end{}" br \begin{${1:something}} ${0:${VISUAL}} \end{$1} endsnippet -#################### -# TABULARS, ARRAYS # -#################### - snippet tab \begin{${1:t}${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}}{${2:c}} $0${2/((?<=.)c|l|r)|./(?1: & )/g} \end{$1${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}} endsnippet -######################## -# ENUM, DESCR, ITEMIZE # -######################## +snippet fig "Figure environment" b +\begin{figure}${2:[htpb]} + \centering + \includegraphics[width=${3:0.8}\linewidth]{${4:name.ext}} + \caption{${4/(\w+)\.\w+/\u$1/}$0} + \label{fig:${4/(\w+)\.\w+/$1/}} +\end{figure} +endsnippet + snippet enum "Enumerate" b \begin{enumerate} \item $0 @@ -52,17 +39,16 @@ snippet desc "Description" b \end{description} endsnippet -##################################### -# SECTIONS, CHAPTERS AND THEIR LIKE # -##################################### +snippet it "Individual item" b +\item ${1} +$0 +endsnippet snippet part "Part" b \part{${1:part name}} \label{prt:${2:${1/(\w+)|\W+/(?1:\L$0\E:_)/ga}}} ${0} - -% part $2 (end) endsnippet snippet cha "Chapter" b @@ -70,8 +56,6 @@ snippet cha "Chapter" b \label{cha:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} ${0} - -% chapter $2 (end) endsnippet snippet sec "Section" b @@ -79,18 +63,13 @@ snippet sec "Section" b \label{sec:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} ${0} - -% section $2 (end) endsnippet - snippet sub "Subsection" b \subsection{${1:subsection name}} \label{sub:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} ${0} - -% subsection $2 (end) endsnippet snippet ssub "Subsubsection" b @@ -98,9 +77,6 @@ snippet ssub "Subsubsection" b \label{ssub:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} ${0} - -% subsubsection $2 (end) - endsnippet snippet par "Paragraph" b @@ -108,30 +84,25 @@ snippet par "Paragraph" b \label{par:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} ${0} - -% paragraph $2 (end) endsnippet - snippet subp "Subparagraph" b \subparagraph{${1:subparagraph name}} \label{par:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}} ${0} - -% subparagraph $2 (end) endsnippet -############### -# Utilities # -############### +snippet ni "Non-indented paragraph" b +\noindent +${0} +endsnippet snippet pac "Package" b \usepackage[${1:options}]{${2:package}}$0 endsnippet - -snippet lp "Long parenthesis" +snippet lp "Long parenthesis" \left(${1:${VISUAL:contents}}\right)$0 endsnippet # vim:ft=snippets: diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index dd65c9b..3a93b3a 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -1450,6 +1450,7 @@ Contributors listed in chronological order: Bernhard Vallant (lazerscience) Von Welch (von) Nikola Petrov (nikolavp) + Maarten Slagter (slagtermaarten) Thank you for your support. From fee8a23d2daffb68f1a35f0bc1f1ceb4e2b2daf1 Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Fri, 31 Jan 2014 16:18:14 +0100 Subject: [PATCH 31/35] Retains the unnamed register during jumps --- plugin/UltiSnips/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 575eae6..b63849e 100755 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -553,8 +553,13 @@ class SnippetManager(object): self._supertab_keys = None self._csnippets = [] + # needed to retain the unnamed register at all times + self._unnamed_reg_cached = False + self._last_placeholder = None + self.reset() + @err_to_scratch_buffer def reset(self, test_error=False): self._vstate = VimState() @@ -832,10 +837,23 @@ class SnippetManager(object): self._current_snippet_is_done() jumped = self._jump(backwards) if jumped: + self._cache_unnamed_register() self._vstate.remember_position() self._ignore_movements = True return jumped + def _cache_unnamed_register(self): + self._unnamed_reg_cached = True + unnamed_reg = _vim.eval('@"') + if self._last_placeholder != unnamed_reg: + self._unnamed_reg_cache = _vim.eval('@"') + self._last_placeholder = self._ctab._initial_text + + def restore_unnamed_register(self): + if self._unnamed_reg_cached: + _vim.command( "let @\"='%s'" % self._unnamed_reg_cache) + self._unnamed_register_cached = False + def _handle_failure(self, trigger): """ Mainly make sure that we play well with SuperTab From bf3bfdac9cf6725cee0385a3cf3bcc6abc761506 Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Fri, 31 Jan 2014 16:20:31 +0100 Subject: [PATCH 32/35] Adds eventhandler to restore the unnamed register --- plugin/UltiSnips.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/UltiSnips.vim b/plugin/UltiSnips.vim index 67d0b64..bdbedcd 100644 --- a/plugin/UltiSnips.vim +++ b/plugin/UltiSnips.vim @@ -227,6 +227,11 @@ endf function! UltiSnips_LeavingBuffer() exec g:_uspy "UltiSnips_Manager.leaving_buffer()" endf + +function! UltiSnips_LeavingInsertMode() + exec g:_uspy "UltiSnips_Manager.restore_unnamed_register()" +endfunction + " }}} " COMPLETE FUNCTIONS {{{ function! UltiSnipsFiletypeComplete(arglead, cmdline, cursorpos) @@ -262,6 +267,7 @@ exec g:_uspy "UltiSnips_Manager.backward_trigger = vim.eval('g:UltiSnipsJumpBack au CursorMovedI * call UltiSnips_CursorMoved() au CursorMoved * call UltiSnips_CursorMoved() au BufLeave * call UltiSnips_LeavingBuffer() +au InsertLeave * call UltiSnips_LeavingInsertMode() call UltiSnips_MapKeys() From 60f1089d9dd02306aeefdc24acc3f84949f9292f Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Fri, 31 Jan 2014 16:55:42 +0100 Subject: [PATCH 33/35] Escapes the cached string --- plugin/UltiSnips/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index b63849e..eb58fc3 100755 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -846,12 +846,13 @@ class SnippetManager(object): self._unnamed_reg_cached = True unnamed_reg = _vim.eval('@"') if self._last_placeholder != unnamed_reg: - self._unnamed_reg_cache = _vim.eval('@"') + self._unnamed_reg_cache = unnamed_reg self._last_placeholder = self._ctab._initial_text def restore_unnamed_register(self): if self._unnamed_reg_cached: - _vim.command( "let @\"='%s'" % self._unnamed_reg_cache) + escaped_cache = self._unnamed_reg_cache.replace("'", "''") + _vim.command("let @\"='%s'" % escaped_cache) self._unnamed_register_cached = False def _handle_failure(self, trigger): From f26a2ce83000948194d16da0cfd64b1d32fb9435 Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Sat, 1 Feb 2014 01:43:43 +0100 Subject: [PATCH 34/35] Adds a test for the new feature --- test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test.py b/test.py index a1f6ed0..d7207bf 100755 --- a/test.py +++ b/test.py @@ -3041,6 +3041,13 @@ class Bug1251994(_VimTest): wanted = " world hello;blub" # End: 1251994 #}}} +# Test for Github Pull Request #134 {{{# +class RetainsTheUnnamedRegister(_VimTest): + snippets = ("test", "${1:hello} ${2:world} ${0}") + keys = "yank" + ESC + "by4lea test" + EX + "HELLO" + JF + JF + ESC + "p" + wanted = "yank HELLO world yank" +# End: Github Pull Request # 134 #}}} + class VerifyVimDict1(_VimTest): """check: correct type (4 means vim dictionary) From 9770ff46cd80e5850440a4673be7d743a05bb994 Mon Sep 17 00:00:00 2001 From: ivanbrennan Date: Sat, 1 Feb 2014 14:19:45 -0500 Subject: [PATCH 35/35] Replace 'INLINE' tags with 'EXPR' tags in form_for snippets. Changed ERB tag-style from '<% %>' to '<%= %>' to be compatible with Rails 3 and newer. --- UltiSnips/eruby.snippets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UltiSnips/eruby.snippets b/UltiSnips/eruby.snippets index cf8ba2f..e5dd2ca 100644 --- a/UltiSnips/eruby.snippets +++ b/UltiSnips/eruby.snippets @@ -140,13 +140,13 @@ endsnippet snippet ffe "form_for with errors" `!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`error_messages_for :${1:model}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_for @${2:$1} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)` +`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`form_for @${2:$1} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` $0 `!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` endsnippet snippet ff "form_for" -`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_for @${1:model} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)` +`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`form_for @${1:model} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` $0 `!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)` endsnippet