Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

":silent loadview" does not suppress errors #3196

Closed
brunobeltran opened this issue Aug 19, 2015 · 18 comments
Closed

":silent loadview" does not suppress errors #3196

brunobeltran opened this issue Aug 19, 2015 · 18 comments
Assignees
Labels
compatibility compatibility with Vim or older Neovim
Milestone

Comments

@brunobeltran
Copy link

As mentioned (and maybe forgotten) in Issue #2194, nvim does not respect a request to "silently" perform a command. In particular, with a nvim at HEAD installed and a blank .nvimrc, the command

silent loadview

will generate the output

E484: Can't open file /home/$USERNAME/.nvim/view/~=+$FILENAME=

In Vim, the behavior is to ignore a missing file whether or not silent is specified. This breaks the suggestion documented under :help loadview (e.g. http://neovim.io/doc/user/starting.html#:loadview).

Is there a workaround for this (besides the obvious hack of just checking for the existence of the view file, which only applies to this particular usage of the word silent)?

Another easy way to reproduce this but is to open stock neovim and type :silent !echo hello

The correct behavior here is to print nothing (and, in vim, possibly jumble the screen, forcing a manual redraw with :redraw! or <c-l>).

In neovim, the word "hello" is actually printed (although the manual redraw is still required.

@justinmk justinmk added the bug issues reporting wrong behavior label Aug 19, 2015
@justinmk justinmk added this to the 0.1-first-public-release milestone Aug 19, 2015
@justinmk
Copy link
Member

The issue title seems a bit broad.

@brunobeltran
Copy link
Author

Doesn't seem so to me. It's one specific keyword, silent which is buggy.
El 19/8/2015 8:26, "Justin M. Keyes" notifications@github.com escribió:

The issue title seems a bit broad.


Reply to this email directly or view it on GitHub
#3196 (comment).

@justinmk
Copy link
Member

What I mean is, are there are other cases where :silent is not respected? :silent echo 'hi' works as expected, as well as :silent edit <file>.

@brunobeltran
Copy link
Author

Not on my box, and I just built head.
El 19/8/2015 10:03, "Justin M. Keyes" notifications@github.com escribió:

What I mean is, are there are other cases where :silent is not respected? :silent
echo 'hi' works as expected, as well as :silent edit .


Reply to this email directly or view it on GitHub
#3196 (comment).

@brunobeltran
Copy link
Author

Strange, actually, after waking up this morning, I can't reproduce the bug except for commands of the form

:silent! !shell_command_with_output

For these commands, the shell output is displayed. Then again, it's not clear to me anymore if this is a bug or intended.

w.r.t. my other complaints, it looks like I forgot the ! in my silent! loadview commands before, since Vim incorrectly did not require it.

If :silent! !echo 'hello' is supposed to print hello, then I should just close the issue. Otherwise, you're right, the title should be made more specific.

@brunobeltran brunobeltran changed the title neovim does not respect "silent" neovim does not respect "silent" when executing shell commands Aug 19, 2015
@justinmk justinmk changed the title neovim does not respect "silent" when executing shell commands ":silent !" (and ":silent te") should be silent Jan 9, 2016
@Cypher1
Copy link

Cypher1 commented Jul 25, 2016

I'm having this as well with

au BufRead * silent loadview

@mhinz
Copy link
Member

mhinz commented Jul 25, 2016

I'm not even sure what's the problem here. :loadview throwing an error if a file can't be found makes sense to me. To silence errors, use :silent! instead.

:silent !echo foo? What is that supposed to do? Filtering stdout? Giving a blank window like Vim does? What's the use case for this?

:silent term makes even less sense to me, it opens an interactive terminal emulator after all.

@Cypher1
Copy link

Cypher1 commented Jul 25, 2016

The problem is that silent isn't silencing the error.

On Mon., 25 Jul. 2016, 10:37 pm Marco Hinz, notifications@github.com
wrote:

I'm not even sure what's the problem here. :loadview throwing an error if
a file can't be found makes sense to me. To silence errors, use :silent!
instead.

:silent !echo foo? What is that supposed to do? Filtering stdout? What's
the use case for this?

:silent term makes even less sense to me, it opens an interactive
terminal emulator after all.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#3196 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABEaHqgVH8tgtDz3vYFCAWGv5l8TSmnVks5qZK4HgaJpZM4FuKe-
.

@mhinz
Copy link
Member

mhinz commented Jul 25, 2016

You mean silent!, right? :silent silences everything but errors.

@Cypher1
Copy link

Cypher1 commented Jul 26, 2016

Yes. Also doesn't work for silent!
Note: this is different behavior to vim which is why it causes trouble.

The work around for shortcuts is to use the very nasty:

:execute "try\n loadview\ncatch\nendtry"

Which correctly silences errors.

On Tue., 26 Jul. 2016, 12:09 am Marco Hinz, notifications@github.com
wrote:

You mean silent!, right? :silent silences everything but errors.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#3196 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABEaHu-hlSiX_OiAwzyGOaocQ6mUXnxHks5qZMOYgaJpZM4FuKe-
.

@ZyX-I
Copy link
Contributor

ZyX-I commented Jul 26, 2016

@Cypher1 It does not silence errors. It ignores exceptions, transforming errors into exceptions in process. Difference may be seen if you have some code after a error: e.g.

redir => g:s | silent! execute 'echo xxx_nonexistent_var_xxx | echo 42' | redir END
echo g:s

will yield two errors (E121 about not existing variable and E15 about invalid expression) and 42.

redir => g:s | try | execute 'echo xxx_nonexistent_var_xxx | echo 42' | catch | endtry | redir END
echo g:s

will yield nothing because E121 was transformed into an exception (and thus not printed and not captured by :redir), E15 ignored and echo 42 not run because unlike errors, exceptions stop execution.

@Cypher1
Copy link

Cypher1 commented Jul 26, 2016

That may be, but I am in favor of it acting in the same way as vim. This
change is pretty annoying for :loadview

On Tue., 26 Jul. 2016, 11:49 am Nikolai Aleksandrovich Pavlov, <
notifications@github.com> wrote:

@Cypher1 https://github.com/Cypher1 It does not silence errors. It
ignores exceptions, transforming errors into exceptions in process.
Difference may be seen if you have some code after a error: e.g.

redir => g:s | silent! execute 'echo xxx_nonexistent_var_xxx | echo 42' | redir ENDecho g:s

will yield two errors (E121 about not existing variable and E15 about
invalid expression) and 42.

redir => g:s | try | execute 'echo xxx_nonexistent_var_xxx | echo 42' | catch | endtry | redir ENDecho g:s

will yield nothing because E121 was transformed into an exception (and
thus not printed and not captured by :redir), E15 ignored and echo 42 not
run because unlike errors, exceptions stop execution.


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#3196 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABEaHlOjTR6XlH2zrtb0BsBgczgSBVTwks5qZWeNgaJpZM4FuKe-
.

@hagabaka
Copy link

hagabaka commented Nov 17, 2016

au BufWinEnter ?* silent! loadview suppresses the error messages for me now.

@justinmk justinmk modified the milestones: 0.3, 0.2 Nov 18, 2016
@tartley
Copy link

tartley commented Dec 11, 2016

I used to use :silent in Vim to prevent 'grep' output being shown (instead I merely want it to populate the quickfix window) Nowadays in Neovim, my grep output is also shown (with the additional wrinkle that if the quickfix is already open, this causes screen corruption that requires a Ctrl-L redraw. Different issue.)

:silent fails to suppress the output for either :silent grep ... (Vim's 'grep' command) or :silent !grep ... (run external 'grep' executable directly)

I can see that there is a potential argument that it should not silence the output from running external !grep (although I don't agree) but I think it is uncontroversial that it should work for the Vim grep command (even if this ultimately also invokes the external grep executable.)

One obvious workaround, to run the external 'grep' command with a redirection to >/dev/null, doesn't work in this case: I want the output to be produced so that Neovim can read it to populate the quickfix window. I just don't want all the intermediate text this produces on grep's stdout to be echoed on top of NeoVim's UI.

FWIW I reverted my custom grepprg to the standard grep -n, and confirmed I still see the behaviour I describe.

@justinmk
Copy link
Member

justinmk commented Dec 12, 2016

I'm confused by the various comments here. Are these requests for breaking compatibility with Vim, or are they bug reports about regressions? In Vim, :silent grep ... is not silent at all, and it's even more weird because it requires CTRL-L in some cases. Neither is :silent !grep.

What we can do is make :silent terminal ... actually be silent. We can do that without breaking compatibility. Though I can't imagine why it would be useful: if you don't care about the result, use jobstart() instead.

@justinmk justinmk changed the title ":silent !" (and ":silent te") should be silent ":silent loadview" does not suppress errors Dec 12, 2016
@tartley
Copy link

tartley commented Dec 14, 2016

Beg your pardon if I muddied the waters. It appears you are right and my memory was misleading me. I fired up Vim and :silent does not suppress the output of grep. I could have sworn it used to work that way for me, but perhaps I am just wrong.

@nikolavp
Copy link

OK so basically loadview in vim doesn't report an error if the file is not found? What I had to do is to change

silent loadview

to

silent! loadview

@justinmk
Copy link
Member

justinmk commented Apr 20, 2017

This was changed in 9b1c939 to fix a coverity warning. Not to mention, it's rather dodgy to silently fail if the file can't be opened.

Using :silent! instead of :silent is a completely reasonable approach that lets the user decide, while still being able to get feedback if :loadview fails unexpectedly.

#6552 changes :help :loadview to recommend :silent!.

@justinmk justinmk added compatibility compatibility with Vim or older Neovim and removed bug issues reporting wrong behavior labels Apr 20, 2017
@justinmk justinmk self-assigned this Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility compatibility with Vim or older Neovim
Projects
None yet
Development

No branches or pull requests

8 participants