Mercurial > vim
annotate runtime/autoload/dist/ft.vim @ 27972:9c0b7953016e v8.2.4511
patch 8.2.4511: filetype test fails
Commit: https://github.com/vim/vim/commit/c12dc47b8f80c02e4fdcdb38b8217e1c06a11368
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 5 13:45:56 2022 +0000
patch 8.2.4511: filetype test fails
Problem: Filetype test fails.
Solution: Change "endw" to "endwhile".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Mar 2022 15:00:03 +0100 |
parents | d19b7aee1925 |
children | c968191a8557 |
rev | line source |
---|---|
27537 | 1 vim9script |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
27537 | 3 # Vim functions for file type detection |
4 # | |
5 # Maintainer: Bram Moolenaar <Bram@vim.org> | |
27903 | 6 # Last Change: 2022 Feb 22 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 |
27537 | 8 # These functions are moved here from runtime/filetype.vim to make startup |
9 # faster. | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 |
27537 | 11 export def Check_inp() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 if getline(1) =~ '^\*' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 setf abaqus |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 else |
27537 | 15 var n = 1 |
16 var nmax = line("$") > 500 ? 500 : line("$") | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 while n <= nmax |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 if getline(n) =~? "^header surface data" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 setf trasys |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 break |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 endif |
27537 | 22 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 endif |
27537 | 25 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 |
27537 | 27 # This function checks for the kind of assembly that is wanted by the user, or |
28 # can be detected from the first five lines of the file. | |
29 export def FTasm() | |
30 # make sure b:asmsyntax exists | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 if !exists("b:asmsyntax") |
27537 | 32 b:asmsyntax = "" |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 if b:asmsyntax == "" |
27537 | 36 FTasmsyntax() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 |
27537 | 39 # if b:asmsyntax still isn't set, default to asmsyntax or GNU |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 if b:asmsyntax == "" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 if exists("g:asmsyntax") |
27537 | 42 b:asmsyntax = g:asmsyntax |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 else |
27537 | 44 b:asmsyntax = "asm" |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 |
27537 | 48 exe "setf " .. fnameescape(b:asmsyntax) |
49 enddef | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 |
27537 | 51 export def FTasmsyntax() |
52 # see if the file contains any asmsyntax=foo overrides. If so, change | |
53 # b:asmsyntax appropriately | |
54 var head = " " .. getline(1) .. " " .. getline(2) .. " " | |
55 .. getline(3) .. " " .. getline(4) .. " " .. getline(5) .. " " | |
56 var match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s') | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 if match != '' |
27537 | 58 b:asmsyntax = match |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
59 elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library')) |
27537 | 60 b:asmsyntax = "vmasm" |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 endif |
27537 | 62 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 |
27537 | 64 var ft_visual_basic_content = '\cVB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)' |
27493
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
65 |
27537 | 66 # See FTfrm() for Visual Basic form file detection |
67 export def FTbas() | |
27287
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
68 if exists("g:filetype_bas") |
27537 | 69 exe "setf " .. g:filetype_bas |
27287
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
70 return |
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
71 endif |
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
72 |
27537 | 73 # most frequent FreeBASIC-specific keywords in distro files |
74 var fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!' | |
75 var fb_preproc = '\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)' | |
76 var fb_comment = "^\\s*/'" | |
77 # OPTION EXPLICIT, without the leading underscore, is common to many dialects | |
78 var qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)' | |
27287
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
79 |
27537 | 80 var lines = getline(1, min([line("$"), 100])) |
27287
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
81 |
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
82 if match(lines, fb_preproc) > -1 || match(lines, fb_comment) > -1 || match(lines, fb_keywords) > -1 |
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
83 setf freebasic |
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
84 elseif match(lines, qb64_preproc) > -1 |
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
85 setf qb64 |
27845
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
86 elseif match(lines, ft_visual_basic_content) > -1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 setf vb |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 else |
27287
9f72ec92d361
patch 8.2.4172: filetype detection for BASIC is not optimal
Bram Moolenaar <Bram@vim.org>
parents:
27162
diff
changeset
|
89 setf basic |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
90 endif |
27537 | 91 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
92 |
27537 | 93 export def FTbtm() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
94 if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
95 setf dosbatch |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
96 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
97 setf btm |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
98 endif |
27537 | 99 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
100 |
27537 | 101 export def BindzoneCheck(default = '') |
102 if getline(1) .. getline(2) .. getline(3) .. getline(4) | |
103 =~ '^; <<>> DiG [0-9.]\+.* <<>>\|$ORIGIN\|$TTL\|IN\s\+SOA' | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
104 setf bindzone |
27537 | 105 elseif default != '' |
106 exe 'setf ' .. default | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
107 endif |
27537 | 108 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
109 |
27537 | 110 export def FTlpc() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
111 if exists("g:lpc_syntax_for_c") |
27537 | 112 var lnum = 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
113 while lnum <= 12 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
114 if getline(lnum) =~# '^\(//\|inherit\|private\|protected\|nosave\|string\|object\|mapping\|mixed\)' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
115 setf lpc |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
116 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
117 endif |
27537 | 118 lnum += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
119 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
120 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
121 setf c |
27537 | 122 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
123 |
27537 | 124 export def FTheader() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
125 if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
126 if exists("g:c_syntax_for_h") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
127 setf objc |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
128 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
129 setf objcpp |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
130 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
131 elseif exists("g:c_syntax_for_h") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
132 setf c |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
133 elseif exists("g:ch_syntax_for_h") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
134 setf ch |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
135 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
136 setf cpp |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
137 endif |
27537 | 138 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
139 |
27537 | 140 # This function checks if one of the first ten lines start with a '@'. In |
141 # that case it is probably a change file. | |
142 # If the first line starts with # or ! it's probably a ch file. | |
143 # If a line has "main", "include", "//" or "/*" it's probably ch. | |
144 # Otherwise CHILL is assumed. | |
145 export def FTchange() | |
146 var lnum = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 while lnum <= 10 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
148 if getline(lnum)[0] == '@' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 setf change |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
150 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
152 if lnum == 1 && (getline(1)[0] == '#' || getline(1)[0] == '!') |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
153 setf ch |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
154 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
155 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
156 if getline(lnum) =~ "MODULE" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
157 setf chill |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
158 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
159 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
160 if getline(lnum) =~ 'main\s*(\|#\s*include\|//' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
161 setf ch |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
163 endif |
27537 | 164 lnum += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 setf chill |
27537 | 167 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 |
27537 | 169 export def FTent() |
170 # This function checks for valid cl syntax in the first five lines. | |
171 # Look for either an opening comment, '#', or a block start, '{". | |
172 # If not found, assume SGML. | |
173 var lnum = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 while lnum < 6 |
27537 | 175 var line = getline(lnum) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
176 if line =~ '^\s*[#{]' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
177 setf cl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
178 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 elseif line !~ '^\s*$' |
27537 | 180 # Not a blank line, not a comment, and not a block start, |
181 # so doesn't look like valid cl code. | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
182 break |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 endif |
27537 | 184 lnum += 1 |
27972
9c0b7953016e
patch 8.2.4511: filetype test fails
Bram Moolenaar <Bram@vim.org>
parents:
27903
diff
changeset
|
185 endwhile |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
186 setf dtd |
27537 | 187 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
188 |
27537 | 189 export def ExCheck() |
190 var lines = getline(1, min([line("$"), 100])) | |
25026
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
191 if exists('g:filetype_euphoria') |
27537 | 192 exe 'setf ' .. g:filetype_euphoria |
25026
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
193 elseif match(lines, '^--\|^ifdef\>\|^include\>') > -1 |
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
194 setf euphoria3 |
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
195 else |
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
196 setf elixir |
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
197 endif |
27537 | 198 enddef |
25026
fda44c0b4b7b
patch 8.2.3050: cannot recognize elixir files
Bram Moolenaar <Bram@vim.org>
parents:
23584
diff
changeset
|
199 |
27537 | 200 export def EuphoriaCheck() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
201 if exists('g:filetype_euphoria') |
27537 | 202 exe 'setf ' .. g:filetype_euphoria |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
203 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
204 setf euphoria3 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
205 endif |
27537 | 206 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 |
27537 | 208 export def DtraceCheck() |
27877
834d3fba1e7c
patch 8.2.4464: Dtrace files are recognized as filetype D
Bram Moolenaar <Bram@vim.org>
parents:
27845
diff
changeset
|
209 if did_filetype() |
834d3fba1e7c
patch 8.2.4464: Dtrace files are recognized as filetype D
Bram Moolenaar <Bram@vim.org>
parents:
27845
diff
changeset
|
210 # Filetype was already detected |
834d3fba1e7c
patch 8.2.4464: Dtrace files are recognized as filetype D
Bram Moolenaar <Bram@vim.org>
parents:
27845
diff
changeset
|
211 return |
834d3fba1e7c
patch 8.2.4464: Dtrace files are recognized as filetype D
Bram Moolenaar <Bram@vim.org>
parents:
27845
diff
changeset
|
212 endif |
27537 | 213 var lines = getline(1, min([line("$"), 100])) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
214 if match(lines, '^module\>\|^import\>') > -1 |
27537 | 215 # D files often start with a module and/or import statement. |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
216 setf d |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
217 elseif match(lines, '^#!\S\+dtrace\|#pragma\s\+D\s\+option\|:\S\{-}:\S\{-}:') > -1 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
218 setf dtrace |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
220 setf d |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
221 endif |
27537 | 222 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
223 |
27537 | 224 export def FTe() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
225 if exists('g:filetype_euphoria') |
27537 | 226 exe 'setf ' .. g:filetype_euphoria |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 else |
27537 | 228 var n = 1 |
16024
7fd3a9eaeedb
patch 8.1.1017: off-by-one error in filetype detection
Bram Moolenaar <Bram@vim.org>
parents:
15527
diff
changeset
|
229 while n < 100 && n <= line("$") |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
230 if getline(n) =~ "^\\s*\\(<'\\|'>\\)\\s*$" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
231 setf specman |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
232 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 endif |
27537 | 234 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 setf eiffel |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 endif |
27537 | 238 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 |
27537 | 240 export def FTfrm() |
27493
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
241 if exists("g:filetype_frm") |
27537 | 242 exe "setf " .. g:filetype_frm |
27493
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
243 return |
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
244 endif |
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
245 |
27537 | 246 var lines = getline(1, min([line("$"), 5])) |
27493
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
247 |
27845
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
248 if match(lines, ft_visual_basic_content) > -1 |
27493
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
249 setf vb |
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
250 else |
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
251 setf form |
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
252 endif |
27537 | 253 enddef |
27493
3af3dee7e5d9
patch 8.2.4274: Basic and form filetype detection is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
254 |
27537 | 255 # Distinguish between Forth and F#. |
256 # Provided by Doug Kearns. | |
257 export def FTfs() | |
26311
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
258 if exists("g:filetype_fs") |
27537 | 259 exe "setf " .. g:filetype_fs |
26311
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
260 else |
27537 | 261 var line = getline(nextnonblank(1)) |
262 # comments and colon definitions | |
26311
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
263 if line =~ '^\s*\.\=( ' || line =~ '^\s*\\G\= ' || line =~ '^\\$' |
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
264 \ || line =~ '^\s*: \S' |
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
265 setf forth |
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
266 else |
26344
36f3a77e4b8c
patch 8.2.3703: most people call F# "fsharp" and not "fs"
Bram Moolenaar <Bram@vim.org>
parents:
26311
diff
changeset
|
267 setf fsharp |
26311
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
268 endif |
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
269 endif |
27537 | 270 enddef |
26311
ce3678583211
patch 8.2.3686: filetype detection often mixes up Forth and F#
Bram Moolenaar <Bram@vim.org>
parents:
26296
diff
changeset
|
271 |
27537 | 272 # Distinguish between HTML, XHTML and Django |
273 export def FThtml() | |
274 var n = 1 | |
16024
7fd3a9eaeedb
patch 8.1.1017: off-by-one error in filetype detection
Bram Moolenaar <Bram@vim.org>
parents:
15527
diff
changeset
|
275 while n < 10 && n <= line("$") |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
276 if getline(n) =~ '\<DTD\s\+XHTML\s' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
277 setf xhtml |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
278 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
279 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
280 if getline(n) =~ '{%\s*\(extends\|block\|load\)\>\|{#\s\+' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
281 setf htmldjango |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
282 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
283 endif |
27537 | 284 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
285 endwhile |
16024
7fd3a9eaeedb
patch 8.1.1017: off-by-one error in filetype detection
Bram Moolenaar <Bram@vim.org>
parents:
15527
diff
changeset
|
286 setf FALLBACK html |
27537 | 287 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
288 |
27537 | 289 # Distinguish between standard IDL and MS-IDL |
290 export def FTidl() | |
291 var n = 1 | |
16024
7fd3a9eaeedb
patch 8.1.1017: off-by-one error in filetype detection
Bram Moolenaar <Bram@vim.org>
parents:
15527
diff
changeset
|
292 while n < 50 && n <= line("$") |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
293 if getline(n) =~ '^\s*import\s\+"\(unknwn\|objidl\)\.idl"' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 setf msidl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 endif |
27537 | 297 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
298 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 setf idl |
27537 | 300 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
301 |
27537 | 302 # Distinguish between "default" and Cproto prototype file. */ |
303 export def ProtoCheck(default: string) | |
304 # Cproto files have a comment in the first line and a function prototype in | |
305 # the second line, it always ends in ";". Indent files may also have | |
306 # comments, thus we can't match comments to see the difference. | |
307 # IDL files can have a single ';' in the second line, require at least one | |
308 # chacter before the ';'. | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
309 if getline(2) =~ '.;$' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
310 setf cpp |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
311 else |
27537 | 312 exe 'setf ' .. default |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
313 endif |
27537 | 314 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
315 |
27537 | 316 export def FTm() |
25727
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
317 if exists("g:filetype_m") |
27537 | 318 exe "setf " .. g:filetype_m |
25727
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
319 return |
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
320 endif |
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
321 |
27537 | 322 # excluding end(for|function|if|switch|while) common to Murphi |
323 var octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|methods\|parfor\|properties\)\>' | |
25727
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
324 |
27537 | 325 var objc_preprocessor = '^\s*#\s*\%(import\|include\|define\|if\|ifn\=def\|undef\|line\|error\|pragma\)\>' |
26296
9f32ccdadd22
patch 8.2.3679: objc file detected as Octave
Bram Moolenaar <Bram@vim.org>
parents:
25794
diff
changeset
|
326 |
27537 | 327 var n = 1 |
328 var saw_comment = 0 # Whether we've seen a multiline comment leader. | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
329 while n < 100 |
27537 | 330 var line = getline(n) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
331 if line =~ '^\s*/\*' |
27537 | 332 # /* ... */ is a comment in Objective C and Murphi, so we can't conclude |
333 # it's either of them yet, but track this as a hint in case we don't see | |
334 # anything more definitive. | |
335 saw_comment = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 endif |
26296
9f32ccdadd22
patch 8.2.3679: objc file detected as Octave
Bram Moolenaar <Bram@vim.org>
parents:
25794
diff
changeset
|
337 if line =~ '^\s*//' || line =~ '^\s*@import\>' || line =~ objc_preprocessor |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 setf objc |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
339 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
340 endif |
25794
374adc90efa5
patch 8.2.3432: octave/Matlab filetype detection does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
25727
diff
changeset
|
341 if line =~ '^\s*\%(#\|%!\)' || line =~ '^\s*unwind_protect\>' || |
25727
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
342 \ line =~ '\%(^\|;\)\s*' .. octave_block_terminators |
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
343 setf octave |
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
344 return |
71d3ebfb00b6
patch 8.2.3399: Octave files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25026
diff
changeset
|
345 endif |
27537 | 346 # TODO: could be Matlab or Octave |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
347 if line =~ '^\s*%' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
348 setf matlab |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
349 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
350 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
351 if line =~ '^\s*(\*' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
352 setf mma |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
353 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
354 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
355 if line =~ '^\c\s*\(\(type\|var\)\>\|--\)' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
356 setf murphi |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
357 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
358 endif |
27537 | 359 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
360 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
361 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
362 if saw_comment |
27537 | 363 # We didn't see anything definitive, but this looks like either Objective C |
364 # or Murphi based on the comment leader. Assume the former as it is more | |
365 # common. | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
366 setf objc |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
367 else |
27537 | 368 # Default is Matlab |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
369 setf matlab |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
370 endif |
27537 | 371 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
372 |
27537 | 373 export def FTmms() |
374 var n = 1 | |
19039
d20ed2e5a776
Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
16086
diff
changeset
|
375 while n < 20 |
27537 | 376 var line = getline(n) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
377 if line =~ '^\s*\(%\|//\)' || line =~ '^\*' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
378 setf mmix |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
379 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
380 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
381 if line =~ '^\s*#' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
382 setf make |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
383 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
384 endif |
27537 | 385 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
386 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
387 setf mmix |
27537 | 388 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
389 |
27537 | 390 # This function checks if one of the first five lines start with a dot. In |
391 # that case it is probably an nroff file: 'filetype' is set and 1 is returned. | |
392 export def FTnroff(): number | |
393 if getline(1)[0] .. getline(2)[0] .. getline(3)[0] | |
394 .. getline(4)[0] .. getline(5)[0] =~ '\.' | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
395 setf nroff |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
396 return 1 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
397 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
398 return 0 |
27537 | 399 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
400 |
27537 | 401 export def FTmm() |
402 var n = 1 | |
19968 | 403 while n < 20 |
27537 | 404 if getline(n) =~ '^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\)' |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
405 setf objcpp |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
406 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
407 endif |
27537 | 408 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
409 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
410 setf nroff |
27537 | 411 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
412 |
27537 | 413 export def FTpl() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
414 if exists("g:filetype_pl") |
27537 | 415 exe "setf " .. g:filetype_pl |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
416 else |
27537 | 417 # recognize Prolog by specific text in the first non-empty line |
418 # require a blank after the '%' because Perl uses "%list" and "%translate" | |
419 var l = getline(nextnonblank(1)) | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
420 if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
421 setf prolog |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
422 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
423 setf perl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
424 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
425 endif |
27537 | 426 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
427 |
27537 | 428 export def FTinc() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
429 if exists("g:filetype_inc") |
27537 | 430 exe "setf " .. g:filetype_inc |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
431 else |
27537 | 432 var lines = getline(1) .. getline(2) .. getline(3) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
433 if lines =~? "perlscript" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
434 setf aspperl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
435 elseif lines =~ "<%" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
436 setf aspvbs |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
437 elseif lines =~ "<?" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
438 setf php |
27537 | 439 # Pascal supports // comments but they're vary rarely used for file |
440 # headers so assume POV-Ray | |
27845
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
441 elseif lines =~ '^\s*\%({\|(\*\)' || lines =~? ft_pascal_keywords |
23584
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
442 setf pascal |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
443 else |
27537 | 444 FTasmsyntax() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
445 if exists("b:asmsyntax") |
27537 | 446 exe "setf " .. fnameescape(b:asmsyntax) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
447 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
448 setf pov |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
449 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
450 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
451 endif |
27537 | 452 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
453 |
27537 | 454 export def FTprogress_cweb() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
455 if exists("g:filetype_w") |
27537 | 456 exe "setf " .. g:filetype_w |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
457 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
458 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
459 if getline(1) =~ '&ANALYZE' || getline(3) =~ '&GLOBAL-DEFINE' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
460 setf progress |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
461 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
462 setf cweb |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
463 endif |
27537 | 464 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
465 |
27537 | 466 export def FTprogress_asm() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
467 if exists("g:filetype_i") |
27537 | 468 exe "setf " .. g:filetype_i |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
469 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
470 endif |
27537 | 471 # This function checks for an assembly comment the first ten lines. |
472 # If not found, assume Progress. | |
473 var lnum = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
474 while lnum <= 10 && lnum < line('$') |
27537 | 475 var line = getline(lnum) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
476 if line =~ '^\s*;' || line =~ '^\*' |
27537 | 477 FTasm() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
478 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
479 elseif line !~ '^\s*$' || line =~ '^/\*' |
27537 | 480 # Not an empty line: Doesn't look like valid assembly code. |
481 # Or it looks like a Progress /* comment | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
482 break |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
483 endif |
27537 | 484 lnum += 1 |
27972
9c0b7953016e
patch 8.2.4511: filetype test fails
Bram Moolenaar <Bram@vim.org>
parents:
27903
diff
changeset
|
485 endwhile |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
486 setf progress |
27537 | 487 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
488 |
27537 | 489 var ft_pascal_comments = '^\s*\%({\|(\*\|//\)' |
490 var ft_pascal_keywords = '^\s*\%(program\|unit\|library\|uses\|begin\|procedure\|function\|const\|type\|var\)\>' | |
23584
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
491 |
27537 | 492 export def FTprogress_pascal() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
493 if exists("g:filetype_p") |
27537 | 494 exe "setf " .. g:filetype_p |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
495 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
496 endif |
27537 | 497 # This function checks for valid Pascal syntax in the first ten lines. |
498 # Look for either an opening comment or a program start. | |
499 # If not found, assume Progress. | |
500 var lnum = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
501 while lnum <= 10 && lnum < line('$') |
27537 | 502 var line = getline(lnum) |
27845
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
503 if line =~ ft_pascal_comments || line =~? ft_pascal_keywords |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
504 setf pascal |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
505 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
506 elseif line !~ '^\s*$' || line =~ '^/\*' |
27537 | 507 # Not an empty line: Doesn't look like valid Pascal code. |
508 # Or it looks like a Progress /* comment | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
509 break |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
510 endif |
27537 | 511 lnum += 1 |
27972
9c0b7953016e
patch 8.2.4511: filetype test fails
Bram Moolenaar <Bram@vim.org>
parents:
27903
diff
changeset
|
512 endwhile |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
513 setf progress |
27537 | 514 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
515 |
27537 | 516 export def FTpp() |
23584
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
517 if exists("g:filetype_pp") |
27537 | 518 exe "setf " .. g:filetype_pp |
23584
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
519 else |
27537 | 520 var line = getline(nextnonblank(1)) |
27845
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
521 if line =~ ft_pascal_comments || line =~? ft_pascal_keywords |
23584
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
522 setf pascal |
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
523 else |
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
524 setf puppet |
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
525 endif |
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
526 endif |
27537 | 527 enddef |
23584
397f95f103e8
patch 8.2.2334: Pascal-like filetypes not always detected
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
528 |
27537 | 529 export def FTr() |
530 var max = line("$") > 50 ? 50 : line("$") | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
531 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
532 for n in range(1, max) |
27537 | 533 # Rebol is easy to recognize, check for that first |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
534 if getline(n) =~? '\<REBOL\>' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
535 setf rebol |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
536 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
537 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
538 endfor |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
539 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
540 for n in range(1, max) |
27537 | 541 # R has # comments |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
542 if getline(n) =~ '^\s*#' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
543 setf r |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
544 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
545 endif |
27537 | 546 # Rexx has /* comments */ |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
547 if getline(n) =~ '^\s*/\*' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
548 setf rexx |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
549 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
550 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
551 endfor |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
552 |
27537 | 553 # Nothing recognized, use user default or assume Rexx |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
554 if exists("g:filetype_r") |
27537 | 555 exe "setf " .. g:filetype_r |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
556 else |
27537 | 557 # Rexx used to be the default, but R appears to be much more popular. |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
558 setf r |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
559 endif |
27537 | 560 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
561 |
27537 | 562 export def McSetf() |
563 # Rely on the file to start with a comment. | |
564 # MS message text files use ';', Sendmail files use '#' or 'dnl' | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
565 for lnum in range(1, min([line("$"), 20])) |
27537 | 566 var line = getline(lnum) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
567 if line =~ '^\s*\(#\|dnl\)' |
27537 | 568 setf m4 # Sendmail .mc file |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
569 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
570 elseif line =~ '^\s*;' |
27537 | 571 setf msmessages # MS Message text file |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
572 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
573 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
574 endfor |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
575 setf m4 " Default: Sendmail .mc file |
27537 | 576 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
577 |
27537 | 578 # Called from filetype.vim and scripts.vim. |
579 export def SetFileTypeSH(name: string) | |
15527
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
580 if did_filetype() |
27537 | 581 # Filetype was already detected |
15527
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
582 return |
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
583 endif |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
584 if expand("<amatch>") =~ g:ft_ignore_pat |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
585 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
586 endif |
27537 | 587 if name =~ '\<csh\>' |
588 # Some .sh scripts contain #!/bin/csh. | |
589 SetFileTypeShell("csh") | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
590 return |
27537 | 591 elseif name =~ '\<tcsh\>' |
592 # Some .sh scripts contain #!/bin/tcsh. | |
593 SetFileTypeShell("tcsh") | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
594 return |
27537 | 595 elseif name =~ '\<zsh\>' |
596 # Some .sh scripts contain #!/bin/zsh. | |
597 SetFileTypeShell("zsh") | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
598 return |
27537 | 599 elseif name =~ '\<ksh\>' |
600 b:is_kornshell = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
601 if exists("b:is_bash") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
602 unlet b:is_bash |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
603 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
604 if exists("b:is_sh") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
605 unlet b:is_sh |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
606 endif |
27537 | 607 elseif exists("g:bash_is_sh") || name =~ '\<bash\>' || name =~ '\<bash2\>' |
608 b:is_bash = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
609 if exists("b:is_kornshell") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
610 unlet b:is_kornshell |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
611 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
612 if exists("b:is_sh") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
613 unlet b:is_sh |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
614 endif |
27537 | 615 elseif name =~ '\<sh\>' |
616 b:is_sh = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
617 if exists("b:is_kornshell") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
618 unlet b:is_kornshell |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
619 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
620 if exists("b:is_bash") |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
621 unlet b:is_bash |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
622 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
623 endif |
27537 | 624 SetFileTypeShell("sh") |
625 enddef | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
626 |
27537 | 627 # For shell-like file types, check for an "exec" command hidden in a comment, |
628 # as used for Tcl. | |
629 # Also called from scripts.vim, thus can't be local to this script. | |
630 export def SetFileTypeShell(name: string) | |
15527
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
631 if did_filetype() |
27537 | 632 # Filetype was already detected |
15527
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
633 return |
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
634 endif |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
635 if expand("<amatch>") =~ g:ft_ignore_pat |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
636 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
637 endif |
27537 | 638 var l = 2 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
639 while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)' |
27537 | 640 # Skip empty and comment lines. |
641 l += 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
642 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
643 if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$' |
27537 | 644 # Found an "exec" line after a comment with continuation |
645 var n = substitute(getline(l), '\s*exec\s\+\([^ ]*/\)\=', '', '') | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
646 if n =~ '\<tclsh\|\<wish' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
647 setf tcl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
648 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
649 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
650 endif |
27537 | 651 exe "setf " .. name |
652 enddef | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
653 |
27537 | 654 export def CSH() |
15527
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
655 if did_filetype() |
27537 | 656 # Filetype was already detected |
15527
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
657 return |
963dd629d19a
patch 8.1.0771: some shell filetype patterns end in a star
Bram Moolenaar <Bram@vim.org>
parents:
14999
diff
changeset
|
658 endif |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
659 if exists("g:filetype_csh") |
27537 | 660 SetFileTypeShell(g:filetype_csh) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
661 elseif &shell =~ "tcsh" |
27537 | 662 SetFileTypeShell("tcsh") |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
663 else |
27537 | 664 SetFileTypeShell("csh") |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
665 endif |
27537 | 666 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
667 |
27537 | 668 var ft_rules_udev_rules_pattern = '^\s*\cudev_rules\s*=\s*"\([^"]\{-1,}\)/*".*' |
669 export def FTRules() | |
670 var path = expand('<amatch>:p') | |
21853
aab3fe874b05
patch 8.2.1476: filetype test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
21849
diff
changeset
|
671 if path =~ '/\(etc/udev/\%(rules\.d/\)\=.*\.rules\|\%(usr/\)\=lib/udev/\%(rules\.d/\)\=.*\.rules\)$' |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
672 setf udevrules |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
673 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
674 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
675 if path =~ '^/etc/ufw/' |
27537 | 676 setf conf # Better than hog |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
677 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
678 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
679 if path =~ '^/\(etc\|usr/share\)/polkit-1/rules\.d' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
680 setf javascript |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
681 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
682 endif |
27537 | 683 var config_lines: list<string> |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
684 try |
27537 | 685 config_lines = readfile('/etc/udev/udev.conf') |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
686 catch /^Vim\%((\a\+)\)\=:E484/ |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
687 setf hog |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
688 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
689 endtry |
27537 | 690 var dir = expand('<amatch>:p:h') |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
691 for line in config_lines |
27845
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
692 if line =~ ft_rules_udev_rules_pattern |
e63514ae0c29
patch 8.2.4448: filetype detection is failing
Bram Moolenaar <Bram@vim.org>
parents:
27557
diff
changeset
|
693 var udev_rules = substitute(line, ft_rules_udev_rules_pattern, '\1', "") |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
694 if dir == udev_rules |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
695 setf udevrules |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
696 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
697 break |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
698 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
699 endfor |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
700 setf hog |
27537 | 701 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
702 |
27537 | 703 export def SQL() |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
704 if exists("g:filetype_sql") |
27537 | 705 exe "setf " .. g:filetype_sql |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
706 else |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
707 setf sql |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
708 endif |
27537 | 709 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
710 |
27537 | 711 # If the file has an extension of 't' and is in a directory 't' or 'xt' then |
712 # it is almost certainly a Perl test file. | |
713 # If the first line starts with '#' and contains 'perl' it's probably a Perl | |
714 # file. | |
715 # (Slow test) If a file contains a 'use' statement then it is almost certainly | |
716 # a Perl file. | |
717 export def FTperl(): number | |
718 var dirname = expand("%:p:h:t") | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
719 if expand("%:e") == 't' && (dirname == 't' || dirname == 'xt') |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
720 setf perl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
721 return 1 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
722 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
723 if getline(1)[0] == '#' && getline(1) =~ 'perl' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
724 setf perl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
725 return 1 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
726 endif |
27537 | 727 var save_cursor = getpos('.') |
728 call cursor(1, 1) | |
27557
ce72087b601f
patch 8.2.4305: tex filetype detection fails
Bram Moolenaar <Bram@vim.org>
parents:
27538
diff
changeset
|
729 var has_use = search('^use\s\s*\k', 'c', 30) > 0 |
13051 | 730 call setpos('.', save_cursor) |
731 if has_use | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
732 setf perl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
733 return 1 |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
734 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
735 return 0 |
27537 | 736 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
737 |
27537 | 738 # Choose context, plaintex, or tex (LaTeX) based on these rules: |
739 # 1. Check the first line of the file for "%&<format>". | |
740 # 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords. | |
741 # 3. Default to "plain" or to g:tex_flavor, can be set in user's vimrc. | |
742 export def FTtex() | |
743 var firstline = getline(1) | |
744 var format: string | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
745 if firstline =~ '^%&\s*\a\+' |
27537 | 746 format = tolower(matchstr(firstline, '\a\+')) |
747 format = substitute(format, 'pdf', '', '') | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
748 if format == 'tex' |
27537 | 749 format = 'latex' |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
750 elseif format == 'plaintex' |
27537 | 751 format = 'plain' |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
752 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
753 elseif expand('%') =~ 'tex/context/.*/.*.tex' |
27537 | 754 format = 'context' |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
755 else |
27537 | 756 # Default value, may be changed later: |
757 format = exists("g:tex_flavor") ? g:tex_flavor : 'plain' | |
758 # Save position, go to the top of the file, find first non-comment line. | |
759 var save_cursor = getpos('.') | |
760 call cursor(1, 1) | |
761 var firstNC = search('^\s*[^[:space:]%]', 'c', 1000) | |
27557
ce72087b601f
patch 8.2.4305: tex filetype detection fails
Bram Moolenaar <Bram@vim.org>
parents:
27538
diff
changeset
|
762 if firstNC > 0 |
ce72087b601f
patch 8.2.4305: tex filetype detection fails
Bram Moolenaar <Bram@vim.org>
parents:
27538
diff
changeset
|
763 # Check the next thousand lines for a LaTeX or ConTeXt keyword. |
27537 | 764 var lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>' |
765 var cpat = 'start\a\+\|setup\a\+\|usemodule\|enablemode\|enableregime\|setvariables\|useencoding\|usesymbols\|stelle\a\+\|verwende\a\+\|stel\a\+\|gebruik\a\+\|usa\a\+\|imposta\a\+\|regle\a\+\|utilisemodule\>' | |
766 var kwline = search('^\s*\\\%(' .. lpat .. '\)\|^\s*\\\(' .. cpat .. '\)', | |
767 'cnp', firstNC + 1000) | |
768 if kwline == 1 # lpat matched | |
769 format = 'latex' | |
770 elseif kwline == 2 # cpat matched | |
771 format = 'context' | |
772 endif # If neither matched, keep default set above. | |
773 # let lline = search('^\s*\\\%(' . lpat . '\)', 'cn', firstNC + 1000) | |
774 # let cline = search('^\s*\\\%(' . cpat . '\)', 'cn', firstNC + 1000) | |
775 # if cline > 0 | |
776 # let format = 'context' | |
777 # endif | |
778 # if lline > 0 && (cline == 0 || cline > lline) | |
779 # let format = 'tex' | |
780 # endif | |
781 endif # firstNC | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
782 call setpos('.', save_cursor) |
27537 | 783 endif # firstline =~ '^%&\s*\a\+' |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
784 |
27537 | 785 # Translation from formats to file types. TODO: add AMSTeX, RevTex, others? |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
786 if format == 'plain' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
787 setf plaintex |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
788 elseif format == 'context' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
789 setf context |
27537 | 790 else # probably LaTeX |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
791 setf tex |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
792 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
793 return |
27537 | 794 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
795 |
27537 | 796 export def FTxml() |
797 var n = 1 | |
16024
7fd3a9eaeedb
patch 8.1.1017: off-by-one error in filetype detection
Bram Moolenaar <Bram@vim.org>
parents:
15527
diff
changeset
|
798 while n < 100 && n <= line("$") |
27537 | 799 var line = getline(n) |
800 # DocBook 4 or DocBook 5. | |
801 var is_docbook4 = line =~ '<!DOCTYPE.*DocBook' | |
802 var is_docbook5 = line =~ ' xmlns="http://docbook.org/ns/docbook"' | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
803 if is_docbook4 || is_docbook5 |
27537 | 804 b:docbk_type = "xml" |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
805 if is_docbook5 |
27537 | 806 b:docbk_ver = 5 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
807 else |
27537 | 808 b:docbk_ver = 4 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
809 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
810 setf docbk |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
811 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
812 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
813 if line =~ 'xmlns:xbl="http://www.mozilla.org/xbl"' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
814 setf xbl |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
815 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
816 endif |
27537 | 817 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
818 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
819 setf xml |
27537 | 820 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
821 |
27537 | 822 export def FTy() |
823 var n = 1 | |
16024
7fd3a9eaeedb
patch 8.1.1017: off-by-one error in filetype detection
Bram Moolenaar <Bram@vim.org>
parents:
15527
diff
changeset
|
824 while n < 100 && n <= line("$") |
27537 | 825 var line = getline(n) |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
826 if line =~ '^\s*%' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
827 setf yacc |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
828 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
829 endif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
830 if getline(n) =~ '^\s*\(#\|class\>\)' && getline(n) !~ '^\s*#\s*include' |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
831 setf racc |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
832 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
833 endif |
27537 | 834 n += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
835 endwhile |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
836 setf yacc |
27537 | 837 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
838 |
27537 | 839 export def Redif() |
840 var lnum = 1 | |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
841 while lnum <= 5 && lnum < line('$') |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
842 if getline(lnum) =~ "^\ctemplate-type:" |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
843 setf redif |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
844 return |
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
845 endif |
27537 | 846 lnum += 1 |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
847 endwhile |
27537 | 848 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
849 |
27537 | 850 # This function is called for all files under */debian/patches/*, make sure not |
851 # to non-dep3patch files, such as README and other text files. | |
852 export def Dep3patch() | |
26628
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
853 if expand('%:t') ==# 'series' |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
854 return |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
855 endif |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
856 |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
857 for ln in getline(1, 100) |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
858 if ln =~# '^\%(Description\|Subject\|Origin\|Bug\|Forwarded\|Author\|From\|Reviewed-by\|Acked-by\|Last-Updated\|Applied-Upstream\):' |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
859 setf dep3patch |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
860 return |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
861 elseif ln =~# '^---' |
27537 | 862 # end of headers found. stop processing |
26628
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
863 return |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
864 endif |
7efd8f561d04
patch 8.2.3843: dep3patch files are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26438
diff
changeset
|
865 endfor |
27537 | 866 enddef |
12816
218102da5226
patch 8.0.1285: occasional crash when using a channel
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
867 |
27537 | 868 # This function checks the first 15 lines for appearance of 'FoamFile' |
869 # and then 'object' in a following line. | |
870 # In that case, it's probably an OpenFOAM file | |
871 export def FTfoam() | |
872 var ffile = 0 | |
873 var lnum = 1 | |
27070
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
874 while lnum <= 15 |
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
875 if getline(lnum) =~# '^FoamFile' |
27537 | 876 ffile = 1 |
27070
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
877 elseif ffile == 1 && getline(lnum) =~# '^\s*object' |
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
878 setf foam |
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
879 return |
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
880 endif |
27537 | 881 lnum += 1 |
27070
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
882 endwhile |
27537 | 883 enddef |
27070
b353bd9faec8
patch 8.2.4064: foam files are not detected
Bram Moolenaar <Bram@vim.org>
parents:
26708
diff
changeset
|
884 |
27537 | 885 # Determine if a *.tf file is TF mud client or terraform |
886 export def FTtf() | |
887 var numberOfLines = line('$') | |
27420
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
888 for i in range(1, numberOfLines) |
27537 | 889 var currentLine = trim(getline(i)) |
890 var firstCharacter = currentLine[0] | |
27420
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
891 if firstCharacter !=? ";" && firstCharacter !=? "/" && firstCharacter !=? "" |
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
892 setf terraform |
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
893 return |
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
894 endif |
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
895 endfor |
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
896 setf tf |
27537 | 897 enddef |
27420
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
898 |
978890380129
patch 8.2.4238: *.tf file could be fileytpe "tf" or "terraform"
Bram Moolenaar <Bram@vim.org>
parents:
27287
diff
changeset
|
899 |
27537 | 900 # Uncomment this line to check for compilation errors early |
27538
f37561549ec2
Update runtime files; use compiled functions
Bram Moolenaar <Bram@vim.org>
parents:
27537
diff
changeset
|
901 # defcompile |