Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7801e3c

Browse files
authored
Update perl snippets (rafamadriz#460)
* include perl in package.json to trigger perl snippets* fixed/updated some perl snippets* Escape $$ and $! occurrences* With native neovim snippets $0 is buggyOk, apologies for multiple commits, but $0 placement is very buggy in neovim native snippets usage. The placeholder text for ${0:placeholder text} is not replaced when you actually start typing at that location. Instead of waiting for a fix in neovim, native-snippets.nvim or whatever tool, I'd rather just work around this in the snippets I'm writing.* fix join command
1 parente11b09b commit7801e3c

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

‎package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@
505505
"language":"tcl",
506506
"path":"./snippets/tcl.json"
507507
},
508+
{
509+
"language":"perl",
510+
"path":"./snippets/perl.json"
511+
},
508512
{
509513
"language":"verilog",
510514
"path":"./snippets/verilog.json"

‎snippets/perl.json‎

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
},
66
"if statement": {
77
"prefix":"if",
8-
"body": ["if ( ${1:condition} ) {","\t${0:body}","}"]
8+
"body": ["if ( ${1:condition} ) {","\t${2:body}","}"]
99
},
1010
"if else statement": {
1111
"prefix":"ife",
1212
"body": [
1313
"if ( ${1:condition} ) {",
1414
"\t${2:body}",
1515
"} else {",
16-
"\t${0:body}",
16+
"\t${3:body}",
1717
"}"
1818
]
1919
},
@@ -23,48 +23,48 @@
2323
"if ( ${1:condition} ) {",
2424
"\t${2:body}",
2525
"} elsif ( ${3:condition} ) {",
26-
"\t${0:body}",
26+
"\t${3:body}",
2727
"}"
2828
]
2929
},
3030
"else statement": {
3131
"prefix":"else",
32-
"body": ["else {","\t${0:body}","}"]
32+
"body": ["else {","\t${1:body}","}"]
3333
},
3434
"elsif statement": {
3535
"prefix":"elsif",
36-
"body": ["elsif ( ${1:condition} ) {","\t${0:body}","}"]
36+
"body": ["elsif ( ${1:condition} ) {","\t${2:body}","}"]
3737
},
3838
"unless": {
3939
"prefix":"unless",
40-
"body": ["unless ( ${1:condition} ) {","\t${0:body}","}"]
40+
"body": ["unless ( ${1:condition} ) {","\t${2:body}","}"]
4141
},
4242
"for loop": {
4343
"prefix":"for",
4444
"body": [
45-
"for (my $${1:loop var} = 0; $$1 < ${2:count}; $$1++) {",
46-
"\t${0:body}",
45+
"for (my\\$${1:loop var} = 0;\\$$1 < ${2:count};\\$$1++) {",
46+
"\t${3:body}",
4747
"}"
4848
]
4949
},
5050
"foreach loop": {
5151
"prefix":"foreach",
52-
"body": ["foreach my $${1:element} ( @${2:array} ) {","\t${0:body}","}"]
52+
"body": ["foreach my\\$${1:element} ( @${2:array} ) {","\t${3:body}","}"]
5353
},
5454
"while Loop": {
5555
"prefix":"while",
56-
"body": ["while ( ${1:condition} ) {","\t${0:body}","}"]
56+
"body": ["while ( ${1:condition} ) {","\t${2:body}","}"]
5757
},
5858
"do while Loop": {
5959
"prefix":"dowhile",
60-
"body": ["do {","\t${0:body}","} while ( ${1:condition} );"]
60+
"body": ["do {","\t${2:body}","} while ( ${1:condition} );"]
6161
},
6262
"subroutine": {
6363
"prefix":"sub",
64-
"body": ["sub ${1:subroutine name} {","\t${0:subbody}","}"]
64+
"body": ["sub ${1:sub_name} {","\t${2:body}","}"]
6565
},
6666
"Comment block for subroutine": {
67-
"prefix":"#subdocumentation",
67+
"prefix":"documentation",
6868
"body": [
6969
"################################################################################",
7070
"#",
@@ -81,39 +81,40 @@
8181
"open file to read": {
8282
"prefix":"openr",
8383
"body": [
84-
"open(my $${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading: $!\";"
84+
"open(my\\$${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading:\\$!\";"
8585
]
8686
},
8787
"open file to write": {
8888
"prefix":"openw",
8989
"body": [
90-
"open(my $${1:fh}, '>',\"${2:file name}\") or die\"Cannot open file '$2' for writing: $!\";"
90+
"open(my\\$${1:fh}, '>',\"${2:file name}\") or die\"Cannot open file '$2' for writing:\\$!\";"
9191
]
9292
},
9393
"print to file": {
9494
"prefix":"file print",
95-
"body": ["print${1:fh}\"$2\\n\";"]
95+
"body": ["print\\$${1:fh}\"${1:string}\\n\";"]
9696
},
9797
"read file into a scalar": {
9898
"prefix":"slurp",
9999
"body": [
100-
"local $/;",
101-
"open(my $${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading: $!\";",
102-
"my $${3:contents} = <$$1>;",
103-
"close($$1);"
100+
"use File::Slurp;",
101+
"",
102+
"my\\$${1:contents} = read_file(\"${2:file_path}\")"
104103
]
105104
},
106105
"read a directory": {
107106
"prefix":"readdir",
108107
"body": [
109-
"opendir(my$$dir, '$1') or die\"Cannot open directory '$1': $!\";",
110-
"my @files = readdir($$dir);",
111-
"closedir($$dir);"
108+
"opendir(my\\$${1:dir}, '$2') or die\"Cannot open directory '$2':\\$!\";",
109+
"my @files = readdir(\\$$1);",
110+
"closedir(\\$$1);"
112111
]
113112
},
114113
"create a directory": {
115114
"prefix":"mkdir",
116-
"body": ["mkdir\"${1:dir}\" or die\"Cannot create directory '$1': $!\";"]
115+
"body": [
116+
"mkdir\"${1:dir}\" or die\"Cannot create directory '$1':\\$!\";"
117+
]
117118
},
118119
"split a string": {
119120
"prefix":"split",
@@ -124,7 +125,7 @@
124125
"join array": {
125126
"prefix":"join",
126127
"body": [
127-
"my $${1:string var} = join('${2:delimiter pattern}', @${3:array var});"
128+
"my\\$${1:string var} = join('${2:delimiter pattern}', @${3:array_var});"
128129
]
129130
},
130131
"format time": {
@@ -138,29 +139,36 @@
138139
"prefix":"trycatch",
139140
"body": [
140141
"use Try::Tiny;",
142+
"",
141143
"try {",
142-
"\t${0:body}",
144+
"\t${1:body}",
143145
"} catch {",
144-
"\tmy $${1:err} = shift;",
145-
"\tprint\"Error: $$1\\n\";",
146+
"\tmy\\$catch_error = shift;",
147+
"\tprint\"Error:\\$catch_error\\n\";",
148+
"} finally {",
149+
"\tif (@_) {",
150+
"\t\tprint\"The try block died with error: @_\\n\"",
151+
"\t} else {",
152+
"\t\tprint\"The try ran successfully.\\n\"",
153+
"\t}",
146154
"};"
147155
]
148156
},
149157
"perl module": {
150-
"prefix":"perlmod",
158+
"prefix":"module package",
151159
"body": [
152160
"package ${1:ModuleName};",
153161
"use strict;",
154162
"use warnings;",
155163
"",
156164
"sub new {",
157-
"\tmy ($$class, %args) = @_;",
158-
"\tmy$$self = bless {%args},$$class;",
159-
"\treturn$$self;",
165+
"\tmy (\\$class, %args) = @_;",
166+
"\tmy\\$self = bless {%args},\\$class;",
167+
"\treturn\\$self;",
160168
"}",
161169
"",
162170
"# Add more methods here",
163-
"$0",
171+
"$2",
164172
"",
165173
"1; # Return true to indicate successful module loading"
166174
]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp