From 670e2e61d089bafacab4d3994578c58794307ef2 Mon Sep 17 00:00:00 2001 From: mityu Date: Tue, 4 Jun 2019 20:26:09 +0900 Subject: Update the method of removeing {{_cursor_}} feedkeys() does only adding characters to the queue of key inputs. --- autoload/sonictemplate.vim | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 9397efa..a7476f8 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -1,7 +1,7 @@ "============================================================================= " sonictemplate.vim " Author: Yasuhiro Matsumoto -" Last Change: 07-Mar-2019. +" Last Change: 04-Jun-2019. let s:save_cpo = &cpo set cpo&vim @@ -320,15 +320,9 @@ function! sonictemplate#apply(name, mode, ...) abort endif endif if stridx(c, '{{_cursor_}}') != -1 - if a:mode == 'n' - silent! call search('\zs{{_cursor_}}', 'w') - silent! foldopen - silent! normal! 12"_x - else - silent! call search('{{_cursor_}}\zs', 'w') - silent! foldopen - silent! call feedkeys(repeat("\", 12)) - endif + silent! call search('\zs{{_cursor_}}', 'w') + silent! foldopen + silent! normal! "_da} endif endfunction @@ -377,9 +371,9 @@ function! sonictemplate#postfix() let &indentexpr = oldindentexpr endif if stridx(c, '{{_cursor_}}') != -1 - silent! call search('{{_cursor_}}\zs', 'w') + silent! call search('\zs{{_cursor_}}', 'w') silent! foldopen - silent! call feedkeys(repeat("\", 12)) + silent! normal! "_da} endif break endif -- cgit v1.2.3-54-g00ecf From b75b06bd0b099cb7e2c54863dbe91bc3a3028d5f Mon Sep 17 00:00:00 2001 From: mityu Date: Tue, 21 Jan 2020 11:59:51 +0900 Subject: Squashed commit of the following: commit e972aa09aa158189c36913b62a4344cb3ca78c76 Merge: 0925277 4d00bdb Author: mattn Date: Tue Jan 14 18:26:58 2020 +0900 Merge pull request #39 from sgur/fix/error_on_normal Prefix noautocmd to "normal!" commands which trigger TextChange events. commit 4d00bdb4b7e60e0466d3a6e5791779f8ebe7d8fc Author: sgur Date: Tue Jan 14 16:28:05 2020 +0900 Prefix noautocmd to normal! commands which trigger TextChange events. Fix #38 commit 0925277597e5db0e4b601aecc290b79db239b174 Author: Yasuhiro Matsumoto Date: Fri Dec 27 15:59:12 2019 +0900 Add snippets for typescript commit 20a19f48f9db3a32c3ebc0352fe094bd9816cd38 Author: Yasuhiro Matsumoto Date: Wed Dec 25 17:04:37 2019 +0900 Add base-main.scala commit e746cdf5c5dc8d3849b7e2517c4a24e57d931dd3 Author: Yasuhiro Matsumoto Date: Sat Dec 21 23:11:46 2019 +0900 Strictly commit c512546f04de8a185d40292dd0860d81d1896130 Merge: 859adef 47c0d77 Author: mattn Date: Thu Nov 14 19:01:33 2019 +0900 Merge pull request #37 from anekos/fix/dont-kill-my-register Avoid updating register commit 47c0d77f6cad63ea17b0fa6c87d585768c35cf89 Author: anekos Date: Thu Nov 14 18:46:36 2019 +0900 Avoid updating register commit 859adef1e67cc0fb1a99e4e3f3d58360f5464f02 Merge: 4e1b1a3 5e752a5 Author: mattn Date: Tue Oct 8 16:00:33 2019 +0900 Merge pull request #36 from wallysslima/master replace deprecated MANTAINER with LABEL in Dockerfile commit 4e1b1a36a95e899ad4415d7b4373e2c0e3ff05af Author: Yasuhiro Matsumoto Date: Sun Oct 6 21:29:01 2019 +0900 Add build.gradle for kotlin commit 5e752a5bf606ec50fffca5a2269ade32a22c1fe4 Author: Wallyss Lima Date: Thu Oct 3 11:58:22 2019 -0300 replace deprecated MANTAINER with LABEL in Dockerfile commit 51a9cec47ad815451a8cdf1408a50ea525111442 Author: Yasuhiro Matsumoto Date: Wed Oct 2 11:26:01 2019 +0900 Fix feedkeys commit 807562bbebb7b7c033823ebd3b13b32a814d4f7f Author: Yasuhiro Matsumoto Date: Wed Oct 2 10:41:10 2019 +0900 Use flag n for feedkeys commit 7db10f422f61819a1a8f45d0dade1de17ecab2b6 Merge: 31de6a5 39cf197 Author: Yasuhiro Matsumoto Date: Wed Oct 2 10:06:35 2019 +0900 Merge branch 'master' of https://github.com/mattn/sonictemplate-vim commit 31de6a5e48b65dface121e654e40e06de6bf364a Author: Yasuhiro Matsumoto Date: Wed Oct 2 09:25:34 2019 +0900 Update postfix completion commit 39cf197d0e46eeff8f905063ba5030e8690169b3 Merge: df88ac3 2f49560 Author: mattn Date: Thu Sep 26 14:28:34 2019 +0900 Merge pull request #34 from hiroebe/fix-shiftwidth Use shiftwidth() instead of &shiftwidth commit 2f49560db7699d7988a817a4f69f8b684cecdfee Author: hiroebe Date: Mon Sep 16 17:17:12 2019 +0900 Use shiftwidth() instead of &shiftwidth commit df88ac36ed24e68d7d9d7e4d9aa471575d3c79bd Author: mattn Date: Wed Aug 14 15:01:05 2019 +0900 Create FUNDING.yml commit c1ec4cdaf215f22c86040584cb1eef2b3ac2b741 Author: Yasuhiro Matsumoto Date: Fri Jul 12 22:29:15 2019 +0900 Fix socket server --- .github/FUNDING.yml | 12 +++++++++ autoload/sonictemplate.vim | 22 ++++++++--------- template/c/base-socket-server.c | 37 +++++++++++++++++++--------- template/dockerfile/base-main.dockerfile | 2 +- template/go/pattern.stpl | 23 +++++++++++++++++ template/groovy/base-gradle-kotlin.gradle | 22 +++++++++++++++++ template/java/pattern.stpl | 6 +++++ template/scala/base-main.scala | 6 +++++ template/typescript/base-class.ts | 5 ++++ template/typescript/snip-class.ts | 5 ++++ template/typescript/snip-ctor.ts | 7 ++++++ template/typescript/snip-dowhile.ts | 3 +++ template/typescript/snip-endregion.ts | 1 + template/typescript/snip-error.ts | 1 + template/typescript/snip-for.ts | 4 +++ template/typescript/snip-foreach-lambda.ts | 3 +++ template/typescript/snip-forin.ts | 6 +++++ template/typescript/snip-forof.ts | 3 +++ template/typescript/snip-function.ts | 3 +++ template/typescript/snip-get.ts | 5 ++++ template/typescript/snip-if.ts | 3 +++ template/typescript/snip-ifelse.ts | 5 ++++ template/typescript/snip-import-statement.ts | 1 + template/typescript/snip-log.ts | 1 + template/typescript/snip-new.ts | 1 + template/typescript/snip-private-method.ts | 3 +++ template/typescript/snip-prop.ts | 9 +++++++ template/typescript/snip-public-method.ts | 6 +++++ template/typescript/snip-ref.ts | 1 + template/typescript/snip-region.ts | 1 + template/typescript/snip-set.ts | 5 ++++ template/typescript/snip-settimeout.ts | 3 +++ template/typescript/snip-switch.ts | 8 ++++++ template/typescript/snip-throw.ts | 1 + template/typescript/snip-trycatch.ts | 5 ++++ template/typescript/snip-warn.ts | 1 + template/typescript/snip-while.ts | 3 +++ 37 files changed, 210 insertions(+), 23 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 template/groovy/base-gradle-kotlin.gradle create mode 100644 template/scala/base-main.scala create mode 100644 template/typescript/base-class.ts create mode 100644 template/typescript/snip-class.ts create mode 100644 template/typescript/snip-ctor.ts create mode 100644 template/typescript/snip-dowhile.ts create mode 100644 template/typescript/snip-endregion.ts create mode 100644 template/typescript/snip-error.ts create mode 100644 template/typescript/snip-for.ts create mode 100644 template/typescript/snip-foreach-lambda.ts create mode 100644 template/typescript/snip-forin.ts create mode 100644 template/typescript/snip-forof.ts create mode 100644 template/typescript/snip-function.ts create mode 100644 template/typescript/snip-get.ts create mode 100644 template/typescript/snip-if.ts create mode 100644 template/typescript/snip-ifelse.ts create mode 100644 template/typescript/snip-import-statement.ts create mode 100644 template/typescript/snip-log.ts create mode 100644 template/typescript/snip-new.ts create mode 100644 template/typescript/snip-private-method.ts create mode 100644 template/typescript/snip-prop.ts create mode 100644 template/typescript/snip-public-method.ts create mode 100644 template/typescript/snip-ref.ts create mode 100644 template/typescript/snip-region.ts create mode 100644 template/typescript/snip-set.ts create mode 100644 template/typescript/snip-settimeout.ts create mode 100644 template/typescript/snip-switch.ts create mode 100644 template/typescript/snip-throw.ts create mode 100644 template/typescript/snip-trycatch.ts create mode 100644 template/typescript/snip-warn.ts create mode 100644 template/typescript/snip-while.ts diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..351ae11 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: mattn # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index a7476f8..15fac9a 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -1,7 +1,7 @@ "============================================================================= " sonictemplate.vim " Author: Yasuhiro Matsumoto -" Last Change: 04-Jun-2019. +" Last Change: 21-Jan-2020. let s:save_cpo = &cpo set cpo&vim @@ -68,7 +68,7 @@ function! s:get_candidate(fts, lead) endif try let ft = s:get_filetype() - let cxt = sonictemplate#lang#{ft!=""?ft:"_"}#guess() + let cxt = sonictemplate#lang#{ft !=# '' ? ft : '_'}#guess() if has_key(cxt, 'prefix') let prefix = cxt['prefix'] call s:setopt('prefix', cxt['prefix']) @@ -281,11 +281,11 @@ function! sonictemplate#apply(name, mode, ...) abort if !buffer_is_not_empty let c = substitute(c, '{{_inline_}}\s*', '', 'g') if &expandtab || (&shiftwidth && &tabstop != &shiftwidth) - let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g') + let c = substitute(c, "\t", repeat(' ', shiftwidth()), 'g') endif silent! %d _ silent! put = c - silent! normal! ggdd + silent! normal! gg"_dd else if c[len(c)-1] == "\n" let c = c[:-2] @@ -295,7 +295,7 @@ function! sonictemplate#apply(name, mode, ...) abort let c = join(split(c, "\n"), "") let oldindentexpr = &indentexpr let &indentexpr = '' - silent! exe "normal! a\=c\" + noautocmd silent! exe "normal! a\=c\" let &indentexpr = oldindentexpr return else @@ -309,12 +309,12 @@ function! sonictemplate#apply(name, mode, ...) abort endif let c = indent . substitute(substitute(c, "\n", "\n".indent, 'g'), "\n".indent."\n", "\n\n", 'g') if len(indent) && (&expandtab || (&shiftwidth && &tabstop != &shiftwidth) || indent =~ '^ \+$') - let c = substitute(c, "\t", repeat(' ', min([len(indent), &shiftwidth])), 'g') + let c = substitute(c, "\t", repeat(' ', min([len(indent), shiftwidth()])), 'g') elseif &expandtab || (&shiftwidth && &tabstop != &shiftwidth) - let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g') + let c = substitute(c, "\t", repeat(' ', shiftwidth()), 'g') endif if line('.') < line('$') - silent! normal! dd + silent! normal! "_dd endif silent! put! =c endif @@ -354,9 +354,9 @@ function! sonictemplate#postfix() if c =~ "\n" let c = indent . substitute(substitute(c, "\n", "\n".indent, 'g'), "\n".indent."\n", "\n\n", 'g') if len(indent) && (&expandtab || (&shiftwidth && &tabstop != &shiftwidth) || indent =~ '^ \+$') - let c = substitute(c, "\t", repeat(' ', min([len(indent), &shiftwidth])), 'g') + let c = substitute(c, "\t", repeat(' ', min([len(indent), shiftwidth()])), 'g') elseif &expandtab || (&shiftwidth && &tabstop != &shiftwidth) - let c = substitute(c, "\t", repeat(' ', &shiftwidth), 'g') + let c = substitute(c, "\t", repeat(' ', shiftwidth()), 'g') endif call setline('.', line) if line('.') < line('$') @@ -367,7 +367,7 @@ function! sonictemplate#postfix() call setline('.', line) let oldindentexpr = &indentexpr let &indentexpr = '' - silent! exe "normal! a\=c\" + noautocmd silent! exe "normal! a\=c\" let &indentexpr = oldindentexpr endif if stridx(c, '{{_cursor_}}') != -1 diff --git a/template/c/base-socket-server.c b/template/c/base-socket-server.c index 4fed22e..5e41e40 100644 --- a/template/c/base-socket-server.c +++ b/template/c/base-socket-server.c @@ -1,5 +1,19 @@ #ifdef _WIN32 # include +# include +# include +static void +socket_perror(const char *s) { + CHAR buf[512]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + WSAGetLastError(), + 0, + buf, + sizeof(buf)/sizeof(buf[0]), + NULL); + printf("%s: %s", s, buf); +} #else # include # include @@ -8,6 +22,7 @@ # include # include #define closesocket(fd) close(fd) +#define socket_perror(s) perror(s) #endif int @@ -23,35 +38,35 @@ main(int argc, char* argv[]) { WSAStartup(MAKEWORD(2, 0), &wsa); #endif - if ((server_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { - perror("reader: socket"); + if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + socket_perror("reader: socket"); exit(1); } memset((char *) &reader_addr, 0, sizeof(reader_addr)); reader_addr.sin_family = PF_INET; reader_addr.sin_addr.s_addr = htonl(INADDR_ANY); - //reader_addr.sin_port = htons(8000); - reader_addr.sin_port = 0; + reader_addr.sin_port = htons(8000); if (bind(server_fd, (struct sockaddr *)&reader_addr, sizeof(reader_addr)) < 0) { - perror("reader: bind"); + socket_perror("reader: bind"); exit(1); } - size_t socklen = sizeof(reader_addr); + socklen_t socklen = sizeof(reader_addr); if (getsockname(server_fd, (struct sockaddr *)&reader_addr, &socklen) < 0) { - perror("reader: bind"); + socket_perror("getsockname: bind"); exit(1); } if (listen(server_fd, 5) < 0) { - perror("reader: listen"); - close(server_fd); + socket_perror("reader: listen"); + closesocket(server_fd); exit(1); } + writer_len = sizeof(writer_addr); if ((client_fd = accept(server_fd,(struct sockaddr *)&writer_addr, &writer_len)) < 0) { - perror("reader: accept"); + socket_perror("reader: accept"); exit(1); } @@ -62,7 +77,7 @@ main(int argc, char* argv[]) { if (n == 0) { break; } else if (n == -1) { - perror("recv"); + socket_perror("recv"); exit(EXIT_FAILURE); } else { send(client_fd, buf, n, 0); diff --git a/template/dockerfile/base-main.dockerfile b/template/dockerfile/base-main.dockerfile index de043d3..cc87523 100644 --- a/template/dockerfile/base-main.dockerfile +++ b/template/dockerfile/base-main.dockerfile @@ -1,4 +1,4 @@ FROM {{_input_:FROM_image}} -MAINTAINER {{_input_:author}} <{{_input_:email}}> +LABEL maintainer "{{_input_:author}} <{{_input_:email}}>" RUN {{_cursor_}} diff --git a/template/go/pattern.stpl b/template/go/pattern.stpl index 1fe0989..26ac4c6 100644 --- a/template/go/pattern.stpl +++ b/template/go/pattern.stpl @@ -56,3 +56,26 @@ \(\S.*\)\.spr\%[int]l\%[n]$ {{_cursor_}} fmt.Sprintln({{$1}}) + +\(\S\+\)\.func$ + func {{$1}} { + {{_cursor_}} + } + +\(\S\+\)\.struct$ + type {{$1}} struct { + {{_cursor_}} + } + +\(\S\+\)\.int$ + {{$1}} int + {{_cursor_}} + +\(\S\+\)\.string$ + {{$1}} string + {{_cursor_}} + +\(\S\+\)\.bool$ + {{$1}} bool + {{_cursor_}} + diff --git a/template/groovy/base-gradle-kotlin.gradle b/template/groovy/base-gradle-kotlin.gradle new file mode 100644 index 0000000..66898ea --- /dev/null +++ b/template/groovy/base-gradle-kotlin.gradle @@ -0,0 +1,22 @@ +buildscript { + ext { + kotlinVersion = '1.3.10' + } + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + } +} + +apply { + plugin 'kotlin' + plugin 'eclipse' + plugin 'idea' +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" + testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" +} diff --git a/template/java/pattern.stpl b/template/java/pattern.stpl index 2a48364..69ad725 100644 --- a/template/java/pattern.stpl +++ b/template/java/pattern.stpl @@ -9,3 +9,9 @@ \(\S.*\)\.pr\%[int]l\%[n]$ System.out.println({{$1}}); {{_cursor_}} + +\(\S.*\)\.false$ + assertFalse({{$1}});{{_cursor_}} + +\(\S.*\)\.true$ + assertTrue({{$1}});{{_cursor_}} diff --git a/template/scala/base-main.scala b/template/scala/base-main.scala new file mode 100644 index 0000000..f0ba3a5 --- /dev/null +++ b/template/scala/base-main.scala @@ -0,0 +1,6 @@ +object {{_name_}} { + def main(args: Array[String]): Unit = { + println("{{_cursor_}}") + } +} + diff --git a/template/typescript/base-class.ts b/template/typescript/base-class.ts new file mode 100644 index 0000000..f6acef4 --- /dev/null +++ b/template/typescript/base-class.ts @@ -0,0 +1,5 @@ +class {{_input_:name}} { + constructor({{_input_:parameters}}) { + {{_cursor_}} + } +} diff --git a/template/typescript/snip-class.ts b/template/typescript/snip-class.ts new file mode 100644 index 0000000..f6acef4 --- /dev/null +++ b/template/typescript/snip-class.ts @@ -0,0 +1,5 @@ +class {{_input_:name}} { + constructor({{_input_:parameters}}) { + {{_cursor_}} + } +} diff --git a/template/typescript/snip-ctor.ts b/template/typescript/snip-ctor.ts new file mode 100644 index 0000000..f77e911 --- /dev/null +++ b/template/typescript/snip-ctor.ts @@ -0,0 +1,7 @@ +/** + * + */ +constructor() { + super(); + {{_cursor_}} +} diff --git a/template/typescript/snip-dowhile.ts b/template/typescript/snip-dowhile.ts new file mode 100644 index 0000000..b9c2ac9 --- /dev/null +++ b/template/typescript/snip-dowhile.ts @@ -0,0 +1,3 @@ +do { + {{_cursor_}} +} while ({{_input_:condition}}); diff --git a/template/typescript/snip-endregion.ts b/template/typescript/snip-endregion.ts new file mode 100644 index 0000000..56ce7f5 --- /dev/null +++ b/template/typescript/snip-endregion.ts @@ -0,0 +1 @@ +//#endregion diff --git a/template/typescript/snip-error.ts b/template/typescript/snip-error.ts new file mode 100644 index 0000000..a520e5b --- /dev/null +++ b/template/typescript/snip-error.ts @@ -0,0 +1 @@ +console.error({{_cursor_}}); diff --git a/template/typescript/snip-for.ts b/template/typescript/snip-for.ts new file mode 100644 index 0000000..275290b --- /dev/null +++ b/template/typescript/snip-for.ts @@ -0,0 +1,4 @@ +for (let {{_input_:index}} = 0; {{_input_:index}} < {{_input_:array}}.length; {{_input_:index}}++) { + const {{_input_:element}} = {{_input_:array}}[{{_input_:index}}]; + {{_cursor_}} +} diff --git a/template/typescript/snip-foreach-lambda.ts b/template/typescript/snip-foreach-lambda.ts new file mode 100644 index 0000000..5c3ed8a --- /dev/null +++ b/template/typescript/snip-foreach-lambda.ts @@ -0,0 +1,3 @@ +{{_input_:array}}.forEach({{_input_:element}} => { + {{_cursor_}} +}); diff --git a/template/typescript/snip-forin.ts b/template/typescript/snip-forin.ts new file mode 100644 index 0000000..44ec674 --- /dev/null +++ b/template/typescript/snip-forin.ts @@ -0,0 +1,6 @@ +for (const {{_input_:key}} in {{_input_:object}}) { + if ({{_input_:object}}.hasOwnProperty({{_input_:key}})) { + const {{_input_:element}} = {{_input_:object}}[{{_input_:key}}]; + {{_cursor_}} + } +} diff --git a/template/typescript/snip-forof.ts b/template/typescript/snip-forof.ts new file mode 100644 index 0000000..70d6432 --- /dev/null +++ b/template/typescript/snip-forof.ts @@ -0,0 +1,3 @@ +for (const {{_input_:iterator}} of {{_input_:object}}) { + {{_cursor_}} +} diff --git a/template/typescript/snip-function.ts b/template/typescript/snip-function.ts new file mode 100644 index 0000000..efe355d --- /dev/null +++ b/template/typescript/snip-function.ts @@ -0,0 +1,3 @@ +function {{_input_:name}}({{_input_:params}}:{{_input_:type}}) { + {{_cursor_}} +} diff --git a/template/typescript/snip-get.ts b/template/typescript/snip-get.ts new file mode 100644 index 0000000..12fce22 --- /dev/null +++ b/template/typescript/snip-get.ts @@ -0,0 +1,5 @@ + +public get {{_input_:value}}() : {{_input_:string}} { + {{_input_:return {{_cursor_}}}} +} + diff --git a/template/typescript/snip-if.ts b/template/typescript/snip-if.ts new file mode 100644 index 0000000..8c0c27a --- /dev/null +++ b/template/typescript/snip-if.ts @@ -0,0 +1,3 @@ +if ({{_input_:condition}}) { + {{_cursor_}} +} diff --git a/template/typescript/snip-ifelse.ts b/template/typescript/snip-ifelse.ts new file mode 100644 index 0000000..7df2562 --- /dev/null +++ b/template/typescript/snip-ifelse.ts @@ -0,0 +1,5 @@ +if ({{_input_:condition}}) { + {{_cursor_}} +} else { + +} diff --git a/template/typescript/snip-import-statement.ts b/template/typescript/snip-import-statement.ts new file mode 100644 index 0000000..fbf67d0 --- /dev/null +++ b/template/typescript/snip-import-statement.ts @@ -0,0 +1 @@ +import { {{_cursor_}} } from "{{_input_:module}}"; diff --git a/template/typescript/snip-log.ts b/template/typescript/snip-log.ts new file mode 100644 index 0000000..dbd5b94 --- /dev/null +++ b/template/typescript/snip-log.ts @@ -0,0 +1 @@ +console.log({{_cursor_}}); diff --git a/template/typescript/snip-new.ts b/template/typescript/snip-new.ts new file mode 100644 index 0000000..0a4c8ea --- /dev/null +++ b/template/typescript/snip-new.ts @@ -0,0 +1 @@ +const {{_input_:name}} = new {{_input_:type}}({{_input_:arguments}});{{_cursor_}} diff --git a/template/typescript/snip-private-method.ts b/template/typescript/snip-private-method.ts new file mode 100644 index 0000000..f23dbb0 --- /dev/null +++ b/template/typescript/snip-private-method.ts @@ -0,0 +1,3 @@ +private {{_input_:name}}() { + {{_cursor_}} +} diff --git a/template/typescript/snip-prop.ts b/template/typescript/snip-prop.ts new file mode 100644 index 0000000..7d8933e --- /dev/null +++ b/template/typescript/snip-prop.ts @@ -0,0 +1,9 @@ + +private _{{_input_:value}} : {{_input_:string}}; +public get {{_input_:value}}() : {{_input_:string}} { + return this._{{_input_:value}}; +} +public set {{_input_:value}}(v : {{_input_:string}}) { + this._{{_input_:value}} = v; +} + diff --git a/template/typescript/snip-public-method.ts b/template/typescript/snip-public-method.ts new file mode 100644 index 0000000..7191874 --- /dev/null +++ b/template/typescript/snip-public-method.ts @@ -0,0 +1,6 @@ +/** + * {{_input_:name}} + */ +public {{_input_:name}}() { + {{_cursor_}} +} diff --git a/template/typescript/snip-ref.ts b/template/typescript/snip-ref.ts new file mode 100644 index 0000000..83eee32 --- /dev/null +++ b/template/typescript/snip-ref.ts @@ -0,0 +1 @@ +/// diff --git a/template/typescript/snip-region.ts b/template/typescript/snip-region.ts new file mode 100644 index 0000000..45bd931 --- /dev/null +++ b/template/typescript/snip-region.ts @@ -0,0 +1 @@ +//#region {{_cursor_}} diff --git a/template/typescript/snip-set.ts b/template/typescript/snip-set.ts new file mode 100644 index 0000000..974dab1 --- /dev/null +++ b/template/typescript/snip-set.ts @@ -0,0 +1,5 @@ + +public set {{_input_:value}}(v : {{_input_:string}}) { + this.{{_cursor_}} = v; +} + diff --git a/template/typescript/snip-settimeout.ts b/template/typescript/snip-settimeout.ts new file mode 100644 index 0000000..ee2c258 --- /dev/null +++ b/template/typescript/snip-settimeout.ts @@ -0,0 +1,3 @@ +setTimeout(() => { + {{_cursor_}} +}, {{_input_:timeout}}); diff --git a/template/typescript/snip-switch.ts b/template/typescript/snip-switch.ts new file mode 100644 index 0000000..625208e --- /dev/null +++ b/template/typescript/snip-switch.ts @@ -0,0 +1,8 @@ +switch ({{_input_:key}}) { + case {{_input_:value}}: + {{_cursor_}} + break; + + default: + break; +} diff --git a/template/typescript/snip-throw.ts b/template/typescript/snip-throw.ts new file mode 100644 index 0000000..86ca9f6 --- /dev/null +++ b/template/typescript/snip-throw.ts @@ -0,0 +1 @@ +throw "{{_cursor_}}"; diff --git a/template/typescript/snip-trycatch.ts b/template/typescript/snip-trycatch.ts new file mode 100644 index 0000000..9d8b2de --- /dev/null +++ b/template/typescript/snip-trycatch.ts @@ -0,0 +1,5 @@ +try { + {{_cursor_}} +} catch ({{_input_:error}}) { + +} diff --git a/template/typescript/snip-warn.ts b/template/typescript/snip-warn.ts new file mode 100644 index 0000000..213eecc --- /dev/null +++ b/template/typescript/snip-warn.ts @@ -0,0 +1 @@ +console.warn({{_cursor_}}); diff --git a/template/typescript/snip-while.ts b/template/typescript/snip-while.ts new file mode 100644 index 0000000..55d9298 --- /dev/null +++ b/template/typescript/snip-while.ts @@ -0,0 +1,3 @@ +while ({{_input_:condition}}) { + {{_cursor_}} +} -- cgit v1.2.3-54-g00ecf From df67b9647f8d5b75cc72d8d7d6054bdf8c2efad1 Mon Sep 17 00:00:00 2001 From: mityu Date: Tue, 21 Jan 2020 12:02:41 +0900 Subject: Fix expanding {{_cursor_}} does not work in insertmode --- autoload/sonictemplate.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 15fac9a..31492fe 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -322,7 +322,9 @@ function! sonictemplate#apply(name, mode, ...) abort if stridx(c, '{{_cursor_}}') != -1 silent! call search('\zs{{_cursor_}}', 'w') silent! foldopen + let curpos = getpos('.') silent! normal! "_da} + call setpos('.', curpos) endif endfunction @@ -373,7 +375,9 @@ function! sonictemplate#postfix() if stridx(c, '{{_cursor_}}') != -1 silent! call search('\zs{{_cursor_}}', 'w') silent! foldopen + let curpos = getpos('.') silent! normal! "_da} + call setpos('.', curpos) endif break endif -- cgit v1.2.3-54-g00ecf