Skip to content

Commit

Permalink
patch 9.0.1643: filetype detection fails if file name ends in many '~'
Browse files Browse the repository at this point in the history
Problem:    Filetype detection fails if file name ends in many '~'.
Solution:   Strip multiple '~' at the same time. (closes vim#12553)
  • Loading branch information
brammool committed Jun 22, 2023
1 parent 545c8a5 commit c12e4ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
11 changes: 11 additions & 0 deletions src/testdir/test_filetype.vim
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1643,
/**/
1642,
/**/
Expand Down

0 comments on commit c12e4ee

Please sign in to comment.