Created
September 2, 2009 18:11
-
-
Save hinrik/179863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /usr/share/vim/vim72/filetype.vim 2009-09-02 18:49:03.650027278 +0000 | |
+++ filetype.vim 2009-09-02 18:48:51.730210021 +0000 | |
@@ -1264,6 +1264,7 @@ | |
au BufNewFile,BufRead *.pl call s:FTpl() | |
endif | |
au BufNewFile,BufRead *.plx setf perl | |
+au BufNewFile,BufRead *.p6 setf perl6 | |
func! s:FTpl() | |
if exists("g:filetype_pl") | |
@@ -1275,7 +1276,7 @@ | |
if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-' | |
setf prolog | |
else | |
- setf perl | |
+ call s:FTperl5or6() | |
endif | |
endif | |
endfunc | |
@@ -1287,11 +1288,34 @@ | |
\ elseif getline(1) =~ "XPM" | | |
\ setf xpm | | |
\ else | | |
- \ setf perl | | |
+ \ call s:FTperl5or6() | | |
\ endif | |
" Perl POD | |
-au BufNewFile,BufRead *.pod setf pod | |
+au BufNewFile,BufRead *.pod call s:FTpod5or6() | |
+ | |
+func! s:FTpod5or6() | |
+ for line_nr in range(1, 30) | |
+ let pod_line = getline(line_nr) | |
+ if pod_line =~ '^\s*=' | |
+ if pod_line =~# '^\s*=encoding' | |
+ " =encoding is ambiguous, skip over it | |
+ elseif pod_line =~# '^\s*=\%(pod\>\|head\d\|over\>\|item\>\)' | |
+ " Pod 5 usually starts with one of these | |
+ setf pod | |
+ return 1 | |
+ else | |
+ " Pod 6 is more likely to start with =begin, =for, etc | |
+ setf perl6 | |
+ return 1 | |
+ endif | |
+ endif | |
+ endfor | |
+ " no Pod directive in first 30 lines? default to new Pod | |
+ setf perl6 | |
+ return 1 | |
+endfunc | |
" Php, php3, php4, etc. | |
" Also Phtml (was used for PHP 2 in the past) | |
@@ -1923,20 +1947,40 @@ | |
" a Perl file. | |
func! s:FTperl() | |
if expand("%:e") == 't' && expand("%:p:h:t") == 't' | |
- setf perl | |
+ call s:FTperl5or6() | |
return 1 | |
endif | |
if getline(1)[0] == '#' && getline(1) =~ 'perl' | |
- setf perl | |
+ call s:FTperl5or6() | |
return 1 | |
endif | |
if search('^use\s\s*\k', 'nc', 30) | |
- setf perl | |
+ call s:FTperl5or6() | |
return 1 | |
endif | |
return 0 | |
endfunc | |
+" If the first line of code starts with "use v6", "grammar", "module", | |
+" "class", or "role" then it's Perl 6, otherwise it's Perl 5 | |
+func! s:FTperl5or6() | |
+ for line_nr in range(1, 30) | |
+ let perl_line = getline(line_nr) | |
+ if perl_line =~ '^\s*[^#]' | |
+ " check if the first line of code is Perl 6 | |
+ if perl_line =~# '^\s*\%(use\s*v6\|\%(grammar\|module\|class\|role\)\>\)' | |
+ setf perl6 | |
+ return 1 | |
+ else | |
+ break | |
+ endif | |
+ endif | |
+ endfor | |
+ " default to Perl 5 | |
+ setf perl | |
+ return 1 | |
+endfunc | |
+ | |
" Tads (or Nroff or Perl test file) | |
au BufNewFile,BufRead *.t | |
\ if !s:FTnroff() && !s:FTperl() | setf tads | endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment