Patch 9.0.1623
Problem: The program to filetype translation is not exported.
Solution: Export Exe2filetype().
Files: runtime/autoload/dist/ft.vim, runtime/autoload/dist/script.vim
*** ../vim-9.0.1622/runtime/autoload/dist/ft.vim 2023-05-29 19:59:38.217805411 +0100
--- runtime/autoload/dist/ft.vim 2023-06-09 20:57:34.635375695 +0100
***************
*** 3,9 ****
# Vim functions for file type detection
#
# Maintainer: Bram Moolenaar <
Br...@vim.org>
! # Last Change: 2022 Apr 13
# These functions are moved here from runtime/filetype.vim to make startup
# faster.
--- 3,9 ----
# Vim functions for file type detection
#
# Maintainer: Bram Moolenaar <
Br...@vim.org>
! # Last Change: 2023 Jun 09
# These functions are moved here from runtime/filetype.vim to make startup
# faster.
***************
*** 362,369 ****
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 =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
setf prolog
else
exe 'setf ' .. default
--- 362,369 ----
else
# recognize Prolog by specific text in the first non-empty line
# require a blank after the '%' because Perl uses "%list" and "%translate"
! var lnum = getline(nextnonblank(1))
! if lnum =~ '\<prolog\>' || lnum =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || lnum =~ ':-'
setf prolog
else
exe 'setf ' .. default
***************
*** 472,483 ****
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) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)'
enddef
# Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod
--- 472,483 ----
def IsLProlog(): bool
# skip apparent comments and blank lines, what looks like
# LambdaProlog comment may be RAPID header
! 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(lnum) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)'
enddef
# Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod
***************
*** 504,511 ****
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 =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
setf prolog
else
setf perl
--- 504,511 ----
else
# recognize Prolog by specific text in the first non-empty line
# require a blank after the '%' because Perl uses "%list" and "%translate"
! var line = getline(nextnonblank(1))
! if line =~ '\<prolog\>' || line =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || line =~ ':-'
setf prolog
else
setf perl
***************
*** 678,703 ****
enddef
# Called from filetype.vim and scripts.vim.
! export def SetFileTypeSH(name: string)
! if did_filetype()
# Filetype was already detected
! return
endif
! if expand("<amatch>") =~ g:ft_ignore_pat
! return
endif
if name =~ '\<csh\>'
# Some .sh scripts contain #!/bin/csh.
! SetFileTypeShell("csh")
! return
elseif name =~ '\<tcsh\>'
# Some .sh scripts contain #!/bin/tcsh.
! SetFileTypeShell("tcsh")
! return
elseif name =~ '\<zsh\>'
# Some .sh scripts contain #!/bin/zsh.
! SetFileTypeShell("zsh")
! return
elseif name =~ '\<ksh\>'
b:is_kornshell = 1
if exists("b:is_bash")
--- 678,701 ----
enddef
# Called from filetype.vim and scripts.vim.
! # 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 ''
endif
! if setft && expand("<amatch>") =~ g:ft_ignore_pat
! return ''
endif
if name =~ '\<csh\>'
# Some .sh scripts contain #!/bin/csh.
! return SetFileTypeShell("csh", setft)
elseif name =~ '\<tcsh\>'
# Some .sh scripts contain #!/bin/tcsh.
! return SetFileTypeShell("tcsh", setft)
elseif name =~ '\<zsh\>'
# Some .sh scripts contain #!/bin/zsh.
! return SetFileTypeShell("zsh", setft)
elseif name =~ '\<ksh\>'
b:is_kornshell = 1
if exists("b:is_bash")
***************
*** 724,757 ****
unlet b:is_bash
endif
endif
! SetFileTypeShell("sh")
enddef
# For shell-like file types, check for an "exec" command hidden in a comment,
# as used for Tcl.
# Also called from scripts.vim, thus can't be local to this script.
! export def SetFileTypeShell(name: string)
! if did_filetype()
# Filetype was already detected
! return
endif
! if expand("<amatch>") =~ g:ft_ignore_pat
! return
endif
! var l = 2
! while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)'
# Skip empty and comment lines.
! l += 1
endwhile
! if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$'
# Found an "exec" line after a comment with continuation
! var n = substitute(getline(l), '\s*exec\s\+\([^ ]*/\)\=', '', '')
if n =~ '\<tclsh\|\<wish'
! setf tcl
! return
endif
endif
! exe "setf " .. name
enddef
export def CSH()
--- 722,764 ----
unlet b:is_bash
endif
endif
!
! 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, setft = true): string
! if setft && did_filetype()
# Filetype was already detected
! return ''
endif
! if setft && expand("<amatch>") =~ g:ft_ignore_pat
! return ''
endif
!
! var lnum = 2
! while lnum < 20 && lnum < line("$") && getline(lnum) =~ '^\s*\(#\|$\)'
# Skip empty and comment lines.
! lnum += 1
endwhile
! 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(lnum), '\s*exec\s\+\([^ ]*/\)\=', '', '')
if n =~ '\<tclsh\|\<wish'
! if setft
! setf tcl
! endif
! return 'tcl'
endif
endif
!
! if setft
! exe "setf " .. name
! endif
! return name
enddef
export def CSH()
*** ../vim-9.0.1622/runtime/autoload/dist/script.vim 2023-06-08 21:26:14.589704404 +0100
--- runtime/autoload/dist/script.vim 2023-06-09 20:50:06.360831720 +0100
***************
*** 4,10 ****
# Invoked from "scripts.vim" in 'runtimepath'
#
# Maintainer: Bram Moolenaar <
Br...@vim.org>
! # Last Change: 2023 Jun 08
export def DetectFiletype()
var line1 = getline(1)
--- 4,10 ----
# Invoked from "scripts.vim" in 'runtimepath'
#
# Maintainer: Bram Moolenaar <
Br...@vim.org>
! # Last Change: 2023 Jun 09
export def DetectFiletype()
var line1 = getline(1)
***************
*** 53,207 ****
name = 'wish'
endif
# Bourne-like shell scripts: bash bash2 dash ksh ksh93 sh
if name =~ '^\(bash\d*\|dash\|ksh\d*\|sh\)\>'
! call dist#ft#SetFileTypeSH(line1)
# csh scripts
elseif name =~ '^csh\>'
! if exists("g:filetype_csh")
! call dist#ft#SetFileTypeShell(g:filetype_csh)
! else
! call dist#ft#SetFileTypeShell("csh")
! endif
# tcsh scripts
elseif name =~ '^tcsh\>'
! call dist#ft#SetFileTypeShell("tcsh")
# Z shell scripts
elseif name =~ '^zsh\>'
! setl ft=zsh
# TCL scripts
elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
! setl ft=tcl
# Expect scripts
elseif name =~ '^expect\>'
! setl ft=expect
# Gnuplot scripts
elseif name =~ '^gnuplot\>'
! setl ft=gnuplot
# Makefiles
elseif name =~ 'make\>'
! setl ft=make
# Pike
elseif name =~ '^pike\%(\>\|[0-9]\)'
! setl ft=pike
# Lua
elseif name =~ 'lua'
! setl ft=lua
# Perl
elseif name =~ 'perl'
! setl ft=perl
# PHP
elseif name =~ 'php'
! setl ft=php
# Python
elseif name =~ 'python'
! setl ft=python
# Groovy
elseif name =~ '^groovy\>'
! setl ft=groovy
# Raku
elseif name =~ 'raku'
! setl ft=raku
# Ruby
elseif name =~ 'ruby'
! setl ft=ruby
# JavaScript
elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>'
! setl ft=javascript
# BC calculator
elseif name =~ '^bc\>'
! setl ft=bc
# sed
elseif name =~ 'sed\>'
! setl ft=sed
# OCaml-scripts
elseif name =~ 'ocaml'
! setl ft=ocaml
# Awk scripts; also finds "gawk"
elseif name =~ 'awk\>'
! setl ft=awk
# Website MetaLanguage
elseif name =~ 'wml'
! setl ft=wml
# Scheme scripts
elseif name =~ 'scheme'
! setl ft=scheme
# CFEngine scripts
elseif name =~ 'cfengine'
! setl ft=cfengine
# Erlang scripts
elseif name =~ 'escript'
! setl ft=erlang
# Haskell
elseif name =~ 'haskell'
! setl ft=haskell
# Scala
elseif name =~ 'scala\>'
! setl ft=scala
# Clojure
elseif name =~ 'clojure'
! setl ft=clojure
# Free Pascal
elseif name =~ 'instantfpc\>'
! setl ft=pascal
# Fennel
elseif name =~ 'fennel\>'
! setl ft=fennel
# MikroTik RouterOS script
elseif name =~ 'rsc\>'
! setl ft=routeros
# Fish shell
elseif name =~ 'fish\>'
! setl ft=fish
# Gforth
elseif name =~ 'gforth\>'
! setl ft=forth
# Icon
elseif name =~ 'icon\>'
! setl ft=icon
# Guile
elseif name =~ 'guile'
! setl ft=scheme
# Nix
elseif name =~ 'nix-shell'
! setl ft=nix
endif
enddef
--- 53,216 ----
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\)\>'
! return dist#ft#SetFileTypeSH(line1, false)
# csh scripts
elseif name =~ '^csh\>'
! return dist#ft#SetFileTypeShell(exists("g:filetype_csh") ? g:filetype_csh : 'csh', false)
# tcsh scripts
elseif name =~ '^tcsh\>'
! return dist#ft#SetFileTypeShell("tcsh", false)
# Z shell scripts
elseif name =~ '^zsh\>'
! return 'zsh'
# TCL scripts
elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
! return 'tcl'
# Expect scripts
elseif name =~ '^expect\>'
! return 'expect'
# Gnuplot scripts
elseif name =~ '^gnuplot\>'
! return 'gnuplot'
# Makefiles
elseif name =~ 'make\>'
! return 'make'
# Pike
elseif name =~ '^pike\%(\>\|[0-9]\)'
! return 'pike'
# Lua
elseif name =~ 'lua'
! return 'lua'
# Perl
elseif name =~ 'perl'
! return 'perl'
# PHP
elseif name =~ 'php'
! return 'php'
# Python
elseif name =~ 'python'
! return 'python'
# Groovy
elseif name =~ '^groovy\>'
! return 'groovy'
# Raku
elseif name =~ 'raku'
! return 'raku'
# Ruby
elseif name =~ 'ruby'
! return 'ruby'
# JavaScript
elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>'
! return 'javascript'
# BC calculator
elseif name =~ '^bc\>'
! return 'bc'
# sed
elseif name =~ 'sed\>'
! return 'sed'
# OCaml-scripts
elseif name =~ 'ocaml'
! return 'ocaml'
# Awk scripts; also finds "gawk"
elseif name =~ 'awk\>'
! return 'awk'
# Website MetaLanguage
elseif name =~ 'wml'
! return 'wml'
# Scheme scripts
elseif name =~ 'scheme'
! return 'scheme'
# CFEngine scripts
elseif name =~ 'cfengine'
! return 'cfengine'
# Erlang scripts
elseif name =~ 'escript'
! return 'erlang'
# Haskell
elseif name =~ 'haskell'
! return 'haskell'
# Scala
elseif name =~ 'scala\>'
! return 'scala'
# Clojure
elseif name =~ 'clojure'
! return 'clojure'
# Free Pascal
elseif name =~ 'instantfpc\>'
! return 'pascal'
# Fennel
elseif name =~ 'fennel\>'
! return 'fennel'
# MikroTik RouterOS script
elseif name =~ 'rsc\>'
! return 'routeros'
# Fish shell
elseif name =~ 'fish\>'
! return 'fish'
# Gforth
elseif name =~ 'gforth\>'
! return 'forth'
# Icon
elseif name =~ 'icon\>'
! return 'icon'
# Guile
elseif name =~ 'guile'
! return 'scheme'
# Nix
elseif name =~ 'nix-shell'
! return 'nix'
endif
+
+ return ''
enddef
*** ../vim-9.0.1622/src/version.c 2023-06-09 19:19:59.627215494 +0100
--- src/version.c 2023-06-09 20:29:25.933527811 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1623,
/**/
--
hundred-and-one symptoms of being an internet addict:
142. You dream about creating the world's greatest web site.
/// 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 ///