Skip to content

Commit ff13a46

Browse files
committed
Use 'set filetype' to set filetype once again
The s:setf() helper function was originally introduced to avoid setting the filetype multiple times (375e9e1). I believe this covered the case where a file had an .ex or .exs extension and also include "elixir" in the shebang line (such that s:DetectElixir() would match and call 'set filetype' redundantly). c56bd82 removed the existing &filetype check in s:setf(), relying on the &filetype global and ftdetect framework to avoid redundant updates. I believe we can simplify this even further by using just 'set filetype' in the file extension-based autocommands and including a guard against (re)setting filetype in s:DetectElixir(). Also, use explicit case-insensitive comparison operators. This isn't a good place to make assumptions about 'ignorecase'.
1 parent c1c3dca commit ff13a46

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

ftdetect/elixir.vim

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
2-
au BufRead,BufNewFile *.eex call s:setf('eelixir')
1+
au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
2+
au BufRead,BufNewFile *.eex set filetype=elixir
33
au BufRead,BufNewFile * call s:DetectElixir()
44

5-
function! s:setf(filetype) abort
6-
let &filetype = a:filetype
7-
endfunction
8-
95
function! s:DetectElixir()
10-
if getline(1) =~ '^#!.*\<elixir\>'
11-
call s:setf('elixir')
6+
if &filetype !=# 'elixir' && getline(1) =~# '^#!.*\<elixir\>'
7+
set filetype=elixir
128
endif
139
endfunction

0 commit comments

Comments
 (0)