Hi Tony :)
* A.J.Mechelynck <[EMAIL PROTECTED]> dixit:
> DervishD wrote:
> > * A.J.Mechelynck <[EMAIL PROTECTED]> dixit:
> >>>>Notice the dash between utf and 8.
> >>> My bad, I typed carelessly. It succeeded on my system because I did
> >>>my first test with a file *named* 'utf8'. I've noticed the problem a
> >>>moment ago, and it's already fixed.
> >>Hoho... Then maybe you should use file -bi rather than file -i in order
> >>to avoid detecting UTF-8 for:
> >>
> >>/home/raul/utf-8_to_latin.txt: text/plain; charset=ISO-8859-1
> >
> > I've done that and more:
> >
> > if system("file -bi " . expand("<amatch>")) =~# "; charset=utf-8$"
> >
> > I was too lazy to ellaborate the regex correctly. It is still
> >unellaborated, but works better.
>
> "regexp matches with matching case", "; charset=utf-8" at end of string.
> Redundant with -b but ought to work, unless a text file can have something
> after the charset, which I haven't seen yet in the experiments I've done.
Well, in fact using the output from "file -i" is not a good idea,
but finding the charset of a file is not easy anyway, so the redundance
doesn't worry me. In fact I prefer that redundance, just in case I
change "file -bi" for anything else in the future (thing that I plan to
do, by the way).
The problem is that the conversion in vim is done before charset can
be set by hand :(, otherwise, a simple ":setlocal fenc=utf8" will do. A
human is the perfect tool to discriminate between charsets :D
> One thing I just noticed: shell scripts (which are text) get
> "application/x-shellscript" and no charset, at least on my system; IMHO
> that's a bug in the "file" program.
I don't know if it is a bug or not, but IMHO it is because the
output has a different structure from one mimetype to other. It should
always output the charset or never, but not only for text. I don't know
if any standard mandates that "charset" is only meaningful for
"text/plain", but...
If tomorrow morning I have some spare time I'll try to get a better
solution, preferably using VimL only.
Thanks for your help :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!