Reply to message «no echo output in command line», sent 23:38:08 08 November 2010, Monday by rameo:
> I noted that all latin1 files are displayed as utf8 in gvim, but they
> are latin1.
> I decided now to set "latin1" as global encoding and to create a
> script
> to check if a latin1 file has utf8 (latin1 non printable) characters.
>
> This is my script:
>
> function! s:NonPrintable()
> silent! exe "setlocal enc=utf8"
> if search('[^\x00-\xff]') != ""
> silent! exe matchadd('Error', '[^\x00-\xff]')
> silent! exe "setlocal enc=latin1"
> echo 'Non printable characters in text'
> else
> silent! exe "setlocal enc=latin1"
> echo 'All ok'
> endif
> endfunction
>
> The script doesn't give the echo command in the commandline.
> What did I wrong?
First, never change `encoding' option. It describes internal representation of
strings and NOT the file encoding.
Second, you do not need to use execute here:
silent! exe "setlocal fenc=latin1"
and
silent! setlocal fenc=latin1
are equivalent.
Third, you should not use silent! here: when you set some option vim does not
throw errors that can be safely ignored.
Fourth, you probably want to replace
silent! exe matchadd(...)
with
call matchadd(...)
. ``exe matchadd(...)'' will transform into `exe N' (+ side effect of adding
match) where `N' is a semi-random number, so it will bring you to the Nth line.
`call' does not have this problem. Again, you should not ignore errors from
matchadd as they are not normally thrown.
Fifth, altering `fenc' which does describe file encoding, has no effect, so you
should use `e! ++enc=latin1'
e! ++enc=latin1
(NO `silent!'!!! You should write code that does not contain errors instead of
ignoring them.)
Sixth, I cannot take the point of this script. Every latin character can be
translated to UTF-8, so why do you want to downgrade `encoding'?
Seventh, `search()' returns either 0 or line number, so `if search(...)' is
enough. The only reason why `search() != ""' works is that string `""' is
converted into number 0 and vim really compares numbers, not strings. Note that
search without the `n' flag moves the cursor what you likely don't want to.
So, you did wrong almost everything, but this script still should echo
something. Try changing `echo' to `echomsg' and check output of `messages'
after
running it.
signature.asc
Description: This is a digitally signed message part.
