To: vim_dev@googlegroups.com Subject: Patch 8.2.4720 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4720 Problem: ABB Rapid files are not recognized properly. Solution: Add checks for ABB Rapid files. (Patrick Meiser-Knosowski, closes #10104) Files: runtime/autoload/dist/ft.vim, runtime/doc/filetype.txt, runtime/filetype.vim, src/testdir/test_filetype.vim, *** ../vim-8.2.4719/runtime/autoload/dist/ft.vim 2022-04-06 18:57:34.119958768 +0100 --- runtime/autoload/dist/ft.vim 2022-04-09 15:10:15.464743821 +0100 *************** *** 107,112 **** --- 107,131 ---- endif enddef + # Returns true if file content looks like RAPID + def IsRapid(sChkExt: string = ""): bool + if sChkExt == "cfg" + return getline(1) =~? '\v^%(EIO|MMC|MOC|PROC|SIO|SYS):CFG' + endif + # called from FTmod, FTprg or FTsys + return getline(nextnonblank(1)) =~? '\v^\s*%(\%{3}|module\s+\k+\s*%(\(|$))' + enddef + + export def FTcfg() + if exists("g:filetype_cfg") + exe "setf " .. g:filetype_cfg + elseif IsRapid("cfg") + setf rapid + else + setf cfg + endif + enddef + export def FTlpc() if exists("g:lpc_syntax_for_c") var lnum = 1 *************** *** 168,174 **** export def FTent() # This function checks for valid cl syntax in the first five lines. ! # Look for either an opening comment, '#', or a block start, '{". # If not found, assume SGML. var lnum = 1 while lnum < 6 --- 187,193 ---- export def FTent() # This function checks for valid cl syntax in the first five lines. ! # Look for either an opening comment, '#', or a block start, '{'. # If not found, assume SGML. var lnum = 1 while lnum < 6 *************** *** 410,415 **** --- 429,464 ---- setf nroff enddef + # Returns true if file content looks like LambdaProlog + 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 + l = nextnonblank(l + 1) + endwhile + # this pattern must not catch a go.mod file + return getline(l) =~ '\") =~ '\ 50 ? 50 : line("$") *************** *** 572,578 **** return endif endfor ! setf m4 " Default: Sendmail .mc file enddef # Called from filetype.vim and scripts.vim. --- 633,639 ---- return endif endfor ! setf m4 # Default: Sendmail .mc file enddef # Called from filetype.vim and scripts.vim. *************** *** 735,740 **** --- 796,809 ---- return 0 enddef + export def FTsys() + if IsRapid() + setf rapid + else + setf bat + endif + enddef + # Choose context, plaintex, or tex (LaTeX) based on these rules: # 1. Check the first line of the file for "%&". # 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords. *** ../vim-8.2.4719/runtime/doc/filetype.txt 2021-11-27 17:21:54.085161469 +0000 --- runtime/doc/filetype.txt 2022-04-09 15:06:28.036883524 +0100 *************** *** 133,158 **** argument was used. *filetype-overrule* ! When the same extension is used for two filetypes, Vim tries to guess what ! kind of file it is. This doesn't always work. A number of global variables ! can be used to overrule the filetype used for certain extensions: file name variable ~ *.asa g:filetype_asa |ft-aspvbs-syntax| |ft-aspperl-syntax| *.asm g:asmsyntax |ft-asm-syntax| *.asp g:filetype_asp |ft-aspvbs-syntax| |ft-aspperl-syntax| ! *.fs g:filetype_fs |ft-forth-syntax| *.i g:filetype_i |ft-progress-syntax| *.inc g:filetype_inc *.m g:filetype_m |ft-mathematica-syntax| *.p g:filetype_p |ft-pascal-syntax| *.pl g:filetype_pl *.pp g:filetype_pp |ft-pascal-syntax| *.prg g:filetype_prg *.sh g:bash_is_sh |ft-sh-syntax| *.tex g:tex_flavor |ft-tex-plugin| *.w g:filetype_w |ft-cweb-syntax| *filetype-ignore* To avoid that certain files are being inspected, the g:ft_ignore_pat variable is used. The default value is set like this: > --- 133,167 ---- argument was used. *filetype-overrule* ! When the same extension is used for multiple filetypes, Vim tries to guess ! what kind of file it is. This doesn't always work. A number of global ! variables can be used to overrule the filetype used for certain extensions: file name variable ~ *.asa g:filetype_asa |ft-aspvbs-syntax| |ft-aspperl-syntax| *.asm g:asmsyntax |ft-asm-syntax| *.asp g:filetype_asp |ft-aspvbs-syntax| |ft-aspperl-syntax| ! *.bas g:filetype_bas |ft-basic-syntax| ! *.dat g:filetype_dat ! *.frm g:filetype_frm |ft-form-syntax| ! *.fs g:filetype_fs |ft-forth-syntax| *.i g:filetype_i |ft-progress-syntax| *.inc g:filetype_inc *.m g:filetype_m |ft-mathematica-syntax| + *.mod g:filetype_mod *.p g:filetype_p |ft-pascal-syntax| *.pl g:filetype_pl *.pp g:filetype_pp |ft-pascal-syntax| *.prg g:filetype_prg + *.src g:filetype_src *.sh g:bash_is_sh |ft-sh-syntax| *.tex g:tex_flavor |ft-tex-plugin| *.w g:filetype_w |ft-cweb-syntax| + For a few filetypes the global variable is used only when the filetype could + not be detected: + *.r g:filetype_r |ft-rexx-syntax| + *filetype-ignore* To avoid that certain files are being inspected, the g:ft_ignore_pat variable is used. The default value is set like this: > *** ../vim-8.2.4719/runtime/filetype.vim 2022-04-08 19:55:36.216168883 +0100 --- runtime/filetype.vim 2022-04-09 15:06:28.040883522 +0100 *************** *** 205,215 **** " FreeBasic file (similar to QBasic) au BufNewFile,BufRead *.fb setf freebasic ! " Batch file for MSDOS. ! au BufNewFile,BufRead *.bat,*.sys setf dosbatch " *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd. au BufNewFile,BufRead *.cmd \ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif " Batch file for 4DOS au BufNewFile,BufRead *.btm call dist#ft#FTbtm() --- 205,217 ---- " FreeBasic file (similar to QBasic) au BufNewFile,BufRead *.fb setf freebasic ! " Batch file for MSDOS. See dist#ft#FTsys for *.sys ! au BufNewFile,BufRead *.bat setf dosbatch " *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd. au BufNewFile,BufRead *.cmd \ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif + " ABB RAPID or Batch file for MSDOS. + au BufNewFile,BufRead *.sys\c call dist#ft#FTsys() " Batch file for 4DOS au BufNewFile,BufRead *.btm call dist#ft#FTbtm() *************** *** 360,372 **** " Clever or dtd au BufNewFile,BufRead *.ent call dist#ft#FTent() ! " Clipper (or FoxPro; could also be eviews) ! au BufNewFile,BufRead *.prg ! \ if exists("g:filetype_prg") | ! \ exe "setf " . g:filetype_prg | ! \ else | ! \ setf clipper | ! \ endif " Clojure au BufNewFile,BufRead *.clj,*.cljs,*.cljx,*.cljc setf clojure --- 362,369 ---- " Clever or dtd au BufNewFile,BufRead *.ent call dist#ft#FTent() ! " Clipper, FoxPro, ABB RAPID or eviews ! au BufNewFile,BufRead *.prg\c call dist#ft#FTprg() " Clojure au BufNewFile,BufRead *.clj,*.cljs,*.cljx,*.cljc setf clojure *************** *** 444,450 **** au BufNewFile,BufRead *.qc setf c " Configure files ! au BufNewFile,BufRead *.cfg setf cfg " Cucumber au BufNewFile,BufRead *.feature setf cucumber --- 441,447 ---- au BufNewFile,BufRead *.qc setf c " Configure files ! au BufNewFile,BufRead *.cfg\c call dist#ft#FTcfg() " Cucumber au BufNewFile,BufRead *.feature setf cucumber *************** *** 980,986 **** " Limits au BufNewFile,BufRead */etc/limits,*/etc/*limits.conf,*/etc/*limits.d/*.conf setf limits ! " LambdaProlog (*.mod too, see Modsim) au BufNewFile,BufRead *.sig setf lprolog " LDAP LDIF --- 977,983 ---- " Limits au BufNewFile,BufRead */etc/limits,*/etc/*limits.conf,*/etc/*limits.d/*.conf setf limits ! " LambdaProlog (see dist#ft#FTmod for *.mod) au BufNewFile,BufRead *.sig setf lprolog " LDAP LDIF *************** *** 1143,1160 **** " Symbian meta-makefile definition (MMP) au BufNewFile,BufRead *.mmp setf mmp ! " Modsim III (or LambdaProlog) ! au BufNewFile,BufRead *.mod ! \ if expand("") =~ '\' | ! \ setf lprolog | ! \ else | ! \ setf modsim3 | ! \ endif ! " Modula-2 (.md removed in favor of Markdown) ! au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.mi setf modula2 " Modula-3 (.m3, .i3, .mg, .ig) au BufNewFile,BufRead *.[mi][3g] setf modula3 --- 1140,1150 ---- " Symbian meta-makefile definition (MMP) au BufNewFile,BufRead *.mmp setf mmp ! " ABB Rapid, Modula-2, Modsim III or LambdaProlog ! au BufNewFile,BufRead *.mod\c call dist#ft#FTmod() ! " Modula-2 (.md removed in favor of Markdown, see dist#ft#FTmod for *.MOD) ! au BufNewFile,BufRead *.m2,*.DEF,*.mi setf modula2 " Modula-3 (.m3, .i3, .mg, .ig) au BufNewFile,BufRead *.[mi][3g] setf modula3 *** ../vim-8.2.4719/src/testdir/test_filetype.vim 2022-04-08 19:55:36.216168883 +0100 --- src/testdir/test_filetype.vim 2022-04-09 15:13:03.092634918 +0100 *************** *** 99,105 **** \ 'cdrtoc': ['file.toc'], \ 'cf': ['file.cfm', 'file.cfi', 'file.cfc'], \ 'cfengine': ['cfengine.conf'], ! \ 'cfg': ['file.cfg', 'file.hgrc', 'filehgrc', 'hgrc', 'some-hgrc'], \ 'ch': ['file.chf'], \ 'chaiscript': ['file.chai'], \ 'chaskell': ['file.chs'], --- 99,105 ---- \ 'cdrtoc': ['file.toc'], \ 'cf': ['file.cfm', 'file.cfi', 'file.cfc'], \ 'cfengine': ['cfengine.conf'], ! \ 'cfg': ['file.hgrc', 'filehgrc', 'hgrc', 'some-hgrc'], \ 'ch': ['file.chf'], \ 'chaiscript': ['file.chai'], \ 'chaskell': ['file.chs'], *************** *** 150,156 **** \ 'dircolors': ['.dir_colors', '.dircolors', '/etc/DIR_COLORS', 'any/etc/DIR_COLORS'], \ 'dnsmasq': ['/etc/dnsmasq.conf', '/etc/dnsmasq.d/file', 'any/etc/dnsmasq.conf', 'any/etc/dnsmasq.d/file'], \ 'dockerfile': ['Containerfile', 'Dockerfile', 'file.Dockerfile', 'Dockerfile.debian', 'Containerfile.something'], ! \ 'dosbatch': ['file.bat', 'file.sys'], \ 'dosini': ['.editorconfig', '/etc/pacman.conf', '/etc/yum.conf', 'file.ini', 'npmrc', '.npmrc', 'php.ini', 'php.ini-5', 'php.ini-file', '/etc/yum.repos.d/file', 'any/etc/pacman.conf', 'any/etc/yum.conf', 'any/etc/yum.repos.d/file', 'file.wrap'], \ 'dot': ['file.dot', 'file.gv'], \ 'dracula': ['file.drac', 'file.drc', 'filelvs', 'filelpe', 'drac.file', 'lpe', 'lvs', 'some-lpe', 'some-lvs'], --- 150,156 ---- \ 'dircolors': ['.dir_colors', '.dircolors', '/etc/DIR_COLORS', 'any/etc/DIR_COLORS'], \ 'dnsmasq': ['/etc/dnsmasq.conf', '/etc/dnsmasq.d/file', 'any/etc/dnsmasq.conf', 'any/etc/dnsmasq.d/file'], \ 'dockerfile': ['Containerfile', 'Dockerfile', 'file.Dockerfile', 'Dockerfile.debian', 'Containerfile.something'], ! \ 'dosbatch': ['file.bat'], \ 'dosini': ['.editorconfig', '/etc/pacman.conf', '/etc/yum.conf', 'file.ini', 'npmrc', '.npmrc', 'php.ini', 'php.ini-5', 'php.ini-file', '/etc/yum.repos.d/file', 'any/etc/pacman.conf', 'any/etc/yum.conf', 'any/etc/yum.repos.d/file', 'file.wrap'], \ 'dot': ['file.dot', 'file.gv'], \ 'dracula': ['file.drac', 'file.drc', 'filelvs', 'filelpe', 'drac.file', 'lpe', 'lvs', 'some-lpe', 'some-lvs'], *************** *** 616,622 **** \ } let s:filename_case_checks = { ! \ 'modula2': ['file.DEF', 'file.MOD'], \ 'bzl': ['file.BUILD', 'BUILD'], \ } --- 616,622 ---- \ } let s:filename_case_checks = { ! \ 'modula2': ['file.DEF'], \ 'bzl': ['file.BUILD', 'BUILD'], \ } *************** *** 832,837 **** --- 832,867 ---- filetype off endfunc + " Test dist#ft#FTcfg() + func Test_cfg_file() + filetype on + + " *.cfg defaults to cfg + call writefile(['looks like cfg'], 'cfgfile.cfg') + split cfgfile.cfg + call assert_equal('cfg', &filetype) + + let g:filetype_cfg = 'other' + edit + call assert_equal('other', &filetype) + bwipe! + unlet g:filetype_cfg + + " RAPID cfg + let ext = 'cfg' + for i in ['EIO', 'MMC', 'MOC', 'PROC', 'SIO', 'SYS'] + call writefile([i .. ':CFG'], 'cfgfile.' .. ext) + execute "split cfgfile." .. ext + call assert_equal('rapid', &filetype) + bwipe! + call delete('cfgfile.' .. ext) + " check different case of file extension + let ext = substitute(ext, '\(\l\)', '\u\1', '') + endfor + + filetype off + endfunc + func Test_d_file() filetype on *************** *** 1277,1282 **** --- 1307,1387 ---- filetype off endfunc + func Test_mod_file() + filetype on + + " *.mod defaults to Modsim III + call writefile(['locks like Modsim III'], 'modfile.mod') + split modfile.mod + call assert_equal('modsim3', &filetype) + bwipe! + + " Users preference set by g:filetype_mod + let g:filetype_mod = 'lprolog' + split modfile.mod + call assert_equal('lprolog', &filetype) + unlet g:filetype_mod + bwipe! + + " RAPID header start with a line containing only "%%%", + " but is not always present. + call writefile(['%%%'], 'modfile.mod') + split modfile.mod + call assert_equal('rapid', &filetype) + bwipe! + call delete('modfile.mod') + + " RAPID supports umlauts in module names, leading spaces, + " the .mod extension is not case sensitive. + call writefile([' module ÜmlautModule'], 'modfile.Mod') + split modfile.Mod + call assert_equal('rapid', &filetype) + bwipe! + call delete('modfile.Mod') + + " RAPID is not case sensitive, embedded spaces, sysmodule, + " file starts with empty line(s). + call writefile(['', 'MODULE rapidmödüle (SYSMODULE,NOSTEPIN)'], 'modfile.MOD') + split modfile.MOD + call assert_equal('rapid', &filetype) + bwipe! + + " Modula-2 MODULE not start of line + call writefile(['IMPLEMENTATION MODULE Module2Mod;'], 'modfile.MOD') + split modfile.MOD + call assert_equal('modula2', &filetype) + bwipe! + + " Modula-2 with comment and empty lines prior MODULE + call writefile(['', '(* with', ' comment *)', '', 'MODULE Module2Mod;'], 'modfile.MOD') + split modfile.MOD + call assert_equal('modula2', &filetype) + bwipe! + call delete('modfile.MOD') + + " LambdaProlog module + call writefile(['module lpromod.'], 'modfile.mod') + split modfile.mod + call assert_equal('lprolog', &filetype) + bwipe! + + " LambdaProlog with comment and empty lines prior module + call writefile(['', '% with', '% comment', '', 'module lpromod.'], 'modfile.mod') + split modfile.mod + call assert_equal('lprolog', &filetype) + bwipe! + call delete('modfile.mod') + + " go.mod + call writefile(['module example.com/M'], 'go.mod') + split go.mod + call assert_equal('gomod', &filetype) + bwipe! + call delete('go.mod') + + filetype off + endfunc + func Test_patch_file() filetype on *************** *** 1345,1350 **** --- 1450,1499 ---- filetype off endfunc + " Test dist#ft#FTprg() + func Test_prg_file() + filetype on + + " *.prg defaults to clipper + call writefile(['looks like clipper'], 'prgfile.prg') + split prgfile.prg + call assert_equal('clipper', &filetype) + bwipe! + + " Users preference set by g:filetype_prg + let g:filetype_prg = 'eviews' + split prgfile.prg + call assert_equal('eviews', &filetype) + unlet g:filetype_prg + bwipe! + + " RAPID header start with a line containing only "%%%", + " but is not always present. + call writefile(['%%%'], 'prgfile.prg') + split prgfile.prg + call assert_equal('rapid', &filetype) + bwipe! + call delete('prgfile.prg') + + " RAPID supports umlauts in module names, leading spaces, + " the .prg extension is not case sensitive. + call writefile([' module ÜmlautModule'], 'prgfile.Prg') + split prgfile.Prg + call assert_equal('rapid', &filetype) + bwipe! + call delete('prgfile.Prg') + + " RAPID is not case sensitive, embedded spaces, sysmodule, + " file starts with empty line(s). + call writefile(['', 'MODULE rapidmödüle (SYSMODULE,NOSTEPIN)'], 'prgfile.PRG') + split prgfile.PRG + call assert_equal('rapid', &filetype) + bwipe! + call delete('prgfile.PRG') + + filetype off + endfunc + func Test_src_file() filetype on *************** *** 1377,1382 **** --- 1526,1567 ---- filetype off endfunc + + func Test_sys_file() + filetype on + + " *.sys defaults to Batch file for MSDOS + call writefile(['looks like dos batch'], 'sysfile.sys') + split sysfile.sys + call assert_equal('bat', &filetype) + bwipe! + + " RAPID header start with a line containing only "%%%", + " but is not always present. + call writefile(['%%%'], 'sysfile.sys') + split sysfile.sys + call assert_equal('rapid', &filetype) + bwipe! + call delete('sysfile.sys') + + " RAPID supports umlauts in module names, leading spaces, + " the .sys extension is not case sensitive. + call writefile([' module ÜmlautModule'], 'sysfile.Sys') + split sysfile.Sys + call assert_equal('rapid', &filetype) + bwipe! + call delete('sysfile.Sys') + + " RAPID is not case sensitive, embedded spaces, sysmodule, + " file starts with empty line(s). + call writefile(['', 'MODULE rapidmödüle (SYSMODULE,NOSTEPIN)'], 'sysfile.SYS') + split sysfile.SYS + call assert_equal('rapid', &filetype) + bwipe! + call delete('sysfile.SYS') + + filetype off + endfunc func Test_tex_file() filetype on *** ../vim-8.2.4719/src/version.c 2022-04-09 13:34:02.780412358 +0100 --- src/version.c 2022-04-09 15:13:25.572620048 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4720, /**/ -- ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot. King of all Britons, defeator of the Saxons, sovereign of all England! [Pause] SOLDIER: Get away! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@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 ///