no echo output in command line

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

no echo output in command line

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?

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

Nikolay Aleksandrovich Pavlov
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 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

rameo
Thank you,

I'm new to vim :)

As you've indicated, I removed the silent! flag, removed the exe
before setlocal..., changed exe matchadd to call matchadd.
Still no echo output. Changed it to echomsg, but still no output.

?

-----------------------------------------------------------

I do have a lot of problems with encoding in Vim.
I noted that Utf8 is not a good solution.

1) printing
I cannot print in utf8 format on my printer in VIM.
Letters as èéà are printed as A' and other string symbols
I do not have any problem printing in utf8 format in other text
editors.

2) opening files
Vim doesn't detect utf-8 or latin1 well.
Everything is mixed up.
Without anything written in the vimrc file,
all utf8 files are opened in latin1 (with unreadable éòà letters)

If I put this ":set fileencodings=ucs-bom,utf-8,default,latin1" in my
vimrc,
all latin1 files are opened in utf8 format (with unreadable -
converted- éòà letters)

----
I tried everything during these last months but it doesn't work as I
want.

I do not have any problem in other editors.
Notepad++ p.e.opens utf8 files as utf8 files and latin1 files as
latin1 files.
Btw latin1 is the default format in france and italy, I write a lot of
text in both languages.

Hope you can help me to find a solution.

Kind regards,
Rameo




--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

rameo
One more question:

Why can't I keep the utf8 settings of a file?

I don't have anything in my vimrc written about encoding.

I have a file and do:
set fenc=utf8
set enc=utf
e!  ++fenc=utf8
setlocal enc=utf8

Whatever I do, when I save the file and reopen the file again the
encoding is latin1 again.

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

Nikolay Aleksandrovich Pavlov
In reply to this post by rameo
Reply to message «Re: no echo output in command line»,
sent 10:36:13 09 November 2010, Tuesday
by rameo:

> As you've indicated, I removed the silent! flag, removed the exe
> before setlocal..., changed exe matchadd to call matchadd.
> Still no echo output. Changed it to echomsg, but still no output.
Have you checked `:messages'? Even your first version should echo something. How
do you run this function?

> 1) printing
> I cannot print in utf8 format on my printer in VIM.
> Letters as èéà are printed as A' and other string symbols
> I do not have any problem printing in utf8 format in other text
> editors.
Never experienced this problem (but never printed from vim). Opened new file,
wrote «∭x²y²z²dxdydz» there, got «□x²y²z²dxdydz» in terminal and «¿x²y²z²dxdydz»
on the paper. `enc' is `utf-8', `fenc' also `utf-8'. Did
    $ touch b
    $ vim b
    e ++enc=latin1
    ièéà^[:hardcopy
got `èéà' on paper. What is your system? What gives the output of ``echo
&printencoding''. (According to the help, `:hardcopy' does not have multibyte
support. Empty printencoding acts like printencoding=latin1.)

BTW, I never printed from vim before and now won't ever try to print from vim.
Try built-in `:TOhtml' or mine `formatvim'
(http://www.vim.org/scripts/script.php?script_id=3113) and print resulting html
instead.

> 2) opening files
> Vim doesn't detect utf-8 or latin1 well.
> Everything is mixed up.
> Without anything written in the vimrc file,
> all utf8 files are opened in latin1 (with unreadable éòà letters)
>
> If I put this ":set fileencodings=ucs-bom,utf-8,default,latin1" in my
> vimrc,
> all latin1 files are opened in utf8 format (with unreadable -
> converted- éòà letters)
Try ``set fileencodings=ucs-bom,utf-8,latin1,default''.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

Nikolay Aleksandrovich Pavlov
In reply to this post by rameo
Reply to message «Re: no echo output in command line»,
sent 17:07:01 09 November 2010, Tuesday
by rameo:

> Why can't I keep the utf8 settings of a file?
You can save encoding settings with a script, but before writing it try moving
`latin1' before `default' in `fileencodings' option:
    set fileencodings=ucs-bom,utf-8,latin1,default

> I don't have anything in my vimrc written about encoding.

> set fenc=utf8
As I already mentioned, this option is set by `e ++enc' and altering it has no
effect on already loaded file. According to the help, changing it will take
effect when you save it.
> set enc=utf
Can't find `utf' in ``:h encoding-names''.
> e!  ++fenc=utf8
It reloads the file with utf-8 encoding. It is not supposed to save information
about file encoding somewhere.
> setlocal enc=utf8
1. Do not change `enc'.
2. `enc' is a global option, so `setlocal', `setglobal' and `set' here have
exactly the same effect.

> Whatever I do, when I save the file and reopen the file again the
> encoding is latin1 again.
Does this file contain any invalid characters? Use `gg08g8' in normal mode to
find it after you opened file with `e ++enc=utf-8'. If they are found, remove
them.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

rameo
In reply to this post by Nikolay Aleksandrovich Pavlov
Hi,

Thank you for both replies.

On Nov 9, 5:51 pm, ZyX <[hidden email]> wrote:

> Reply to message «Re: no echo output in command line»,
> sent 10:36:13 09 November 2010, Tuesday
> by rameo:
>
> > As you've indicated, I removed the silent! flag, removed the exe
> > before setlocal..., changed exe matchadd to call matchadd.
> > Still no echo output. Changed it to echomsg, but still no output.
>
> Have you checked `:messages'? Even your first version should echo something. How
> do you run this function?

No, nothing about this in ":messages".

I run this script in menu.vim
The script works fine, it colored all the non latin1 characters as I
intended.

I noted that the encoding lines disabled the echo output.
Without the encoding lines i receive an echo output.

>
> > 1) printing
> > I cannot print in utf8 format on my printer in VIM.
> > Letters as èéà are printed as A' and other string symbols
> > I do not have any problem printing in utf8 format in other text
> > editors.
>
> Never experienced this problem (but never printed from vim). Opened new file,
> wrote «∭x²y²z²dxdydz» there, got «□x²y²z²dxdydz» in terminal and «¿x²y²z²dxdydz»
> on the paper. `enc' is `utf-8', `fenc' also `utf-8'. Did
>     $ touch b
>     $ vim b
>     e ++enc=latin1
>     ièéà^[:hardcopy
> got `èéà' on paper. What is your system? What gives the output of ``echo
> &printencoding''. (According to the help, `:hardcopy' does not have multibyte
> support. Empty printencoding acts like printencoding=latin1.)
>

Same here. In latin1 I can print fine.
In utf8 not.
I have to remove/modify all non latin1 characters before printing.

> BTW, I never printed from vim before and now won't ever try to print from vim.

You also do not print in Vim???
Why so many people do not print in Vim?
Is there no way to make printing interesting enough to print in Vim
self?

> Try built-in `:TOhtml' or mine `formatvim'

Yes, that is what I did a few times.
Now I'm transferring the text in another text editor and print from
there.

> (http://www.vim.org/scripts/script.php?script_id=3113) and print resulting html
> instead.
>
> > 2) opening files
> > Vim doesn't detect utf-8 or latin1 well.
> > Everything is mixed up.
> > Without anything written in the vimrc file,
> > all utf8 files are opened in latin1 (with unreadable éòà letters)
>
> > If I put this ":set fileencodings=ucs-bom,utf-8,default,latin1" in my
> > vimrc,
> > all latin1 files are opened in utf8 format (with unreadable -
> > converted- éòà letters)
>
> Try ``set fileencodings=ucs-bom,utf-8,latin1,default''.
>

I've already tried this one a few days ago. It opened all my (latin1)
files in utf8 and corrupted a few one after saving.

>  signature.asc
> < 1KViewDownload

You ask me about printencoding in your other message.
No output echoing it.
(printencoding is only available when compiled with the |+printer| and
|+postscript| features, not in gvim. I use gvim}

I'm thinking to stop trying with encoding.
I dedicated so much time to it.
I'll put everything in latin1 (global default), avoiding utf8 text and
print in browser or other texteditors.

Why is it that other editors do not have problems to save text in utf8
and recognizing the text as latin1 or utf8 (with/without BOM) when I
reopen the file?
Is it easier in windows to do this?

Vim is such a great editor, the best of all i.m.o., why can't the
printing problems (encoding problems) not being resolved, why is it
necessary that so many people have to print in external applications?

There is also another annoying thing, when printing in gvim, the text
has to be formatted before printing, if not it breaks in the middle of
words.

Thanks for your help :)
Rameo

--
You received this message from the "vim_use" 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
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

Nikolay Aleksandrovich Pavlov
Reply to message «Re: no echo output in command line»,
sent 20:33:36 09 November 2010, Tuesday
by rameo:

> No, nothing about this in ":messages".
>
> I run this script in menu.vim
> The script works fine, it colored all the non latin1 characters as I
> intended.
>
> I noted that the encoding lines disabled the echo output.
> Without the encoding lines i receive an echo output.
It should be a vim bug, but I failed to reproduce this behavior. Have you
removed old (set enc) or new (e ++enc) encoding lines? And what is your vim
version?

> Same here. In latin1 I can print fine.
> In utf8 not.
> I have to remove/modify all non latin1 characters before printing.
You should be able to print even in utf-8, but all characters that cannot be
converted to latin1 will be replaced.

> You also do not print in Vim???
> Why so many people do not print in Vim?
> Is there no way to make printing interesting enough to print in Vim
> self?
Because vim has lots of problems with printing coming from the time when you can
hardly imagine coloured printing of triple integral sign (problems both with
colours and multibyte characters, latter occures in other places too). Try
printing from kate (it is a good KDE editor), it will save all colours and print
all characters that are supported by your font. If you use vim, the only thing
you can do is to use some convert-to-html plugin and print the result of its
work (it is even mentioned just above the `:hardcopy' tag in `:h :hardcopy').

> I've already tried this one a few days ago. It opened all my (latin1)
> files in utf8 and corrupted a few one after saving.
It should not: latin1 file is not a valid UTF-8 file.

> You ask me about printencoding in your other message.
> No output echoing it.
> (printencoding is only available when compiled with the |+printer| and
>
> |+postscript| features, not in gvim. I use gvim}
I do not see why gvim cannot have `+printer' feature. I compile development
version with
    ./configure --with-features=huge
    make
and resulting vim executable has both gtk graphics and printer support. If you
want to see, whether you have printencoding option, use either
    echo has("postscript")
or
    echo exists('&printencoding')
. If you have not modified your `printencoding' then it is empty and
    echo &printencoding
will not echo anything. If you have printer support disabled, then it will echo
`E113' error, not nothing.

> There is also another annoying thing, when printing in gvim, the text
> has to be formatted before printing, if not it breaks in the middle of
> words.
Just another reason why one should not print from vim.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: no echo output in command line

rameo
Hi Zyx, pribiet :)

On Nov 9, 9:47 pm, ZyX <[hidden email]> wrote:
> Reply to message «Re: no echo output in command line»,
> sent 20:33:36 09 November 2010, Tuesday
> by rameo:
>
>
> It should be a vim bug, but I failed to reproduce this behavior. Have you
> removed old (set enc) or new (e ++enc) encoding lines? And what is your vim
> version?
>


Vim Version 7.3.46

When I disable the encoding lines the script gives an echo output.

  function! s:NonPrintable()
      "setlocal enc=utf8
      if search('[^\x00-\xff]') != 0
        call matchadd('Error', '[^\x00-\xff]')
        echo 'Non printable characters in text'
      else
       "setlocal enc=latin1
        echo 'All ok'
      endif
  endfunction

Now there is an echo output.

> > Same here. In latin1 I can print fine.
> > In utf8 not.
> > I have to remove/modify all non latin1 characters before printing.
>
> You should be able to print even in utf-8, but all characters that cannot be
> converted to latin1 will be replaced.
>

True.

> > You also do not print in Vim???
> > Why so many people do not print in Vim?
> > Is there no way to make printing interesting enough to print in Vim
> > self?
>
> Because vim has lots of problems with printing coming from the time when you can
> hardly imagine coloured printing of triple integral sign (problems both with
> colours and multibyte characters, latter occures in other places too). Try
> printing from kate (it is a good KDE editor), it will save all colours and print
> all characters that are supported by your font. If you use vim, the only thing
> you can do is to use some convert-to-html plugin and print the result of its
> work (it is even mentioned just above the `:hardcopy' tag in `:h :hardcopy').
>

Ok.

> > I've already tried this one a few days ago. It opened all my (latin1)
> > files in utf8 and corrupted a few one after saving.
>
> It should not: latin1 file is not a valid UTF-8 file.
>
> > You ask me about printencoding in your other message.
> > No output echoing it.
> > (printencoding is only available when compiled with the |+printer| and
>
> > |+postscript| features, not in gvim. I use gvim}
>
> I do not see why gvim cannot have `+printer' feature. I compile development
> version with
>     ./configure --with-features=huge
>     make
> and resulting vim executable has both gtk graphics and printer support. If you
> want to see, whether you have printencoding option, use either
>     echo has("postscript")
>

echo has("postscript") ---> 0


>     echo exists('&printencoding')

echo exists('&printencoding') ---> 1


> . If you have not modified your `printencoding' then it is empty and
>     echo &printencoding


echo &printencoding ---> nothing echoed.

> will not echo anything. If you have printer support disabled, then it will echo
> `E113' error, not nothing.
>
> > There is also another annoying thing, when printing in gvim, the text
> > has to be formatted before printing, if not it breaks in the middle of
> > words.
>
> Just another reason why one should not print from vim.
>

You are all working so long with VIM, Bram and the others.. no one is
enable to resolve these problems?

Kind regards,
Rameo

--
You received this message from the "vim_use" 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