aboutsummaryrefslogblamecommitdiff
path: root/autoload/alternate_filetypes.vim
blob: 713015f3ed456565dba27345a029833c91a9fa25 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                
                                      
 





                                                                          
 






                                                                             
       
 


                                                                     



                                                          
 
           
" Switch to next alternate filetype if specified
function! alternate_filetypes#() abort

  " We only have anything to do if there's a list of filetypes defined for
  " this buffer; otherwise, just return
  "
  if !exists('b:alternate_filetypes')
    return
  endif

  " Get the index of the current filetype in the list of filetypes; return if
  " it's not in there at all
  "
  let filetypes = b:alternate_filetypes
  let index = index(filetypes, &filetype)
  if index == -1
    return
  endif

  " Switch to the next filetype, or the first filetype if the current
  " filetype is the last in the list
  "
  let filetype = filetypes[ (index + 1) % len(filetypes) ]
  if &filetype != filetype
    let &filetype = filetype
  endif

endfunction