mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0006: not all Visual Basic files are recognized (#19153)
Problem: Not all Visual Basic files are recognized.
Solution: Change detection of *.cls files. (Doug Kearns)
8b5901e2f9
This commit is contained in:
parent
ba583f8206
commit
1eb9624666
49
runtime/autoload/dist/ft.vim
vendored
49
runtime/autoload/dist/ft.vim
vendored
@ -78,22 +78,30 @@ func dist#ft#FTbas()
|
|||||||
|
|
||||||
" most frequent FreeBASIC-specific keywords in distro files
|
" most frequent FreeBASIC-specific keywords in distro files
|
||||||
let fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!'
|
let fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!'
|
||||||
let fb_preproc = '\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)'
|
let fb_preproc = '\c^\s*\%(' ..
|
||||||
|
\ '#\s*\a\+\|' ..
|
||||||
|
\ 'option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|' ..
|
||||||
|
\ '\%(''\|rem\)\s*\$lang\>\|' ..
|
||||||
|
\ 'def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>' ..
|
||||||
|
\ '\)'
|
||||||
let fb_comment = "^\\s*/'"
|
let fb_comment = "^\\s*/'"
|
||||||
" OPTION EXPLICIT, without the leading underscore, is common to many dialects
|
" OPTION EXPLICIT, without the leading underscore, is common to many dialects
|
||||||
let qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)'
|
let qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)'
|
||||||
|
|
||||||
let lines = getline(1, min([line("$"), 100]))
|
for lnum in range(1, min([line("$"), 100]))
|
||||||
|
let line = getline(lnum)
|
||||||
if match(lines, fb_preproc) > -1 || match(lines, fb_comment) > -1 || match(lines, fb_keywords) > -1
|
if line =~ s:ft_visual_basic_content
|
||||||
setf freebasic
|
setf vb
|
||||||
elseif match(lines, qb64_preproc) > -1
|
return
|
||||||
setf qb64
|
elseif line =~ fb_preproc || line =~ fb_comment || line =~ fb_keywords
|
||||||
elseif match(lines, s:ft_visual_basic_content) > -1
|
setf freebasic
|
||||||
setf vb
|
return
|
||||||
else
|
elseif line =~ qb64_preproc
|
||||||
setf basic
|
setf qb64
|
||||||
endif
|
return
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
setf basic
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func dist#ft#FTbtm()
|
func dist#ft#FTbtm()
|
||||||
@ -131,6 +139,23 @@ func dist#ft#FTcfg()
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func dist#ft#FTcls()
|
||||||
|
if exists("g:filetype_cls")
|
||||||
|
exe "setf " .. g:filetype_cls
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
if getline(1) =~ '^%'
|
||||||
|
setf tex
|
||||||
|
elseif getline(1)[0] == '#' && getline(1) =~ 'rexx'
|
||||||
|
setf rexx
|
||||||
|
elseif getline(1) == 'VERSION 1.0 CLASS'
|
||||||
|
setf vb
|
||||||
|
else
|
||||||
|
setf st
|
||||||
|
endif
|
||||||
|
endfunc
|
||||||
|
|
||||||
func dist#ft#FTlpc()
|
func dist#ft#FTlpc()
|
||||||
if exists("g:lpc_syntax_for_c")
|
if exists("g:lpc_syntax_for_c")
|
||||||
let lnum = 1
|
let lnum = 1
|
||||||
|
@ -141,6 +141,7 @@ variables can be used to overrule the filetype used for certain extensions:
|
|||||||
*.asp g:filetype_asp |ft-aspvbs-syntax| |ft-aspperl-syntax|
|
*.asp g:filetype_asp |ft-aspvbs-syntax| |ft-aspperl-syntax|
|
||||||
*.bas g:filetype_bas |ft-basic-syntax|
|
*.bas g:filetype_bas |ft-basic-syntax|
|
||||||
*.cfg g:filetype_cfg
|
*.cfg g:filetype_cfg
|
||||||
|
*.cls g:filetype_cls
|
||||||
*.csh g:filetype_csh |ft-csh-syntax|
|
*.csh g:filetype_csh |ft-csh-syntax|
|
||||||
*.dat g:filetype_dat
|
*.dat g:filetype_dat
|
||||||
*.frm g:filetype_frm |ft-form-syntax|
|
*.frm g:filetype_frm |ft-form-syntax|
|
||||||
|
@ -1794,16 +1794,11 @@ au BufNewFile,BufRead *.il,*.ils,*.cdf setf skill
|
|||||||
au BufNewFile,BufRead .slrnrc setf slrnrc
|
au BufNewFile,BufRead .slrnrc setf slrnrc
|
||||||
au BufNewFile,BufRead *.score setf slrnsc
|
au BufNewFile,BufRead *.score setf slrnsc
|
||||||
|
|
||||||
" Smalltalk (and TeX)
|
" Smalltalk
|
||||||
au BufNewFile,BufRead *.st setf st
|
au BufNewFile,BufRead *.st setf st
|
||||||
au BufNewFile,BufRead *.cls
|
|
||||||
\ if getline(1) =~ '^%' |
|
" Smalltalk (and Rexx, TeX, and Visual Basic)
|
||||||
\ setf tex |
|
au BufNewFile,BufRead *.cls call dist#ft#FTcls()
|
||||||
\ elseif getline(1)[0] == '#' && getline(1) =~ 'rexx' |
|
|
||||||
\ setf rexx |
|
|
||||||
\ else |
|
|
||||||
\ setf st |
|
|
||||||
\ endif
|
|
||||||
|
|
||||||
" Smarty templates
|
" Smarty templates
|
||||||
au BufNewFile,BufRead *.tpl setf smarty
|
au BufNewFile,BufRead *.tpl setf smarty
|
||||||
|
@ -83,19 +83,19 @@ function M.bas(bufnr)
|
|||||||
local fb_keywords =
|
local fb_keywords =
|
||||||
[[\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!]]
|
[[\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!]]
|
||||||
local fb_preproc =
|
local fb_preproc =
|
||||||
[[\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)]]
|
[[\c^\s*\%(#\s*\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|\%(''\|rem\)\s*\$lang\>\|def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>\)]]
|
||||||
|
|
||||||
local fb_comment = "^%s*/'"
|
local fb_comment = "^%s*/'"
|
||||||
-- OPTION EXPLICIT, without the leading underscore, is common to many dialects
|
-- OPTION EXPLICIT, without the leading underscore, is common to many dialects
|
||||||
local qb64_preproc = [[\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)]]
|
local qb64_preproc = [[\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)]]
|
||||||
|
|
||||||
for _, line in ipairs(getlines(bufnr, 1, 100)) do
|
for _, line in ipairs(getlines(bufnr, 1, 100)) do
|
||||||
if line:find(fb_comment) or matchregex(line, fb_preproc) or matchregex(line, fb_keywords) then
|
if findany(line:lower(), visual_basic_content) then
|
||||||
|
return 'vb'
|
||||||
|
elseif line:find(fb_comment) or matchregex(line, fb_preproc) or matchregex(line, fb_keywords) then
|
||||||
return 'freebasic'
|
return 'freebasic'
|
||||||
elseif matchregex(line, qb64_preproc) then
|
elseif matchregex(line, qb64_preproc) then
|
||||||
return 'qb64'
|
return 'qb64'
|
||||||
elseif findany(line:lower(), visual_basic_content) then
|
|
||||||
return 'vb'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 'basic'
|
return 'basic'
|
||||||
@ -172,11 +172,16 @@ function M.class(bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.cls(bufnr)
|
function M.cls(bufnr)
|
||||||
|
if vim.g.filetype_cls then
|
||||||
|
return vim.g.filetype_cls
|
||||||
|
end
|
||||||
local line = getlines(bufnr, 1)
|
local line = getlines(bufnr, 1)
|
||||||
if line:find('^%%') then
|
if line:find('^%%') then
|
||||||
return 'tex'
|
return 'tex'
|
||||||
elseif line:find('^#') and line:lower():find('rexx') then
|
elseif line:find('^#') and line:lower():find('rexx') then
|
||||||
return 'rexx'
|
return 'rexx'
|
||||||
|
elseif line == 'VERSION 1.0 CLASS' then
|
||||||
|
return 'vb'
|
||||||
else
|
else
|
||||||
return 'st'
|
return 'st'
|
||||||
end
|
end
|
||||||
|
@ -812,7 +812,7 @@ func Test_bas_file()
|
|||||||
|
|
||||||
" Visual Basic
|
" Visual Basic
|
||||||
|
|
||||||
call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas')
|
call writefile(['Attribute VB_NAME = "Testing"', 'Enum Foo', 'End Enum'], 'Xfile.bas')
|
||||||
split Xfile.bas
|
split Xfile.bas
|
||||||
call assert_equal('vb', &filetype)
|
call assert_equal('vb', &filetype)
|
||||||
bwipe!
|
bwipe!
|
||||||
@ -1692,5 +1692,45 @@ func Test_xpm_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_cls_file()
|
||||||
|
filetype on
|
||||||
|
|
||||||
|
call writefile(['looks like Smalltalk'], 'Xfile.cls')
|
||||||
|
split Xfile.cls
|
||||||
|
call assert_equal('st', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Test dist#ft#FTcls()
|
||||||
|
|
||||||
|
let g:filetype_cls = 'vb'
|
||||||
|
split Xfile.cls
|
||||||
|
call assert_equal('vb', &filetype)
|
||||||
|
bwipe!
|
||||||
|
unlet g:filetype_cls
|
||||||
|
|
||||||
|
" TeX
|
||||||
|
|
||||||
|
call writefile(['%'], 'Xfile.cls')
|
||||||
|
split Xfile.cls
|
||||||
|
call assert_equal('tex', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Rexx
|
||||||
|
|
||||||
|
call writefile(['# rexx'], 'Xfile.cls')
|
||||||
|
split Xfile.cls
|
||||||
|
call assert_equal('rexx', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Visual Basic
|
||||||
|
|
||||||
|
call writefile(['VERSION 1.0 CLASS'], 'Xfile.cls')
|
||||||
|
split Xfile.cls
|
||||||
|
call assert_equal('vb', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call delete('Xfile.cls')
|
||||||
|
filetype off
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user