Patch 9.0.1539

6 views
Skip to first unread message

Bram Moolenaar

unread,
May 10, 2023, 5:02:34 PM5/10/23
to vim...@googlegroups.com

Patch 9.0.1539
Problem: Typst filetype is not recognized.
Solution: Distinguish between sql and typst. (Gaetan Lepage, closes #12363)
Files: runtime/autoload/dist/ft.vim, runtime/doc/filetype.txt,
runtime/filetype.vim, src/testdir/test_filetype.vim


*** ../vim-9.0.1538/runtime/autoload/dist/ft.vim 2023-04-22 21:38:43.154215972 +0100
--- runtime/autoload/dist/ft.vim 2023-05-10 21:55:48.427843611 +0100
***************
*** 470,476 ****

# Returns true if file content looks like LambdaProlog module
def IsLProlog(): bool
! # skip apparent comments and blank lines, what looks like
# LambdaProlog comment may be RAPID header
var l: number = nextnonblank(1)
while l > 0 && l < line('$') && getline(l) =~ '^\s*%' # LambdaProlog comment
--- 470,476 ----

# Returns true if file content looks like LambdaProlog module
def IsLProlog(): bool
! # skip apparent comments and blank lines, what looks like
# LambdaProlog comment may be RAPID header
var l: number = nextnonblank(1)
while l > 0 && l < line('$') && getline(l) =~ '^\s*%' # LambdaProlog comment
***************
*** 1106,1111 ****
--- 1106,1136 ----
endif
enddef

+ export def FTtyp()
+ if exists("g:filetype_typ")
+ exe "setf " .. g:filetype_typ
+ return
+ endif
+
+ # Look for SQL type definition syntax
+ for line in getline(1, 200)
+ # SQL type files may define the casing
+ if line =~ '^CASE\s\==\s\=\(SAME\|LOWER\|UPPER\|OPPOSITE\)$'
+ setf sql
+ return
+ endif
+
+ # SQL type files may define some types as follows
+ if line =~ '^TYPE\s.*$'
+ setf sql
+ return
+ endif
+ endfor
+
+ # Otherwise, affect the typst filetype
+ setf typst
+ enddef
+
# Set the filetype of a *.v file to Verilog, V or Cog based on the first 200
# lines.
export def FTv()
*** ../vim-9.0.1538/runtime/doc/filetype.txt 2022-10-17 13:32:13.677965004 +0100
--- runtime/doc/filetype.txt 2023-05-10 21:55:48.427843611 +0100
***************
*** 164,169 ****
--- 164,170 ----
*.sys g:filetype_sys
*.sh g:bash_is_sh |ft-sh-syntax|
*.tex g:tex_flavor |ft-tex-plugin|
+ *.typ g:filetype_typ
*.w g:filetype_w |ft-cweb-syntax|

For a few filetypes the global variable is used only when the filetype could
*** ../vim-9.0.1538/runtime/filetype.vim 2023-04-30 21:24:33.152633659 +0100
--- runtime/filetype.vim 2023-05-10 22:00:20.868644933 +0100
***************
*** 2058,2064 ****
au BufNewFile,BufRead squid.conf setf squid

" SQL for Oracle Designer
! au BufNewFile,BufRead *.tyb,*.typ,*.tyc,*.pkb,*.pks setf sql

" SQL
au BufNewFile,BufRead *.sql call dist#ft#SQL()
--- 2058,2067 ----
au BufNewFile,BufRead squid.conf setf squid

" SQL for Oracle Designer
! au BufNewFile,BufRead *.tyb,*.tyc,*.pkb,*.pks setf sql
!
! " *.typ can be either SQL or Typst files
! au BufNewFile,BufRead *.typ call dist#ft#FTtyp()

" SQL
au BufNewFile,BufRead *.sql call dist#ft#SQL()
*** ../vim-9.0.1538/src/testdir/test_filetype.vim 2023-04-30 21:24:33.152633659 +0100
--- src/testdir/test_filetype.vim 2023-05-10 21:59:02.128447527 +0100
***************
*** 564,570 ****
\ 'spice': ['file.sp', 'file.spice'],
\ 'spup': ['file.speedup', 'file.spdata', 'file.spd'],
\ 'spyce': ['file.spy', 'file.spi'],
! \ 'sql': ['file.tyb', 'file.typ', 'file.tyc', 'file.pkb', 'file.pks'],
\ 'sqlj': ['file.sqlj'],
\ 'prql': ['file.prql'],
\ 'sqr': ['file.sqr', 'file.sqi'],
--- 564,570 ----
\ 'spice': ['file.sp', 'file.spice'],
\ 'spup': ['file.speedup', 'file.spdata', 'file.spd'],
\ 'spyce': ['file.spy', 'file.spi'],
! \ 'sql': ['file.tyb', 'file.tyc', 'file.pkb', 'file.pks'],
\ 'sqlj': ['file.sqlj'],
\ 'prql': ['file.prql'],
\ 'sqr': ['file.sqr', 'file.sqi'],
***************
*** 2046,2050 ****
--- 2046,2081 ----

filetype off
endfunc
+
+ func Test_typ_file()
+ filetype on
+
+ " SQL type file
+
+ call writefile(['CASE = LOWER'], 'Xfile.typ', 'D')
+ split Xfile.typ
+ call assert_equal('sql', &filetype)
+ bwipe!
+
+ call writefile(['TYPE foo'], 'Xfile.typ')
+ split Xfile.typ
+ call assert_equal('sql', &filetype)
+ bwipe!
+
+ " typst document
+
+ call writefile(['this is a fallback'], 'Xfile.typ')
+ split Xfile.typ
+ call assert_equal('typst', &filetype)
+ bwipe!
+
+ let g:filetype_typ = 'typst'
+ split test.typ
+ call assert_equal('typst', &filetype)
+ bwipe!
+ unlet g:filetype_typ
+
+ filetype off
+ endfunc

" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.1538/src/version.c 2023-05-10 16:53:23.872081797 +0100
--- src/version.c 2023-05-10 21:57:28.844180091 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1539,
/**/

--
How To Keep A Healthy Level Of Insanity:
9. As often as possible, skip rather than walk.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages