filetype detection for dbus configuration files

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

filetype detection for dbus configuration files

sebastian.novak
Hi,

the current filetype.vim does not detect the filetype for the dbus
configuration files (which on my system are stored in /etc/dbus-1/*
and subfolders). These are in doctype sgml and are not detected
because they end on ".conf". A simple patch is attached.

I think it would be best if vim could find out about filetypes without
having to resort to file endings as much as now. This would settle
cases as the one above once and for all.
Just as a naive idea: Couldn't the "file" program (or just its rules)
be used by vim? At least in this case it immediately returns the
correct file type and the magic rules there are already quite
sophisticated.

Best,
Sebastian Novak




--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

filetype.vim.patch (485 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: filetype detection for dbus configuration files

Tony Mechelynck
On 16/05/10 02:46, sebastian.novak wrote:

> Hi,
>
> the current filetype.vim does not detect the filetype for the dbus
> configuration files (which on my system are stored in /etc/dbus-1/*
> and subfolders). These are in doctype sgml and are not detected
> because they end on ".conf". A simple patch is attached.
>
> I think it would be best if vim could find out about filetypes without
> having to resort to file endings as much as now. This would settle
> cases as the one above once and for all.
> Just as a naive idea: Couldn't the "file" program (or just its rules)
> be used by vim? At least in this case it immediately returns the
> correct file type and the magic rules there are already quite
> sophisticated.
>
> Best,
> Sebastian Novak
>
>
>
>

filetype.vim recognizes filetypes by means of whatever can be seen
without reading the file (e.g. anything ending in .css is a CSS style
sheet, anything ending in .vim or in vimrc is a Vim script. This is the
fastest way when it works, I wouldn't call it "resorting" to file ending.

When it doesn't work, the contents of the files have to be examined,
which is much slower and often less trustworthy. That is the job of
scripts.vim, not filetype.vim

_Resorting_ to an external tool such as file would mean (a) having to
load that external tool, which in turn would probably mean loading a
shell first; and (b) on OSes where the tool doesn't exist, you're lost.
For something as basic as recognizing filetypes, Vim uses filenames when
it can, file contents when it has to, and never resorts to calling
external applications. IMHO that's the way to go.

Bram will probably examine your proposed patch, and maybe incorporate it
into some future version of scripts.vim; in the meantime:

1) You should never modify anything in $VIMRUNTIME or any of its
subdirectories, because any upgrade may, and sooner or later one will,
silently remove any such changes.

2) But you can create your own ~/.vim/scripts.vim or
$VIM/vimfiles/scripts.vim to examine the file contents. If the files'
names and paths are enough though, you should use them in priority, and
put the corresponding tests in ~/.vim/filetype.vim or
$VIM/vimfiles/filetype.vim -- or you can create a brand new ftdetect
subdirectory, see :help new-filetype. Any of the files and directories
mentioned in this paragraph need only exist when you have something to
put in them: by defaut they are not created when you install Vim, but
you can create them yourself once you need them.


Best regards,
Tony.
--
I've enjoyed just about as much of this as I can stand.

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php