Skip to content

Instantly share code, notes, and snippets.

@petdance
Created March 20, 2019 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petdance/992edef4f81dd9518400a280472cc1c4 to your computer and use it in GitHub Desktop.
Save petdance/992edef4f81dd9518400a280472cc1c4 to your computer and use it in GitHub Desktop.
This update to syntax/perl.vim broke indenting
This update to my syntax/perl.vim made auto indenting break.
If I type
sub foo {
and then hit return, the cursor used to move to the next line and be indented 4 spaces. This is no longer the case.
Index: syntax/perl.vim
===================================================================
--- syntax/perl.vim (revision 7495)
+++ syntax/perl.vim (working copy)
@@ -3,6 +3,7 @@
" Maintainer: vim-perl <vim-perl@googlegroups.com>
" Homepage: http://github.com/vim-perl/vim-perl/tree/master
" Bugs/requests: http://github.com/vim-perl/vim-perl/issues
+" License: Vim License (see :help license)
" Last Change: {{LAST_CHANGE}}
" Contributors: Andy Lester <andy@petdance.com>
" Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
@@ -167,7 +168,7 @@
syn match perlPackageConst "__PACKAGE__" nextgroup=perlPostDeref
syn match perlPostDeref "->\%($#\|[$@%&*]\)\*" contained nextgroup=perlVarSimpleMember,perlVarMember,perlPostDeref
syn region perlPostDeref start="->\%($#\|[$@%&*]\)\[" skip="\\]" end="]" contained contains=@perlExpr nextgroup=perlVarSimpleMember,perlVarMember,perlPostDeref
- syn region perlPostDeref matchgroup=perlPostDeref start="->\%($#\|[$@%&*]\){" skip="\\}" end="}" contained contains=@perlExpr nextgroup=perlVarSimpleMember,perlVarMember,perlPostDeref
+ syn region perlPostDeref matchgroup=perlPostDeref start="->\%($#\|[$@%&*]\){" skip="\\}" end="}" keepend extend contained contains=@perlExpr nextgroup=perlVarSimpleMember,perlVarMember,perlPostDeref
endif
" File Descriptors
@@ -379,25 +380,16 @@
syn keyword perlStatementPackage package contained
" Functions
-" sub [name] [(prototype)] {
-"
-syn match perlSubError "[^[:space:];{#]" contained
-syn match perlSubAttributesCont "\h\w*\_s*\%(:\_s*\)\=" nextgroup=@perlSubAttrMaybe contained
-syn region perlSubAttributesCont matchgroup=perlSubAttributesCont start="\h\w*(" end=")\_s*\%(:\_s*\)\=" nextgroup=@perlSubAttrMaybe contained contains=@perlInterpSQ,perlParensSQ
-syn cluster perlSubAttrMaybe contains=perlSubAttributesCont,perlSubError,perlFakeGroup
-syn match perlSubAttributes "" contained nextgroup=perlSubError
-syn match perlSubAttributes ":\_s*" contained nextgroup=@perlSubAttrMaybe
if get(g:, "perl_sub_signatures", 0)
- syn match perlSignature +(\_[^)]*)\_s*+ nextgroup=perlSubAttributes,perlComment contained
+ syn match perlSubSignature "\s*([^)]*)" contained extend
else
- syn match perlSubPrototypeError "(\%(\_s*\%(\%(\\\%([$@%&*]\|\[[$@%&*]\+\]\)\|[$&*]\|[@%]\%(\_s*)\)\@=\|;\%(\_s*[)$@%&*\\]\)\@=\|_\%(\_s*[);]\)\@=\)\_s*\)*\)\@>\zs\_[^)]\+" contained
- syn match perlSubPrototype +(\_[^)]*)\_s*+ nextgroup=perlSubAttributes,perlComment contained contains=perlSubPrototypeError
+ syn match perlSubPrototype "\s*([\\$@%&*\[\];]*)" contained extend
endif
+syn match perlSubAttribute "\s*:\s*\h\w*\%(([^)]*)\|\)" contained extend
+syn match perlSubName "\%(\h\|::\|'\w\)\%(\w\|::\|'\w\)*\s*" contained extend
+syn region perlSubDeclaration start="" end="[;{]" contains=perlSubName,perlSubPrototype,perlSubAttribute,perlSubSignature,perlComment contained transparent
+syn match perlFunction "\<sub\>\_s*" nextgroup=perlSubDeclaration
-syn match perlSubName +\%(\h\|::\|'\w\)\%(\w\|::\|'\w\)*\_s*\|+ contained nextgroup=perlSubPrototype,perlSignature,perlSubAttributes,perlComment
-
-syn match perlFunction +\<sub\>\_s*+ nextgroup=perlSubName
-
" The => operator forces a bareword to the left of it to be interpreted as
" a string
syn match perlString "\I\@<!-\?\I\i*\%(\s*=>\)\@="
@@ -426,7 +418,6 @@
"
" Folding
-
if get(g:, 'perl_fold', 0)
" Note: this bit must come before the actual highlighting of the "package"
" keyword, otherwise this will screw up Pod lines that match /^package/
@@ -436,17 +427,35 @@
endif
if !get(g:, 'perl_nofold_subs', 0)
if get(g:, "perl_fold_anonymous_subs", 0)
- syn region perlSubFold start="\<sub\>[^{]*{" end="}" transparent fold keepend extend
- syn region perlSubFold start="\<\%(BEGIN\|END\|CHECK\|INIT\)\>\s*{" end="}" transparent fold keepend
+ " EXPLANATION:
+ " \<sub\> - "sub" keyword
+ " \_[^;{]* - any characters, including new line, but not ";" or "{", zero or more times
+ " \%(([\\$@%&*\[\];]*)\)\= - prototype definition, \$@%&*[]; characters between (), zero or 1 times
+ " \_[^;]* - any characters, including new line, but not ";" or "{", zero or more times
+ " { - start subroutine block
+ syn region perlSubFold start="\<sub\>\_[^;{]*\%(([\\$@%&*\[\];]*)\)\=\_[^;{]*{" end="}" transparent fold keepend extend
else
- syn region perlSubFold start="^\z(\s*\)\<sub\>.*[^};]$" end="^\z1}\s*\%(#.*\)\=$" transparent fold keepend
- syn region perlSubFold start="^\z(\s*\)\<\%(BEGIN\|END\|CHECK\|INIT\|UNITCHECK\)\>.*[^};]$" end="^\z1}\s*$" transparent fold keepend
+ " EXPLANATION:
+ " same, as above, but first non-space character after "sub" keyword must
+ " be [A-Za-z_]
+ syn region perlSubFold start="\<sub\>\s*\h\_[^;{]*\%(([\\$@%&*\[\];]*)\)\=\_[^;]*{" end="}" transparent fold keepend extend
endif
+
+ syn region perlSubFold start="\<\%(BEGIN\|END\|CHECK\|INIT\|UNITCHECK\)\>\_s*{" end="}" transparent fold keepend
endif
if get(g:, 'perl_fold_blocks', 0)
syn region perlBlockFold start="^\z(\s*\)\%(if\|elsif\|unless\|for\|while\|until\|given\)\s*(.*)\%(\s*{\)\=\s*\%(#.*\)\=$" start="^\z(\s*\)for\%(each\)\=\s*\%(\%(my\|our\)\=\s*\S\+\s*\)\=(.*)\%(\s*{\)\=\s*\%(#.*\)\=$" end="^\z1}\s*;\=\%(#.*\)\=$" transparent fold keepend
+
+ " TODO this is works incorrectly
syn region perlBlockFold start="^\z(\s*\)\%(do\|else\)\%(\s*{\)\=\s*\%(#.*\)\=$" end="^\z1}\s*while" end="^\z1}\s*;\=\%(#.*\)\=$" transparent fold keepend
+ else
+ if get(g:, 'perl_fold_do_blocks', 0)
+ syn region perlDoBlockDeclaration start="" end="{" contains=perlComment contained transparent
+ syn match perlOperator "\<do\>\_s*" nextgroup=perlDoBlockDeclaration
+
+ syn region perlDoBlockFold start="\<do\>\_[^{]*{" end="}" transparent fold keepend extend
+ endif
endif
syn sync fromstart
@@ -477,9 +486,8 @@
hi def link perlFunction Keyword
hi def link perlSubName Function
hi def link perlSubPrototype Type
-hi def link perlSignature Type
-hi def link perlSubAttributes PreProc
-hi def link perlSubAttributesCont perlSubAttributes
+hi def link perlSubSignature Type
+hi def link perlSubAttribute PreProc
hi def link perlComment Comment
hi def link perlTodo Todo
if get(g:, 'perl_string_as_statement', 0)
@@ -570,8 +578,6 @@
" Possible errors
hi def link perlNotEmptyLine Error
hi def link perlElseIfError Error
-hi def link perlSubPrototypeError Error
-hi def link perlSubError Error
" Syncing to speed up processing
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment