# HG changeset patch # User Bram Moolenaar # Date 1686341703 -7200 # Node ID c777d71cf397ad754894fdaf94eaf6aeef10e34f # Parent fa05c32c24ca482a65830d03025175b194f1384d patch 9.0.1623: the program to filetype translation is not exported Commit: https://github.com/vim/vim/commit/f07d1a7108f29068efeb61d91454c4120ab5ae6c Author: Bram Moolenaar Date: Fri Jun 9 21:01:47 2023 +0100 patch 9.0.1623: the program to filetype translation is not exported Problem: The program to filetype translation is not exported. Solution: Export Exe2filetype(). diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim --- a/runtime/autoload/dist/ft.vim +++ b/runtime/autoload/dist/ft.vim @@ -3,7 +3,7 @@ vim9script # Vim functions for file type detection # # Maintainer: Bram Moolenaar -# Last Change: 2023 Apr 22 +# Last Change: 2023 Jun 09 # These functions are moved here from runtime/filetype.vim to make startup # faster. @@ -362,8 +362,8 @@ export def ProtoCheck(default: string) else # recognize Prolog by specific text in the first non-empty line # require a blank after the '%' because Perl uses "%list" and "%translate" - var l = getline(nextnonblank(1)) - if l =~ '\' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-' + var lnum = getline(nextnonblank(1)) + if lnum =~ '\' || lnum =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || lnum =~ ':-' setf prolog else exe 'setf ' .. default @@ -472,12 +472,12 @@ enddef 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) + var lnum: number = nextnonblank(1) + while lnum > 0 && lnum < line('$') && getline(lnum) =~ '^\s*%' # LambdaProlog comment + lnum = nextnonblank(lnum + 1) endwhile # this pattern must not catch a go.mod file - return getline(l) =~ '\' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-' + var line = getline(nextnonblank(1)) + if line =~ '\' || line =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || line =~ ':-' setf prolog else setf perl @@ -678,26 +678,24 @@ export def McSetf() enddef # Called from filetype.vim and scripts.vim. -export def SetFileTypeSH(name: string) - if did_filetype() +# When "setft" is passed and false then the 'filetype' option is not set. +export def SetFileTypeSH(name: string, setft = true): string + if setft && did_filetype() # Filetype was already detected - return + return '' endif - if expand("") =~ g:ft_ignore_pat - return + if setft && expand("") =~ g:ft_ignore_pat + return '' endif if name =~ '\' # Some .sh scripts contain #!/bin/csh. - SetFileTypeShell("csh") - return + return SetFileTypeShell("csh", setft) elseif name =~ '\' # Some .sh scripts contain #!/bin/tcsh. - SetFileTypeShell("tcsh") - return + return SetFileTypeShell("tcsh", setft) elseif name =~ '\' # Some .sh scripts contain #!/bin/zsh. - SetFileTypeShell("zsh") - return + return SetFileTypeShell("zsh", setft) elseif name =~ '\' b:is_kornshell = 1 if exists("b:is_bash") @@ -724,34 +722,43 @@ export def SetFileTypeSH(name: string) unlet b:is_bash endif endif - SetFileTypeShell("sh") + + return SetFileTypeShell("sh", setft) enddef # For shell-like file types, check for an "exec" command hidden in a comment, # as used for Tcl. +# When "setft" is passed and false then the 'filetype' option is not set. # Also called from scripts.vim, thus can't be local to this script. -export def SetFileTypeShell(name: string) - if did_filetype() +export def SetFileTypeShell(name: string, setft = true): string + if setft && did_filetype() # Filetype was already detected - return + return '' endif - if expand("") =~ g:ft_ignore_pat - return + if setft && expand("") =~ g:ft_ignore_pat + return '' endif - var l = 2 - while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)' + + var lnum = 2 + while lnum < 20 && lnum < line("$") && getline(lnum) =~ '^\s*\(#\|$\)' # Skip empty and comment lines. - l += 1 + lnum += 1 endwhile - if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$' + if lnum < line("$") && getline(lnum) =~ '\s*exec\s' && getline(lnum - 1) =~ '^\s*#.*\\$' # Found an "exec" line after a comment with continuation - var n = substitute(getline(l), '\s*exec\s\+\([^ ]*/\)\=', '', '') + var n = substitute(getline(lnum), '\s*exec\s\+\([^ ]*/\)\=', '', '') if n =~ '\ -# Last Change: 2023 Jun 08 +# Last Change: 2023 Jun 09 export def DetectFiletype() var line1 = getline(1) @@ -53,155 +53,164 @@ def DetectFromHashBang(firstline: string name = 'wish' endif + var ft = Exe2filetype(name, line1) + if ft != '' + exe 'setl ft=' .. ft + endif +enddef + +# Returns the filetype name associated with program "name". +# "line1" is the #! line at the top of the file. Use the same as "name" if +# not available. +# Returns an empty string when not recognized. +export def Exe2filetype(name: string, line1: string): string # Bourne-like shell scripts: bash bash2 dash ksh ksh93 sh if name =~ '^\(bash\d*\|dash\|ksh\d*\|sh\)\>' - call dist#ft#SetFileTypeSH(line1) + return dist#ft#SetFileTypeSH(line1, false) # csh scripts elseif name =~ '^csh\>' - if exists("g:filetype_csh") - call dist#ft#SetFileTypeShell(g:filetype_csh) - else - call dist#ft#SetFileTypeShell("csh") - endif + return dist#ft#SetFileTypeShell(exists("g:filetype_csh") ? g:filetype_csh : 'csh', false) # tcsh scripts elseif name =~ '^tcsh\>' - call dist#ft#SetFileTypeShell("tcsh") + return dist#ft#SetFileTypeShell("tcsh", false) # Z shell scripts elseif name =~ '^zsh\>' - setl ft=zsh + return 'zsh' # TCL scripts elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>' - setl ft=tcl + return 'tcl' # Expect scripts elseif name =~ '^expect\>' - setl ft=expect + return 'expect' # Gnuplot scripts elseif name =~ '^gnuplot\>' - setl ft=gnuplot + return 'gnuplot' # Makefiles elseif name =~ 'make\>' - setl ft=make + return 'make' # Pike elseif name =~ '^pike\%(\>\|[0-9]\)' - setl ft=pike + return 'pike' # Lua elseif name =~ 'lua' - setl ft=lua + return 'lua' # Perl elseif name =~ 'perl' - setl ft=perl + return 'perl' # PHP elseif name =~ 'php' - setl ft=php + return 'php' # Python elseif name =~ 'python' - setl ft=python + return 'python' # Groovy elseif name =~ '^groovy\>' - setl ft=groovy + return 'groovy' # Raku elseif name =~ 'raku' - setl ft=raku + return 'raku' # Ruby elseif name =~ 'ruby' - setl ft=ruby + return 'ruby' # JavaScript elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>' - setl ft=javascript + return 'javascript' # BC calculator elseif name =~ '^bc\>' - setl ft=bc + return 'bc' # sed elseif name =~ 'sed\>' - setl ft=sed + return 'sed' # OCaml-scripts elseif name =~ 'ocaml' - setl ft=ocaml + return 'ocaml' # Awk scripts; also finds "gawk" elseif name =~ 'awk\>' - setl ft=awk + return 'awk' # Website MetaLanguage elseif name =~ 'wml' - setl ft=wml + return 'wml' # Scheme scripts elseif name =~ 'scheme' - setl ft=scheme + return 'scheme' # CFEngine scripts elseif name =~ 'cfengine' - setl ft=cfengine + return 'cfengine' # Erlang scripts elseif name =~ 'escript' - setl ft=erlang + return 'erlang' # Haskell elseif name =~ 'haskell' - setl ft=haskell + return 'haskell' # Scala elseif name =~ 'scala\>' - setl ft=scala + return 'scala' # Clojure elseif name =~ 'clojure' - setl ft=clojure + return 'clojure' # Free Pascal elseif name =~ 'instantfpc\>' - setl ft=pascal + return 'pascal' # Fennel elseif name =~ 'fennel\>' - setl ft=fennel + return 'fennel' # MikroTik RouterOS script elseif name =~ 'rsc\>' - setl ft=routeros + return 'routeros' # Fish shell elseif name =~ 'fish\>' - setl ft=fish + return 'fish' # Gforth elseif name =~ 'gforth\>' - setl ft=forth + return 'forth' # Icon elseif name =~ 'icon\>' - setl ft=icon + return 'icon' # Guile elseif name =~ 'guile' - setl ft=scheme + return 'scheme' # Nix elseif name =~ 'nix-shell' - setl ft=nix + return 'nix' endif + + return '' enddef diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1623, +/**/ 1622, /**/ 1621,