0
0
mirror of https://github.com/vim/vim.git synced 2025-09-02 21:13:50 -04:00

patch 9.0.1519: global 'filetype' is set when detected from file content

Problem:    Global 'filetype' is set when it is detected from the file content.
Solution:   Set the local 'filetype' option value.
This commit is contained in:
Bram Moolenaar 2023-05-06 21:21:52 +01:00
parent 34a6a3617b
commit 0b70aeb49d
2 changed files with 78 additions and 76 deletions

View File

@ -71,131 +71,131 @@ def DetectFromHashBang(firstline: string)
# Z shell scripts # Z shell scripts
elseif name =~ '^zsh\>' elseif name =~ '^zsh\>'
set ft=zsh setl ft=zsh
# TCL scripts # TCL scripts
elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>' elseif name =~ '^\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
set ft=tcl setl ft=tcl
# Expect scripts # Expect scripts
elseif name =~ '^expect\>' elseif name =~ '^expect\>'
set ft=expect setl ft=expect
# Gnuplot scripts # Gnuplot scripts
elseif name =~ '^gnuplot\>' elseif name =~ '^gnuplot\>'
set ft=gnuplot setl ft=gnuplot
# Makefiles # Makefiles
elseif name =~ 'make\>' elseif name =~ 'make\>'
set ft=make setl ft=make
# Pike # Pike
elseif name =~ '^pike\%(\>\|[0-9]\)' elseif name =~ '^pike\%(\>\|[0-9]\)'
set ft=pike setl ft=pike
# Lua # Lua
elseif name =~ 'lua' elseif name =~ 'lua'
set ft=lua setl ft=lua
# Perl # Perl
elseif name =~ 'perl' elseif name =~ 'perl'
set ft=perl setl ft=perl
# PHP # PHP
elseif name =~ 'php' elseif name =~ 'php'
set ft=php setl ft=php
# Python # Python
elseif name =~ 'python' elseif name =~ 'python'
set ft=python setl ft=python
# Groovy # Groovy
elseif name =~ '^groovy\>' elseif name =~ '^groovy\>'
set ft=groovy setl ft=groovy
# Raku # Raku
elseif name =~ 'raku' elseif name =~ 'raku'
set ft=raku setl ft=raku
# Ruby # Ruby
elseif name =~ 'ruby' elseif name =~ 'ruby'
set ft=ruby setl ft=ruby
# JavaScript # JavaScript
elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>' elseif name =~ 'node\(js\)\=\>\|js\>' || name =~ 'rhino\>'
set ft=javascript setl ft=javascript
# BC calculator # BC calculator
elseif name =~ '^bc\>' elseif name =~ '^bc\>'
set ft=bc setl ft=bc
# sed # sed
elseif name =~ 'sed\>' elseif name =~ 'sed\>'
set ft=sed setl ft=sed
# OCaml-scripts # OCaml-scripts
elseif name =~ 'ocaml' elseif name =~ 'ocaml'
set ft=ocaml setl ft=ocaml
# Awk scripts; also finds "gawk" # Awk scripts; also finds "gawk"
elseif name =~ 'awk\>' elseif name =~ 'awk\>'
set ft=awk setl ft=awk
# Website MetaLanguage # Website MetaLanguage
elseif name =~ 'wml' elseif name =~ 'wml'
set ft=wml setl ft=wml
# Scheme scripts # Scheme scripts
elseif name =~ 'scheme' elseif name =~ 'scheme'
set ft=scheme setl ft=scheme
# CFEngine scripts # CFEngine scripts
elseif name =~ 'cfengine' elseif name =~ 'cfengine'
set ft=cfengine setl ft=cfengine
# Erlang scripts # Erlang scripts
elseif name =~ 'escript' elseif name =~ 'escript'
set ft=erlang setl ft=erlang
# Haskell # Haskell
elseif name =~ 'haskell' elseif name =~ 'haskell'
set ft=haskell setl ft=haskell
# Scala # Scala
elseif name =~ 'scala\>' elseif name =~ 'scala\>'
set ft=scala setl ft=scala
# Clojure # Clojure
elseif name =~ 'clojure' elseif name =~ 'clojure'
set ft=clojure setl ft=clojure
# Free Pascal # Free Pascal
elseif name =~ 'instantfpc\>' elseif name =~ 'instantfpc\>'
set ft=pascal setl ft=pascal
# Fennel # Fennel
elseif name =~ 'fennel\>' elseif name =~ 'fennel\>'
set ft=fennel setl ft=fennel
# MikroTik RouterOS script # MikroTik RouterOS script
elseif name =~ 'rsc\>' elseif name =~ 'rsc\>'
set ft=routeros setl ft=routeros
# Fish shell # Fish shell
elseif name =~ 'fish\>' elseif name =~ 'fish\>'
set ft=fish setl ft=fish
# Gforth # Gforth
elseif name =~ 'gforth\>' elseif name =~ 'gforth\>'
set ft=forth setl ft=forth
# Icon # Icon
elseif name =~ 'icon\>' elseif name =~ 'icon\>'
set ft=icon setl ft=icon
# Guile # Guile
elseif name =~ 'guile' elseif name =~ 'guile'
set ft=scheme setl ft=scheme
endif endif
enddef enddef
@ -218,28 +218,28 @@ def DetectFromText(line1: string)
|| "\n" .. line1 .. "\n" .. line2 .. "\n" .. line3 .. || "\n" .. line1 .. "\n" .. line2 .. "\n" .. line3 ..
"\n" .. line4 .. "\n" .. line5 "\n" .. line4 .. "\n" .. line5
=~ '\n\s*emulate\s\+\%(-[LR]\s\+\)\=[ckz]\=sh\>' =~ '\n\s*emulate\s\+\%(-[LR]\s\+\)\=[ckz]\=sh\>'
set ft=zsh setl ft=zsh
# ELM Mail files # ELM Mail files
elseif line1 =~ '^From \([a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\=\|-\) .* \(19\|20\)\d\d$' elseif line1 =~ '^From \([a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\=\|-\) .* \(19\|20\)\d\d$'
set ft=mail setl ft=mail
# Mason # Mason
elseif line1 =~ '^<[%&].*>' elseif line1 =~ '^<[%&].*>'
set ft=mason setl ft=mason
# Vim scripts (must have '" vim' as the first line to trigger this) # Vim scripts (must have '" vim' as the first line to trigger this)
elseif line1 =~ '^" *[vV]im$' elseif line1 =~ '^" *[vV]im$'
set ft=vim setl ft=vim
# libcxx and libstdc++ standard library headers like "iostream" do not have # libcxx and libstdc++ standard library headers like "iostream" do not have
# an extension, recognize the Emacs file mode. # an extension, recognize the Emacs file mode.
elseif line1 =~? '-\*-.*C++.*-\*-' elseif line1 =~? '-\*-.*C++.*-\*-'
set ft=cpp setl ft=cpp
# MOO # MOO
elseif line1 =~ '^\*\* LambdaMOO Database, Format Version \%([1-3]\>\)\@!\d\+ \*\*$' elseif line1 =~ '^\*\* LambdaMOO Database, Format Version \%([1-3]\>\)\@!\d\+ \*\*$'
set ft=moo setl ft=moo
# Diff file: # Diff file:
# - "diff" in first line (context diff) # - "diff" in first line (context diff)
@ -258,11 +258,11 @@ def DetectFromText(line1: string)
|| (line1 =~ '^\*\*\* ' && line2 =~ '^--- ') || (line1 =~ '^\*\*\* ' && line2 =~ '^--- ')
|| (line1 =~ '^=== ' && ((line2 =~ '^=\{66\}' && line3 =~ '^--- ' && line4 =~ '^+++') || (line2 =~ '^--- ' && line3 =~ '^+++ '))) || (line1 =~ '^=== ' && ((line2 =~ '^=\{66\}' && line3 =~ '^--- ' && line4 =~ '^+++') || (line2 =~ '^--- ' && line3 =~ '^+++ ')))
|| (line1 =~ '^=== \(removed\|added\|renamed\|modified\)') || (line1 =~ '^=== \(removed\|added\|renamed\|modified\)')
set ft=diff setl ft=diff
# PostScript Files (must have %!PS as the first line, like a2ps output) # PostScript Files (must have %!PS as the first line, like a2ps output)
elseif line1 =~ '^%![ \t]*PS' elseif line1 =~ '^%![ \t]*PS'
set ft=postscr setl ft=postscr
# M4 scripts: Guess there is a line that starts with "dnl". # M4 scripts: Guess there is a line that starts with "dnl".
elseif line1 =~ '^\s*dnl\>' elseif line1 =~ '^\s*dnl\>'
@ -270,64 +270,64 @@ def DetectFromText(line1: string)
|| line3 =~ '^\s*dnl\>' || line3 =~ '^\s*dnl\>'
|| line4 =~ '^\s*dnl\>' || line4 =~ '^\s*dnl\>'
|| line5 =~ '^\s*dnl\>' || line5 =~ '^\s*dnl\>'
set ft=m4 setl ft=m4
# AmigaDos scripts # AmigaDos scripts
elseif $TERM == "amiga" && (line1 =~ "^;" || line1 =~? '^\.bra') elseif $TERM == "amiga" && (line1 =~ "^;" || line1 =~? '^\.bra')
set ft=amiga setl ft=amiga
# SiCAD scripts (must have procn or procd as the first line to trigger this) # SiCAD scripts (must have procn or procd as the first line to trigger this)
elseif line1 =~? '^ *proc[nd] *$' elseif line1 =~? '^ *proc[nd] *$'
set ft=sicad setl ft=sicad
# Purify log files start with "**** Purify" # Purify log files start with "**** Purify"
elseif line1 =~ '^\*\*\*\* Purify' elseif line1 =~ '^\*\*\*\* Purify'
set ft=purifylog setl ft=purifylog
# XML # XML
elseif line1 =~ '<?\s*xml.*?>' elseif line1 =~ '<?\s*xml.*?>'
set ft=xml setl ft=xml
# XHTML (e.g.: PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN") # XHTML (e.g.: PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN")
elseif line1 =~ '\<DTD\s\+XHTML\s' elseif line1 =~ '\<DTD\s\+XHTML\s'
set ft=xhtml setl ft=xhtml
# HTML (e.g.: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN") # HTML (e.g.: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN")
# Avoid "doctype html", used by slim. # Avoid "doctype html", used by slim.
elseif line1 =~? '<!DOCTYPE\s\+html\>' elseif line1 =~? '<!DOCTYPE\s\+html\>'
set ft=html setl ft=html
# PDF # PDF
elseif line1 =~ '^%PDF-' elseif line1 =~ '^%PDF-'
set ft=pdf setl ft=pdf
# XXD output # XXD output
elseif line1 =~ '^\x\{7}: \x\{2} \=\x\{2} \=\x\{2} \=\x\{2} ' elseif line1 =~ '^\x\{7}: \x\{2} \=\x\{2} \=\x\{2} \=\x\{2} '
set ft=xxd setl ft=xxd
# RCS/CVS log output # RCS/CVS log output
elseif line1 =~ '^RCS file:' || line2 =~ '^RCS file:' elseif line1 =~ '^RCS file:' || line2 =~ '^RCS file:'
set ft=rcslog setl ft=rcslog
# CVS commit # CVS commit
elseif line2 =~ '^CVS:' || getline("$") =~ '^CVS: ' elseif line2 =~ '^CVS:' || getline("$") =~ '^CVS: '
set ft=cvs setl ft=cvs
# Prescribe # Prescribe
elseif line1 =~ '^!R!' elseif line1 =~ '^!R!'
set ft=prescribe setl ft=prescribe
# Send-pr # Send-pr
elseif line1 =~ '^SEND-PR:' elseif line1 =~ '^SEND-PR:'
set ft=sendpr setl ft=sendpr
# SNNS files # SNNS files
elseif line1 =~ '^SNNS network definition file' elseif line1 =~ '^SNNS network definition file'
set ft=snnsnet setl ft=snnsnet
elseif line1 =~ '^SNNS pattern definition file' elseif line1 =~ '^SNNS pattern definition file'
set ft=snnspat setl ft=snnspat
elseif line1 =~ '^SNNS result file' elseif line1 =~ '^SNNS result file'
set ft=snnsres setl ft=snnsres
# Virata # Virata
elseif line1 =~ '^%.\{-}[Vv]irata' elseif line1 =~ '^%.\{-}[Vv]irata'
@ -335,81 +335,81 @@ def DetectFromText(line1: string)
|| line3 =~ '^%.\{-}[Vv]irata' || line3 =~ '^%.\{-}[Vv]irata'
|| line4 =~ '^%.\{-}[Vv]irata' || line4 =~ '^%.\{-}[Vv]irata'
|| line5 =~ '^%.\{-}[Vv]irata' || line5 =~ '^%.\{-}[Vv]irata'
set ft=virata setl ft=virata
# Strace # Strace
# inaccurate fast match first, then use accurate slow match # inaccurate fast match first, then use accurate slow match
elseif (line1 =~ 'execve(' && line1 =~ '^[0-9:.]* *execve(') elseif (line1 =~ 'execve(' && line1 =~ '^[0-9:.]* *execve(')
|| line1 =~ '^__libc_start_main' || line1 =~ '^__libc_start_main'
set ft=strace setl ft=strace
# VSE JCL # VSE JCL
elseif line1 =~ '^\* $$ JOB\>' || line1 =~ '^// *JOB\>' elseif line1 =~ '^\* $$ JOB\>' || line1 =~ '^// *JOB\>'
set ft=vsejcl setl ft=vsejcl
# TAK and SINDA # TAK and SINDA
elseif line4 =~ 'K & K Associates' || line2 =~ 'TAK 2000' elseif line4 =~ 'K & K Associates' || line2 =~ 'TAK 2000'
set ft=takout setl ft=takout
elseif line3 =~ 'S Y S T E M S I M P R O V E D ' elseif line3 =~ 'S Y S T E M S I M P R O V E D '
set ft=sindaout setl ft=sindaout
elseif getline(6) =~ 'Run Date: ' elseif getline(6) =~ 'Run Date: '
set ft=takcmp setl ft=takcmp
elseif getline(9) =~ 'Node File 1' elseif getline(9) =~ 'Node File 1'
set ft=sindacmp setl ft=sindacmp
# DNS zone files # DNS zone files
elseif line1 .. line2 .. line3 .. line4 =~ '^; <<>> DiG [0-9.]\+.* <<>>\|$ORIGIN\|$TTL\|IN\s\+SOA' elseif line1 .. line2 .. line3 .. line4 =~ '^; <<>> DiG [0-9.]\+.* <<>>\|$ORIGIN\|$TTL\|IN\s\+SOA'
set ft=bindzone setl ft=bindzone
# BAAN # BAAN
elseif line1 =~ '|\*\{1,80}' && line2 =~ 'VRC ' elseif line1 =~ '|\*\{1,80}' && line2 =~ 'VRC '
|| line2 =~ '|\*\{1,80}' && line3 =~ 'VRC ' || line2 =~ '|\*\{1,80}' && line3 =~ 'VRC '
set ft=baan setl ft=baan
# Valgrind # Valgrind
elseif line1 =~ '^==\d\+== valgrind' || line3 =~ '^==\d\+== Using valgrind' elseif line1 =~ '^==\d\+== valgrind' || line3 =~ '^==\d\+== Using valgrind'
set ft=valgrind setl ft=valgrind
# Go docs # Go docs
elseif line1 =~ '^PACKAGE DOCUMENTATION$' elseif line1 =~ '^PACKAGE DOCUMENTATION$'
set ft=godoc setl ft=godoc
# Renderman Interface Bytestream # Renderman Interface Bytestream
elseif line1 =~ '^##RenderMan' elseif line1 =~ '^##RenderMan'
set ft=rib setl ft=rib
# Scheme scripts # Scheme scripts
elseif line1 =~ 'exec\s\+\S*scheme' || line2 =~ 'exec\s\+\S*scheme' elseif line1 =~ 'exec\s\+\S*scheme' || line2 =~ 'exec\s\+\S*scheme'
set ft=scheme setl ft=scheme
# Git output # Git output
elseif line1 =~ '^\(commit\|tree\|object\) \x\{40,\}\>\|^tag \S\+$' elseif line1 =~ '^\(commit\|tree\|object\) \x\{40,\}\>\|^tag \S\+$'
set ft=git setl ft=git
# Gprof (gnu profiler) # Gprof (gnu profiler)
elseif line1 == 'Flat profile:' elseif line1 == 'Flat profile:'
&& line2 == '' && line2 == ''
&& line3 =~ '^Each sample counts as .* seconds.$' && line3 =~ '^Each sample counts as .* seconds.$'
set ft=gprof setl ft=gprof
# Erlang terms # Erlang terms
# (See also: http://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html#Choosing-Modes) # (See also: http://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html#Choosing-Modes)
elseif line1 =~? '-\*-.*erlang.*-\*-' elseif line1 =~? '-\*-.*erlang.*-\*-'
set ft=erlang setl ft=erlang
# YAML # YAML
elseif line1 =~ '^%YAML' elseif line1 =~ '^%YAML'
set ft=yaml setl ft=yaml
# MikroTik RouterOS script # MikroTik RouterOS script
elseif line1 =~ '^#.*by RouterOS.*$' elseif line1 =~ '^#.*by RouterOS.*$'
set ft=routeros setl ft=routeros
# Sed scripts # Sed scripts
# #ncomment is allowed but most likely a false positive so require a space # #ncomment is allowed but most likely a false positive so require a space
# before any trailing comment text # before any trailing comment text
elseif line1 =~ '^#n\%($\|\s\)' elseif line1 =~ '^#n\%($\|\s\)'
set ft=sed setl ft=sed
else else
var lnum = 1 var lnum = 1
@ -418,7 +418,7 @@ def DetectFromText(line1: string)
endwhile endwhile
if getline(lnum) =~ '^Index:\s\+\f\+$' if getline(lnum) =~ '^Index:\s\+\f\+$'
# CVS diff # CVS diff
set ft=diff setl ft=diff
# locale input files: Formal Definitions of Cultural Conventions # locale input files: Formal Definitions of Cultural Conventions
# filename must be like en_US, fr_FR@euro or en_US.UTF-8 # filename must be like en_US, fr_FR@euro or en_US.UTF-8

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 */
/**/
1519,
/**/ /**/
1518, 1518,
/**/ /**/