0
0
mirror of https://github.com/vim/vim.git synced 2025-07-25 10:54:51 -04:00

patch 9.0.1623: the program to filetype translation is not exported

Problem:    The program to filetype translation is not exported.
Solution:   Export Exe2filetype().
This commit is contained in:
Bram Moolenaar 2023-06-09 21:01:47 +01:00
parent 740df76c90
commit f07d1a7108
3 changed files with 93 additions and 75 deletions

View File

@ -3,7 +3,7 @@ vim9script
# Vim functions for file type detection # Vim functions for file type detection
# #
# Maintainer: Bram Moolenaar <Bram@vim.org> # Maintainer: Bram Moolenaar <Bram@vim.org>
# Last Change: 2023 Apr 22 # Last Change: 2023 Jun 09
# These functions are moved here from runtime/filetype.vim to make startup # These functions are moved here from runtime/filetype.vim to make startup
# faster. # faster.
@ -362,8 +362,8 @@ export def ProtoCheck(default: string)
else else
# recognize Prolog by specific text in the first non-empty line # recognize Prolog by specific text in the first non-empty line
# require a blank after the '%' because Perl uses "%list" and "%translate" # require a blank after the '%' because Perl uses "%list" and "%translate"
var l = getline(nextnonblank(1)) var lnum = getline(nextnonblank(1))
if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-' if lnum =~ '\<prolog\>' || lnum =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || lnum =~ ':-'
setf prolog setf prolog
else else
exe 'setf ' .. default exe 'setf ' .. default
@ -472,12 +472,12 @@ enddef
def IsLProlog(): bool def IsLProlog(): bool
# skip apparent comments and blank lines, what looks like # skip apparent comments and blank lines, what looks like
# LambdaProlog comment may be RAPID header # LambdaProlog comment may be RAPID header
var l: number = nextnonblank(1) var lnum: number = nextnonblank(1)
while l > 0 && l < line('$') && getline(l) =~ '^\s*%' # LambdaProlog comment while lnum > 0 && lnum < line('$') && getline(lnum) =~ '^\s*%' # LambdaProlog comment
l = nextnonblank(l + 1) lnum = nextnonblank(lnum + 1)
endwhile endwhile
# this pattern must not catch a go.mod file # this pattern must not catch a go.mod file
return getline(l) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)' return getline(lnum) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)'
enddef enddef
# Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod # Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod
@ -504,8 +504,8 @@ export def FTpl()
else else
# recognize Prolog by specific text in the first non-empty line # recognize Prolog by specific text in the first non-empty line
# require a blank after the '%' because Perl uses "%list" and "%translate" # require a blank after the '%' because Perl uses "%list" and "%translate"
var l = getline(nextnonblank(1)) var line = getline(nextnonblank(1))
if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-' if line =~ '\<prolog\>' || line =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || line =~ ':-'
setf prolog setf prolog
else else
setf perl setf perl
@ -678,26 +678,24 @@ export def McSetf()
enddef enddef
# Called from filetype.vim and scripts.vim. # Called from filetype.vim and scripts.vim.
export def SetFileTypeSH(name: string) # When "setft" is passed and false then the 'filetype' option is not set.
if did_filetype() export def SetFileTypeSH(name: string, setft = true): string
if setft && did_filetype()
# Filetype was already detected # Filetype was already detected
return return ''
endif endif
if expand("<amatch>") =~ g:ft_ignore_pat if setft && expand("<amatch>") =~ g:ft_ignore_pat
return return ''
endif endif
if name =~ '\<csh\>' if name =~ '\<csh\>'
# Some .sh scripts contain #!/bin/csh. # Some .sh scripts contain #!/bin/csh.
SetFileTypeShell("csh") return SetFileTypeShell("csh", setft)
return
elseif name =~ '\<tcsh\>' elseif name =~ '\<tcsh\>'
# Some .sh scripts contain #!/bin/tcsh. # Some .sh scripts contain #!/bin/tcsh.
SetFileTypeShell("tcsh") return SetFileTypeShell("tcsh", setft)
return
elseif name =~ '\<zsh\>' elseif name =~ '\<zsh\>'
# Some .sh scripts contain #!/bin/zsh. # Some .sh scripts contain #!/bin/zsh.
SetFileTypeShell("zsh") return SetFileTypeShell("zsh", setft)
return
elseif name =~ '\<ksh\>' elseif name =~ '\<ksh\>'
b:is_kornshell = 1 b:is_kornshell = 1
if exists("b:is_bash") if exists("b:is_bash")
@ -724,34 +722,43 @@ export def SetFileTypeSH(name: string)
unlet b:is_bash unlet b:is_bash
endif endif
endif endif
SetFileTypeShell("sh")
return SetFileTypeShell("sh", setft)
enddef enddef
# For shell-like file types, check for an "exec" command hidden in a comment, # For shell-like file types, check for an "exec" command hidden in a comment,
# as used for Tcl. # 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. # Also called from scripts.vim, thus can't be local to this script.
export def SetFileTypeShell(name: string) export def SetFileTypeShell(name: string, setft = true): string
if did_filetype() if setft && did_filetype()
# Filetype was already detected # Filetype was already detected
return return ''
endif endif
if expand("<amatch>") =~ g:ft_ignore_pat if setft && expand("<amatch>") =~ g:ft_ignore_pat
return return ''
endif 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. # Skip empty and comment lines.
l += 1 lnum += 1
endwhile 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 # 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 =~ '\<tclsh\|\<wish' if n =~ '\<tclsh\|\<wish'
setf tcl if setft
return setf tcl
endif
return 'tcl'
endif endif
endif endif
exe "setf " .. name
if setft
exe "setf " .. name
endif
return name
enddef enddef
export def CSH() export def CSH()

View File

@ -4,7 +4,7 @@ vim9script
# Invoked from "scripts.vim" in 'runtimepath' # Invoked from "scripts.vim" in 'runtimepath'
# #
# Maintainer: Bram Moolenaar <Bram@vim.org> # Maintainer: Bram Moolenaar <Bram@vim.org>
# Last Change: 2023 Jun 08 # Last Change: 2023 Jun 09
export def DetectFiletype() export def DetectFiletype()
var line1 = getline(1) var line1 = getline(1)
@ -53,155 +53,164 @@ def DetectFromHashBang(firstline: string)
name = 'wish' name = 'wish'
endif 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 # Bourne-like shell scripts: bash bash2 dash ksh ksh93 sh
if name =~ '^\(bash\d*\|dash\|ksh\d*\|sh\)\>' if name =~ '^\(bash\d*\|dash\|ksh\d*\|sh\)\>'
call dist#ft#SetFileTypeSH(line1) return dist#ft#SetFileTypeSH(line1, false)
# csh scripts # csh scripts
elseif name =~ '^csh\>' elseif name =~ '^csh\>'
if exists("g:filetype_csh") return dist#ft#SetFileTypeShell(exists("g:filetype_csh") ? g:filetype_csh : 'csh', false)
call dist#ft#SetFileTypeShell(g:filetype_csh)
else
call dist#ft#SetFileTypeShell("csh")
endif
# tcsh scripts # tcsh scripts
elseif name =~ '^tcsh\>' elseif name =~ '^tcsh\>'
call dist#ft#SetFileTypeShell("tcsh") return dist#ft#SetFileTypeShell("tcsh", false)
# Z shell scripts # Z shell scripts
elseif name =~ '^zsh\>' elseif name =~ '^zsh\>'
setl ft=zsh return 'zsh'
# TCL scripts # TCL scripts
elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>' elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
setl ft=tcl return 'tcl'
# Expect scripts # Expect scripts
elseif name =~ '^expect\>' elseif name =~ '^expect\>'
setl ft=expect return 'expect'
# Gnuplot scripts # Gnuplot scripts
elseif name =~ '^gnuplot\>' elseif name =~ '^gnuplot\>'
setl ft=gnuplot return 'gnuplot'
# Makefiles # Makefiles
elseif name =~ 'make\>' elseif name =~ 'make\>'
setl ft=make return 'make'
# Pike # Pike
elseif name =~ '^pike\%(\>\|[0-9]\)' elseif name =~ '^pike\%(\>\|[0-9]\)'
setl ft=pike return 'pike'
# Lua # Lua
elseif name =~ 'lua' elseif name =~ 'lua'
setl ft=lua return 'lua'
# Perl # Perl
elseif name =~ 'perl' elseif name =~ 'perl'
setl ft=perl return 'perl'
# PHP # PHP
elseif name =~ 'php' elseif name =~ 'php'
setl ft=php return 'php'
# Python # Python
elseif name =~ 'python' elseif name =~ 'python'
setl ft=python return 'python'
# Groovy # Groovy
elseif name =~ '^groovy\>' elseif name =~ '^groovy\>'
setl ft=groovy return 'groovy'
# Raku # Raku
elseif name =~ 'raku' elseif name =~ 'raku'
setl ft=raku return 'raku'
# Ruby # Ruby
elseif name =~ 'ruby' elseif name =~ 'ruby'
setl ft=ruby return 'ruby'
# JavaScript # JavaScript
elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>' elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>'
setl ft=javascript return 'javascript'
# BC calculator # BC calculator
elseif name =~ '^bc\>' elseif name =~ '^bc\>'
setl ft=bc return 'bc'
# sed # sed
elseif name =~ 'sed\>' elseif name =~ 'sed\>'
setl ft=sed return 'sed'
# OCaml-scripts # OCaml-scripts
elseif name =~ 'ocaml' elseif name =~ 'ocaml'
setl ft=ocaml return 'ocaml'
# Awk scripts; also finds "gawk" # Awk scripts; also finds "gawk"
elseif name =~ 'awk\>' elseif name =~ 'awk\>'
setl ft=awk return 'awk'
# Website MetaLanguage # Website MetaLanguage
elseif name =~ 'wml' elseif name =~ 'wml'
setl ft=wml return 'wml'
# Scheme scripts # Scheme scripts
elseif name =~ 'scheme' elseif name =~ 'scheme'
setl ft=scheme return 'scheme'
# CFEngine scripts # CFEngine scripts
elseif name =~ 'cfengine' elseif name =~ 'cfengine'
setl ft=cfengine return 'cfengine'
# Erlang scripts # Erlang scripts
elseif name =~ 'escript' elseif name =~ 'escript'
setl ft=erlang return 'erlang'
# Haskell # Haskell
elseif name =~ 'haskell' elseif name =~ 'haskell'
setl ft=haskell return 'haskell'
# Scala # Scala
elseif name =~ 'scala\>' elseif name =~ 'scala\>'
setl ft=scala return 'scala'
# Clojure # Clojure
elseif name =~ 'clojure' elseif name =~ 'clojure'
setl ft=clojure return 'clojure'
# Free Pascal # Free Pascal
elseif name =~ 'instantfpc\>' elseif name =~ 'instantfpc\>'
setl ft=pascal return 'pascal'
# Fennel # Fennel
elseif name =~ 'fennel\>' elseif name =~ 'fennel\>'
setl ft=fennel return 'fennel'
# MikroTik RouterOS script # MikroTik RouterOS script
elseif name =~ 'rsc\>' elseif name =~ 'rsc\>'
setl ft=routeros return 'routeros'
# Fish shell # Fish shell
elseif name =~ 'fish\>' elseif name =~ 'fish\>'
setl ft=fish return 'fish'
# Gforth # Gforth
elseif name =~ 'gforth\>' elseif name =~ 'gforth\>'
setl ft=forth return 'forth'
# Icon # Icon
elseif name =~ 'icon\>' elseif name =~ 'icon\>'
setl ft=icon return 'icon'
# Guile # Guile
elseif name =~ 'guile' elseif name =~ 'guile'
setl ft=scheme return 'scheme'
# Nix # Nix
elseif name =~ 'nix-shell' elseif name =~ 'nix-shell'
setl ft=nix return 'nix'
endif endif
return ''
enddef enddef

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1623,
/**/ /**/
1622, 1622,
/**/ /**/