Skip to content

Commit

Permalink
fix(runtime): add docs and test for *.l filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-418 committed Apr 13, 2024
1 parent 96d130f commit 40c0458
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
29 changes: 15 additions & 14 deletions runtime/autoload/dist/ft.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1191,27 +1191,28 @@ export def FTdat()
endif
enddef

# Determine if a *.l file is Lex or PicoLisp
# Determine if a *.l file is Lex or PicoLisp (default to Lex)
export def FTl()
" Default to Lex
setf lex
if exists("g:filetype_l")
exe "setf " .. g:filetype_l
return
endif
for i in range(1, line("$"))
let l:line = trim(getline(i))
" PicoLisp uses # comments
if l:line =~ "^#\.*$"
set ft=picolisp
var line = trim(getline(i))
if line =~ "^\s+\/\*.*\*\/.*$"
setf lex
return
" Lex uses // comments
elseif (l:line =~ "//" && l:line !~ "([^)]*//") || l:line =~ "/\\*" || l:line =~ "\\*/"
set ft=lex
elseif line =~ "^#\.*$"
setf picolisp
return
" PicoLisp uses Lisp syntax
elseif l:line =~ "^("
set ft=picolisp
elseif line =~ "^(\.*$"
setf picolisp
return
endif
endfor
enddef
setf lex
return
enddef

export def FTlsl()
if exists("g:filetype_lsl")
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/filetype.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ variables can be used to overrule the filetype used for certain extensions:
*.h g:c_syntax_for_h |ft-c-syntax|
*.i g:filetype_i |ft-progress-syntax|
*.inc g:filetype_inc
*.l g:filetype_l
*.lsl g:filetype_lsl
*.m g:filetype_m |ft-mathematica-syntax|
*.mod g:filetype_mod
Expand Down
32 changes: 32 additions & 0 deletions src/testdir/test_filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,38 @@ func Test_inc_file()
filetype off
endfunc

func Test_l_file()
filetype on

call writefile(['(de example "Looks like PicoLisp")'], 'Xfile.l', 'D')
split Xfile.l
call assert_equal('picolisp', &filetype)
bwipe!

call writefile(['# PicoLisp comment'], 'Xfile.l')
split Xfile.l
call assert_equal('picolisp', &filetype)
bwipe!

let g:filetype_l = 'lex'
split Xfile.l
call assert_equal('lex', &filetype)
bwipe!
unlet g:filetype_l

call writefile([' /* Lex comment */'], 'Xfile.l')
split Xfile.l
call assert_equal('lex', &filetype)
bwipe!

let g:filetype_l = 'picolisp'
split Xfile.l
call assert_equal('picolisp', &filetype)
bwipe!

filetype off
endfunc

func Test_lsl_file()
filetype on

Expand Down

0 comments on commit 40c0458

Please sign in to comment.