On 2020-02-03, Ian Howell wrote:
> Describe the bug
> Reading from stdin (i.e. vim -) causes vim to mark the buffer as modified. 
> This
> prevents a user from quitting with :q, and instead must resort to :q!. This
> behavior runs contrary to what is documented under :h --, which states that
> "The buffer will not be marked as modified, so that it's easy to exit".

Interesting.  It has worked that way for as long as I can remember;
I thought it was supposed to work that way.  In fact, I have the
following in my vimrc to work around the issue.

    autocmd StdinReadPost * set nomodified

> This also prevents vim from opening to stdin in readonly mode, i.e. ls | vim 
> -R
> - causes vim to exit with the error W10: Warning: Changing a readonly file,
> followed by Vim: Error reading input, exiting.... This entirely prevents the
> view command from reading from stdin.
> 
> To Reproduce
> Run any command that produces output on stdout and pipe to vim -.
> Examples:
> 
> echo "hello" | vim -     # Opens with the string "hello", but must be closed 
> with :q!
> echo "hello" | vim -R -  # Fails to open vim
> echo "hello" | view      # Fails to open vim
> 
> The behavior can also be reproduced by running vim - alone, typing in some
> text, then sending the EOF signal, for example:
> 
> vim -             # Enter
> this is a test    # Enter
> # ctrl-d
> 
> The bug does not occur when using the previous example with vim -R -, in which
> case the buffer is not marked as modified, and behavior is as expected.

I can reproduce your results with "vim -", but not with "vim -R -"
or "view -".  The latter open vim and allow :q to quit.  I actually
tested with "-N -u NONE" added to your commands to avoid the effects
of my environment:

    echo "hello" | vim -N -u NONE -
    echo "hello" | vim -R -N -u NONE -
    echo "hello" | view -N -u NONE -

All three opened with the string "hello", but the first required :q!
to close while the last two required only :q.

However, the way I read the documentation, the current behavior of
"vim -R -" and "view -" that I observed is also wrong.  The :help
says:

    The buffer will not be marked as modified, so that it's easy
    to exit.  Be careful to mark it as modified if you don't want
    to accidentally lose it.  Example: >
            ls | view -

That second sentence, immediately followed by the view example,
suggests that the buffer in the view example will be marked as
modified, which it currently is not.

It looks to me like there's a test in the Vim code that's handled
backwards.  From a cursory look at the code, it looks like it might
be this, in the read_buffer() function in buffer.c.

    if (read_stdin)
    {
        // Set or reset 'modified' before executing autocommands, so that
        // it can be changed there.
        if (!readonlymode && !BUFEMPTY())
            changed();
        else if (retval == OK)
            unchanged(curbuf, FALSE, TRUE);

or perhaps this, executed later in open_buffer(), also in buffer.c.
Those first two sentences appear to contradict the :help.

    // When reading stdin, the buffer contents always needs writing, so set
    // the changed flag.  Unless in readonly mode: "ls | gview -".
    // When interrupted and 'cpoptions' contains 'i' set changed flag.
    if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
                || modified_was_set     // ":set modified" used in autocmd
#ifdef FEAT_EVAL
                || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
#endif
       )
        changed();
    else if (retval == OK && !read_stdin && !read_fifo)
        unchanged(curbuf, FALSE, TRUE);

I'll take a closer look at those when I have more time.

> Expected behavior
> Vim should open with the contents of stdin. The buffer should not be marked as
> modified.
> 
> Environment:
> 
>   • Vim version: 8.2.110
>   • OS: Ubuntu 18.04,
>   • Terminal: GNOME Terminal

I'm running Vim 8.2.140 on Ubuntu 18.04 in an xterm.

Regards,
Gary

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20200203210111.GA3735%40phoenix.

Raspunde prin e-mail lui