On 12-Jun-2014 13:07 +0200, Ingo Karkat wrote:

> On 12-Jun-2014 12:51 +0200, Bram Moolenaar wrote:
> 
>> Christian wrote:
>>
>>> On Di, 10 Jun 2014, Ingo Karkat wrote:
>>>
>>>> Hello Vim developers,
>>>>
>>>> a question on Super User
>>>> (http://superuser.com/questions/766817/hide-non-printable-characters-in-vim/)
>>>> asks to show all non-printable (control) characters with a single
>>>> display cell. One (hacky, and arguably not perfect) way to do this is by
>>>> including all ASCII characters in 'isprint':
>>>>
>>>>     :set isprint=0-255
>>>>
>>>> However, this yields "E474: Invalid argument". It only works by
>>>> excluding ^@ = 0 (via :set isprint=1-255). Also, other variants such as
>>>> :set isprint^=0 and :set isprint=0,1-255 and :set
>>>> isprint=<C-v><C-@>,1-255 do not work (verified up to current version
>>>> 7.4.316).
>>>>
>>>> The same applies to the similar 'isfname' setting, even though its
>>>> documentation (and 'isprint' refers to that, too) explicitly mentions
>>>> the number 0:
>>>>
>>>> ,----[ :help 'isfname' excerpt ]----
>>>> | The format of this option is a list of parts, separated with commas.
>>>> | Each part can be a single character number or a range.  A range is two
>>>> | character numbers with '-' in between.  A character number can be a
>>>> | decimal number between 0 and 255 or the ASCII character itself (does
>>>> | not work for digits).
>>>> `----
>>>>
>>>> I see this as a bug in the :set command, or, if technical reasons
>>>> prevent the use of ^@ in those option values, a bug in the
>>>> documentation. (Preferably, to address the issue in the mentioned
>>>> question, the first. :-)
>>>
>>> I don't know if it is a bug or it was done intentionally and I even 
>>> don't know what :set isprint=0-255 is supposed to be doing. But here is 
>>> a patch:
>>>
>>> diff --git a/src/charset.c b/src/charset.c
>>> --- a/src/charset.c
>>> +++ b/src/charset.c
>>> @@ -197,7 +197,7 @@ buf_init_chartab(buf, global)
>>>  #endif
>>>                     c2 = *p++;
>>>             }
>>> -           if (c <= 0 || c >= 256 || (c2 < c && c2 != -1) || c2 >= 256
>>> +           if (c < 0 || c >= 256 || (c2 < c && c2 != -1) || c2 >= 256
>>>                                                  || !(*p == NUL || *p == 
>>> ','))
>>>                 return FAIL;
>>
>> Well, this allows having a zero in the option value, but I very much
>> doubt it actually works.  In C the zero is used to terminate a string,
>> thus sending a zero to the terminal just won't work.
> 
> Well, at least I can do this in a terminal:
> 
>     $ printf "foo\0bar\n"
>     foobar
> 
> Seems like Bash handles this somehow, and the NUL is skipped / prints as
> nothing.
> 
>> If you want to *display* control characters you need to do something
>> else anyway, since sending a BS or other control character won't result
>> in displaying anything.
> 
> The OP's use case is representing every character by a single display
> cell. Obviously, BS will mess up things. But probably, a (binary) file
> won't contain many of those (in the area of interest), but possibly a
> lot of NULs. Skipping those in the output might be okay for his use.

I've just tested Christian's patch (on Ubuntu 13.10); adding 0 to
'isprint' messes up the displayed window contents in terminal Vim, less
so in GVIM (there, the NUL is shown as "?", but I still saw occasional
glitches when navigating in the window).

At least, no crashes or other critical problems. So, adding the patch
would make the option more consistent by allowing the 0 value, even
though it's questionable that the current behavior is of any actual use
(but maybe this prompts someone to develop better support for that).

-- regards, ingo

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui