# HG changeset patch # User Bram Moolenaar # Date 1687433405 -7200 # Node ID 2cd120c9dabae709be32cbf0862934d33576dfc6 # Parent dfe2a1a0824c47344ddd4812f6af74593f92813e patch 9.0.1643: filetype detection fails if file name ends in many '~' Commit: https://github.com/vim/vim/commit/c12e4eecbb26cedca96e0810d3501043356eebaa Author: Bram Moolenaar Date: Thu Jun 22 12:18:57 2023 +0100 patch 9.0.1643: filetype detection fails if file name ends in many '~' Problem: Filetype detection fails if file name ends in many '~'. Solution: Strip multiple '~' at the same time. (closes https://github.com/vim/vim/issues/12553) diff --git a/runtime/filetype.vim b/runtime/filetype.vim --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -21,7 +21,7 @@ au BufNewFile,BufRead ?\+.orig,?\+.bak,? \ exe "doau filetypedetect BufRead " . fnameescape(expand(":r")) au BufNewFile,BufRead *~ \ let s:name = expand("") | - \ 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 | diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -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 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1643, +/**/ 1642, /**/ 1641,