]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1643: filetype detection fails if file name ends in many '~' v9.0.1643
authorBram Moolenaar <Bram@vim.org>
Thu, 22 Jun 2023 11:18:57 +0000 (12:18 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Jun 2023 11:18:57 +0000 (12:18 +0100)
Problem:    Filetype detection fails if file name ends in many '~'.
Solution:   Strip multiple '~' at the same time. (closes #12553)

runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index c93ce5eaeb75e271506a4d09e611682f6368a89d..9daf5a3cbbb73f3be77c0d3aea3d213e6f05e53f 100644 (file)
@@ -21,7 +21,7 @@ au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.dpkg-dist,?\+.dpkg-ol
        \ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
 au BufNewFile,BufRead *~
        \ let s:name = expand("<afile>") |
-       \ let s:short = substitute(s:name, '\~$', '', '') |
+       \ let s:short = substitute(s:name, '\~\+$', '', '') |
        \ if s:name != s:short && s:short != "" |
        \   exe "doau filetypedetect BufRead " . fnameescape(s:short) |
        \ endif |
index 41b91061364cb8cb258fe5192ade1d0f731a48e4..9c1b11d2a01ef140ee5b761927da8c44e5d9131a 100644 (file)
@@ -1,5 +1,16 @@
 " Test :setfiletype
 
+func Test_backup_strip()
+  filetype on
+  let fname = 'Xdetect.js~~~~~~~~~~~'
+  call writefile(['one', 'two', 'three'], fname, 'D')
+  exe 'edit ' .. fname
+  call assert_equal('javascript', &filetype)
+
+  bwipe!
+  filetype off
+endfunc
+
 func Test_detection()
   filetype on
   augroup filetypedetect
index 1d294270181411b33c65530a7c3dfb9238de5b20..c5aa47af6076d79e06572b7d226e2e61b1e5f645 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1643,
 /**/
     1642,
 /**/