2

I got some code that jobstart() a ripgrep, but if there is an error I wish to show it. At the on_exit callback a summary message is echom'ed after whether it was successfull or not.

Unfortunately I only ever see the exit summary message, not the "error" message from SearchOnStderr below: Note: The reason I am not using "echoerr" is because I don't wish to have the line number and some other info printed (however echoerr does pause the messages to one can read it). Although echo can print multiline, it is not added to the :messages, hence I did not use that either.

If I use an input (like below), then I only see the "Press <ENTER> ...".

let dummy = input("Press <ENTER> ...")

:h echo-redraw talks about using redraws to prevent losing messages. But I have never gotten redraw to help at all.

function! myautoload#SearchOnStderr(job_id, data, event)
    let height_bak = &cmdheight
    set cmdheight=12
    redraw
    echom "SEARCH ERROR, job_id:".a:job_id." event:".a:event
    echohl errormsg
    for errorLine in a:data
        echom errorLine
    endfor
    echohl normal
    " ... WAIT HERE for enter to be pressed ...
    exe "set cmdheight=".height_bak
endfun

Desired output (With maybe a press enter to continue after it) is shown in the image below. This message is displayed too fast to read, so one has to look at :messages to read it: enter image description here

EDITS: Adding requested additional info. Yes I'm using Neovim. Here's some of parts of the code of interest:

function! myautoload#SearchInFiles()
    let g:searchString = input('Search in Files '.getcwd().': ')
    let g:search_errors = 0
    let rg_cmd = 'rg -H --no-heading --column --line-number --smart-case '.g:searchString

    " Clear the quickfix of entries
    silent copen " Must be first so over operate on quickfix window
    let title = " ".g:searchString. "     Command: ".rg_cmd
    let context = {'cmd' : rg_cmd}
    call setqflist([], ' ', {'title' : title, 'context' : context})
    echom "--------------------------------------------------"
    echom "About to start job..."
    let opts_dict = {'on_exit': 'myautoload#SearchOnExit', 'on_stdout': 'myautoload#SearchOnStdout', 'on_stderr': 'myautoload#SearchOnStderr'}
    let terminal_buf_nr = jobstart(rg_cmd, opts_dict)
endfunction



function! myautoload#SearchOnExit(job_id, data, event)
    " Refer to :h getqflist-examples*
    let num_entries = getqflist({'size' : 0}).size

    if g:search_errors
        echom "Complete with ERRORS. ".num_entries." entries for: ".g:searchString
    else
        echom "COMPLETE. ".num_entries." entries for: ".g:searchString
    endif
endfun

11
  • 1
    Why do you reset the height of the command-line to 12?
    – user938271
    Apr 27, 2020 at 11:02
  • 1
    @user938271 So one can see the whole error message. Was something I tried, probably not helpful.... Hopefully the command window height auto grows if one displays the message correctly. Apr 27, 2020 at 11:41
  • 1
    @run_the_race You don't need to reset the height of the command-line for that. Try this: 0x0.st/ijCn.txt
    – user938271
    Apr 27, 2020 at 11:47
  • 1
    There is not enough information in the question: Vim or Neovim? What is jobexit() (can't find this function in the help)? How is the job started and with which options? Basically, a simple and complete example. In any case, you can't have the desired hit-enter prompt if height of the command-line is increased too much. Besides, if you have several callbacks each displaying their own message, the last one may erase the message of the previous one.
    – user938271
    Apr 27, 2020 at 12:18
  • 3
    Finally, if you're using Nvim, there is a known issue which prevents a callback from printing a multi-line message (github.com/neovim/neovim/issues/5067).
    – user938271
    Apr 27, 2020 at 12:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.