changeset 23078:d01b011f91b9 v8.2.2085

patch 8.2.2085: Qt translation file is recognized as typescript Commit: https://github.com/vim/vim/commit/c0d670ce16d0e148b7d39ac354571b3d284a0b53 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 3 21:08:37 2020 +0100 patch 8.2.2085: Qt translation file is recognized as typescript Problem: Qt translation file is recognized as typescript. Solution: Check the first line for "<?xml". (closes https://github.com/vim/vim/issues/7418)
author Bram Moolenaar <Bram@vim.org>
date Thu, 03 Dec 2020 21:15:06 +0100
parents 02af8cff1cf9
children 56e11a681a56
files runtime/filetype.vim src/testdir/test_filetype.vim src/version.c
diffstat 3 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1763,8 +1763,13 @@ au BufNewFile,BufReadPost *.tsscl		setf 
 " TWIG files
 au BufNewFile,BufReadPost *.twig		setf twig
 
-" Typescript
-au BufNewFile,BufReadPost *.ts			setf typescript
+" Typescript or Qt translation file (which is XML)
+au BufNewFile,BufReadPost *.ts
+	\ if getline(1) =~ '<?xml' |
+	\   setf xml |
+	\ else |
+	\   setf typescript |
+	\ endif
 
 " TypeScript with React
 au BufNewFile,BufRead *.tsx			setf typescriptreact
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -487,7 +487,6 @@ let s:filename_checks = {
     \ 'tssgm': ['file.tssgm'],
     \ 'tssop': ['file.tssop'],
     \ 'twig': ['file.twig'],
-    \ 'typescript': ['file.ts'],
     \ 'typescriptreact': ['file.tsx'],
     \ 'uc': ['file.uc'],
     \ 'udevconf': ['/etc/udev/udev.conf', 'any/etc/udev/udev.conf'],
@@ -709,5 +708,22 @@ func Test_hook_file()
   filetype off
 endfunc
 
+func Test_ts_file()
+  filetype on
+
+  call writefile(['<?xml version="1.0" encoding="utf-8"?>'], 'Xfile.ts')
+  split Xfile.ts
+  call assert_equal('xml', &filetype)
+  bwipe!
+
+  call writefile(['// looks like Typescript'], 'Xfile.ts')
+  split Xfile.ts
+  call assert_equal('typescript', &filetype)
+  bwipe!
+
+  call delete('Xfile.hook')
+  filetype off
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2085,
+/**/
     2084,
 /**/
     2083,