To: vim_dev@googlegroups.com Subject: Patch 8.2.4238 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4238 Problem: *.tf file could be fileytpe "tf" or "terraform". Solution: Detect the type from the file contents. (closes #9642) Files: runtime/filetype.vim, runtime/autoload/dist/ft.vim, src/testdir/test_filetype.vim *** ../vim-8.2.4237/runtime/filetype.vim 2022-01-23 17:09:00.342463158 +0000 --- runtime/filetype.vim 2022-01-28 14:13:52.929907358 +0000 *************** *** 1946,1955 **** au BufNewFile,BufRead .tidyrc,tidyrc,tidy.conf setf tidy " TF mud client ! au BufNewFile,BufRead *.tf,.tfrc,tfrc setf tf " TLA+ ! au BufRead,BufNewFile *.tla setf tla " tmux configuration au BufNewFile,BufRead {.,}tmux*.conf setf tmux --- 1946,1958 ---- au BufNewFile,BufRead .tidyrc,tidyrc,tidy.conf setf tidy " TF mud client ! au BufNewFile,BufRead .tfrc,tfrc setf tf ! ! " TF mud client or terraform ! au BufNewFile,BufRead *.tf call dist#ft#FTtf() " TLA+ ! au BufNewFile,BufRead *.tla setf tla " tmux configuration au BufNewFile,BufRead {.,}tmux*.conf setf tmux *************** *** 1958,1964 **** au BufNewFile,BufRead *.toml setf toml " TPP - Text Presentation Program ! au BufNewFile,BufReadPost *.tpp setf tpp " Treetop au BufRead,BufNewFile *.treetop setf treetop --- 1961,1967 ---- au BufNewFile,BufRead *.toml setf toml " TPP - Text Presentation Program ! au BufNewFile,BufRead *.tpp setf tpp " Treetop au BufRead,BufNewFile *.treetop setf treetop *** ../vim-8.2.4237/runtime/autoload/dist/ft.vim 2022-01-21 14:55:10.169295589 +0000 --- runtime/autoload/dist/ft.vim 2022-01-28 14:13:57.549841104 +0000 *************** *** 862,867 **** --- 862,882 ---- endwhile endfunc + " Determine if a *.tf file is TF mud client or terraform + func dist#ft#FTtf() + let numberOfLines = line('$') + for i in range(1, numberOfLines) + let currentLine = trim(getline(i)) + let firstCharacter = currentLine[0] + if firstCharacter !=? ";" && firstCharacter !=? "/" && firstCharacter !=? "" + setf terraform + return + endif + endfor + setf tf + endfunc + + " Restore 'cpoptions' let &cpo = s:cpo_save unlet s:cpo_save *** ../vim-8.2.4237/src/testdir/test_filetype.vim 2022-01-24 11:40:33.944693856 +0000 --- src/testdir/test_filetype.vim 2022-01-28 14:08:42.546357875 +0000 *************** *** 771,776 **** --- 771,794 ---- filetype off endfunc + func Test_tf_file() + filetype on + + call writefile([';;; TF MUD client is super duper cool'], 'Xfile.tf') + split Xfile.tf + call assert_equal('tf', &filetype) + bwipe! + + call writefile(['provider "azurerm" {'], 'Xfile.tf') + split Xfile.tf + call assert_equal('terraform', &filetype) + bwipe! + + call delete('Xfile.tf') + filetype off + endfunc + + func Test_ts_file() filetype on *** ../vim-8.2.4237/src/version.c 2022-01-28 12:50:38.596217550 +0000 --- src/version.c 2022-01-28 14:10:30.428811178 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4238, /**/ -- It might look like I'm doing nothing, but at the cellular level I'm really quite busy. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///