neomutt / neomutt.vim

🔧 vim syntax for neomuttrc
GNU General Public License v2.0
39 stars 7 forks source link

Default filetype detection may need to be disabled #4

Closed doronbehar closed 5 years ago

doronbehar commented 5 years ago

Hey,

Sometimes I write mails in HTML and when I edit an HTML attachment in mutt, I want the right filetype to be detected, according to the contents of the file, not it's path.

If I had neomutt.vim installed manually i.e this plugin's file ftdetect/mail.vim was under my own runtimepath, I would have just changed this file to something like this:

au BufNewFile,BufRead neomutt-*-\w\+,neomutt[[:alnum:]_-]\\\{6\} if getline(1) =~# '^<DOCTYPE html' | set filetype=html | else | set filetype=mail | endif

But that's not elegant at all because I prefer to keep plugin as they are.

I've also tried to put the following straight in my init.vim and it didn't help either:

au FileType neomutt-*-\w\+,neomutt[[:alnum:]_-]\\\{6\} if getline(1) =~# '^<DOCTYPE html' | set filetype=html | endif

Please tell me if I'm missing a specific essential Vim feature. Otherwise, I see these change nescessary. I've updated doc/neomutt.txt as well.

Thanks in advance.

flatcap commented 5 years ago

Thanks for the PR, @doronbehar That'll certainly do the job, but I think there's another way...

According to the Vim docs, there are two ways to set the filetype:

" Forcefully
setlocal filetype=mail

" Reluctantly
setfiletype mail

setfiletype will only set the file type if it hasn't already been set. If Vim has set the file type, based on its contents, then changing neomutt.vim to use setfiletype mail would do nothing. In theory.

If you have a moment to investigate this, that'd be really appreciated.

doronbehar commented 5 years ago

Thanks for investigating that. I guess Vim was smarter then me. I've tested the following in my own filetype.vim:

au BufNewFile,BufRead neomutt-*-\w\+,neomutt[[:alnum:]_-]\\\{6\} if getline(1) =~# '^<!DOCTYPE html' | setfiletype html | endif

While ftdetect/mail.vim was modified to use setfiletype and it worked. This is definitely more elegant.

I'm updating the PR to use setfiletype instead of set filetype in all files in ftdetect/.