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

setqflist called from autocmd does not change current qf list #11424

Open
damage220 opened this issue Nov 19, 2019 · 2 comments
Open

setqflist called from autocmd does not change current qf list #11424

damage220 opened this issue Nov 19, 2019 · 2 comments
Labels
bug-vim wrong behavior inherited from vim

Comments

@damage220
Copy link

damage220 commented Nov 19, 2019

  • nvim --version: NVIM v0.4.3
  • vim -u DEFAULTS (version: 8.1, patches 1-2268) behaves the same.
  • Operating system/version: Arch Linux
  • Terminal name/version: termite v15
  • $TERM: xterm-termite

Steps to reproduce using nvim -u NONE

nvim -u NONE your-project
mistype something to populate qf list
:autocmd QuickFixCmdPost make call setqflist([], "a", {"nr": 2, "items": []})
:make
:cwindow
:chistory

Actual behaviour

After qf list is populated, the autocmd above creates another qf list at index 2. The initial qf list is still selected:

> error list 1 of 2; 13 errors    :make
  error list 2 of 2; 0 errors     :setqflist()

Expected behaviour

After qf list is populated, the autocmd above should create another qf list at index 2 and set it as the selected. Like when I call setqflist manually after :make.

  error list 1 of 2; 13 errors    :make
> error list 2 of 2; 0 errors     :setqflist()
@damage220 damage220 added the bug issues reporting wrong behavior label Nov 19, 2019
@justinmk
Copy link
Member

vim -u DEFAULTS (version: 8.1, patches 1-2268) behaves the same.

@chrisbra @yegappan is this expected behavior?

@justinmk justinmk added the bug-vim wrong behavior inherited from vim label Nov 20, 2019
@damage220
Copy link
Author

damage220 commented Nov 20, 2019

I am not sure whether this is intentional or not, but I think the behavior should be consistent both for autocmd and mapping/calling manually, unless the opposite is specified in the help. Also, here is the output of the following autocmd in vim 8.1:

autocmd QuickFixCmdPost make chist | call setqflist([], " ") | chist
> error list 1 of 1; 13 errors    :make
[setqflist call]
  error list 1 of 2; 13 errors    :make
> error list 2 of 2; 0 errors     :setqflist()

And when I type :chist again, it is already:

> error list 1 of 2; 13 errors    :make`
  error list 2 of 2; 0 errors     :setqflist()

No mention about restrictions on setqflist() (like sandbox or textlock) in the help page (did I miss something?). Again, it works if I just type :call setqflist([], " ") or call it from mapping. By the way, setloclist() is also affected.

These caused UB in my plugin.

" create copy of the initial qf list to be able to restore it in the future
" produces list #2
call setqflist(getqflist(), " ")

" filter current list and apply it
" because vim set #2 as current list, "r" flag make vim to redraw qf window
call setqflist(filtered_items, "r")

When autocmd handler has finished, vim restore current qf list to #1 and completely breaks qf window. qf window contains items from list #2, but commands like :cnext operate on list #1. QuickFixLine syntax group is broken, too.

@dundargoc dundargoc removed the bug issues reporting wrong behavior label Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-vim wrong behavior inherited from vim
Projects
None yet
Development

No branches or pull requests

3 participants