@@ -12,7 +12,7 @@ local list_defaults = {
12
12
auto_open = true , -- Automatically open list on QuickFixCmdPost
13
13
auto_resize = true , -- Auto resize and shrink location list if less than `max_height`
14
14
max_height = 8 , -- Maximum height of location/quickfix list
15
- min_height = 5 , -- Minumum height of location/quickfix list
15
+ min_height = 5 , -- Minimum height of location/quickfix list
16
16
wide = false , -- Open list at the very bottom of the screen, stretching the whole width.
17
17
number = false , -- Show line numbers in list
18
18
relativenumber = false , -- Show relative line numbers in list
@@ -95,11 +95,11 @@ local function setup_autocmds(config)
95
95
cmd (' autocmd QuickFixCmdPost ' .. loc_post_commands () .. ' :lua require"qf".open("l", true)' )
96
96
end
97
97
98
- if c .auto_open then
99
- cmd (' autocmd QuickFixCmdPost ' .. qf_post_commands () .. ' :lua require"qf".open("c", true)' )
100
- end
98
+ -- if c.auto_open then
99
+ -- cmd('autocmd QuickFixCmdPost ' .. qf_post_commands() .. ' :lua require"qf".open("c", true)')
100
+ -- end
101
101
102
- cmd (' autocmd WinNew * :lua require"qf".reopen_all()' )
102
+ -- cmd('autocmd WinLeave * :lua require"qf".reopen_all()')
103
103
104
104
cmd (' autocmd QuitPre * :lua require"qf".close("loc")' )
105
105
@@ -192,25 +192,30 @@ end
192
192
-- Close and opens list if already open.
193
193
-- This is to fix the list stretching bottom of a new vertical split.
194
194
function M .reopen (list )
195
- if vim .o .ft == ' qf' then
195
+ local prev = fn .win_getid (fn .winnr (' #' ))
196
+ if api .nvim_buf_get_option (api .nvim_win_get_buf (0 ), ' filetype' ) ~= ' qf' or api .nvim_buf_get_option (api .nvim_win_get_buf (prev ), ' filetype' ) ~= ' qf' then
197
+ -- print'qf'
196
198
return
197
199
end
198
200
199
201
list = fix_list (list )
200
202
local num_items = # list_items (list )
201
203
202
204
if not M .list_visible (list ) then
205
+ -- print 'not visible'
203
206
return
204
207
end
205
208
206
- print (" Reopening " .. list )
207
- cmd (' noau wincmd p | noau ' .. list .. ' close | ' .. list .. ' open ' .. get_height (list , num_items ))
209
+ cmd (' noau ' .. list .. ' close | noau ' .. list .. ' open ' .. get_height (list , num_items ))
208
210
209
211
M .on_ft ()
212
+
213
+ cmd (" noau wincmd p" )
210
214
end
211
215
212
216
function M .reopen_all ()
213
217
local reopen = M .reopen
218
+ -- print("Reopening")
214
219
reopen (' c' )
215
220
reopen (' l' )
216
221
end
@@ -278,18 +283,18 @@ function M.resize(list, stay, num_items)
278
283
cmd (list .. " open " .. height )
279
284
280
285
if stay then
281
- cmd " noau wincmd p"
286
+ cmd " wincmd p"
282
287
end
283
288
end
284
289
285
290
-- Open the `quickfix` or `location` list
286
291
-- If stay == true, the list will not be focused
287
292
-- If auto_close is true, the list will be closed if empty, similar to cwindow
288
- function M .open (list , stay , verbose )
293
+ function M .open (list , stay , verbose , num_items )
289
294
list = fix_list (list )
290
295
291
296
local opts = M .config [list ]
292
- local num_items = # list_items (list )
297
+ num_items = num_items or # list_items (list )
293
298
294
299
check_empty (list , num_items , verbose )
295
300
@@ -299,24 +304,25 @@ function M.open(list, stay, verbose)
299
304
cmd (list .. ' close' )
300
305
else
301
306
-- List is empty, but ensure it is properly sized
302
- M .resize (list , true , num_items )
307
+ -- M.resize(list, true, num_items)
303
308
end
304
309
return
305
310
end
306
311
307
- cmd (list .. ' open ' .. get_height (list , num_items ))
308
-
309
- if stay then
310
- cmd " noau wincmd p"
311
- end
312
-
313
312
if opts .close_other then
314
313
if list == ' c' then
315
314
cmd ' lclose'
316
315
elseif list == ' l' then
317
316
cmd ' cclose'
318
317
end
319
318
end
319
+
320
+ cmd (list .. ' open ' .. get_height (list , num_items ))
321
+
322
+ if stay then
323
+ cmd " wincmd p"
324
+ end
325
+
320
326
end
321
327
322
328
-- Close list
@@ -689,22 +695,30 @@ end
689
695
690
696
-- Set location or quickfix list items
691
697
-- Invalidates follow cache
692
- function M .set (list , items )
698
+ function M .set (list , items , title , winid )
693
699
list = fix_list (list )
694
700
695
701
if list == ' c' then
696
- fn .setqflist (items )
702
+ vim .fn .setqflist ({}, ' r' , {
703
+ title = title or ' ' ,
704
+ items = items ;
705
+ })
697
706
else
698
- fn .setloclist (' .' , items )
707
+ vim .fn .setloclist (winid or 0 , {}, ' r' , {
708
+ title = title or ' ' ,
709
+ items = items ;
710
+ })
699
711
end
700
712
701
713
local opts = M .config [list ]
702
714
opts .last_line = nil
703
715
704
- if # items == 0 and opts .auto_close then
716
+ if # items == 0 and opts .auto_close then
705
717
M .close (list )
718
+ -- elseif M.list_visible(list) then
719
+ -- M.resize(list, true, #items)
706
720
elseif opts .auto_open then
707
- M .open (list , true )
721
+ M .open (list , true , # items )
708
722
end
709
723
end
710
724
0 commit comments