Skip to content

Commit 09ee857

Browse files
committed
Small changes
1 parent 60059dd commit 09ee857

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ require 'qf'.setup {
160160
auto_open = true, -- Automatically open list on QuickFixCmdPost
161161
auto_resize = true, -- Auto resize and shrink location list if less than `max_height`
162162
max_height = 8, -- Maximum height of location/quickfix list
163-
min_height = 5, -- Minumum height of location/quickfix list
163+
min_height = 5, -- Minimum height of location/quickfix list
164164
wide = false, -- Open list at the very bottom of the screen, stretching the whole width.
165165
number = false, -- Show line numbers in list
166166
relativenumber = false, -- Show relative line numbers in list
@@ -177,7 +177,7 @@ require 'qf'.setup {
177177
auto_open = true, -- Automatically open list on QuickFixCmdPost
178178
auto_resize = true, -- Auto resize and shrink location list if less than `max_height`
179179
max_height = 8, -- Maximum height of location/quickfix list
180-
min_height = 5, -- Minumum height of location/quickfix list
180+
min_height = 5, -- Minimum height of location/quickfix list
181181
wide = false, -- Open list at the very bottom of the screen, stretching the whole width.
182182
number = false, -- Show line numbers in list
183183
relativenumber = false, -- Show relative line numbers in list

lua/qf.lua

+37-23
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local list_defaults = {
1212
auto_open = true, -- Automatically open list on QuickFixCmdPost
1313
auto_resize = true, -- Auto resize and shrink location list if less than `max_height`
1414
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
1616
wide = false, -- Open list at the very bottom of the screen, stretching the whole width.
1717
number = false, -- Show line numbers in list
1818
relativenumber = false, -- Show relative line numbers in list
@@ -95,11 +95,11 @@ local function setup_autocmds(config)
9595
cmd('autocmd QuickFixCmdPost ' .. loc_post_commands() .. ' :lua require"qf".open("l", true)')
9696
end
9797

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
101101

102-
cmd('autocmd WinNew * :lua require"qf".reopen_all()')
102+
-- cmd('autocmd WinLeave * :lua require"qf".reopen_all()')
103103

104104
cmd('autocmd QuitPre * :lua require"qf".close("loc")')
105105

@@ -192,25 +192,30 @@ end
192192
-- Close and opens list if already open.
193193
-- This is to fix the list stretching bottom of a new vertical split.
194194
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'
196198
return
197199
end
198200

199201
list = fix_list(list)
200202
local num_items = #list_items(list)
201203

202204
if not M.list_visible(list) then
205+
-- print 'not visible'
203206
return
204207
end
205208

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))
208210

209211
M.on_ft()
212+
213+
cmd("noau wincmd p")
210214
end
211215

212216
function M.reopen_all()
213217
local reopen = M.reopen
218+
-- print("Reopening")
214219
reopen('c')
215220
reopen('l')
216221
end
@@ -278,18 +283,18 @@ function M.resize(list, stay, num_items)
278283
cmd(list .. "open " .. height )
279284

280285
if stay then
281-
cmd "noau wincmd p"
286+
cmd "wincmd p"
282287
end
283288
end
284289

285290
-- Open the `quickfix` or `location` list
286291
-- If stay == true, the list will not be focused
287292
-- 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)
289294
list = fix_list(list)
290295

291296
local opts = M.config[list]
292-
local num_items = #list_items(list)
297+
num_items = num_items or #list_items(list)
293298

294299
check_empty(list, num_items, verbose)
295300

@@ -299,24 +304,25 @@ function M.open(list, stay, verbose)
299304
cmd(list .. 'close')
300305
else
301306
-- List is empty, but ensure it is properly sized
302-
M.resize(list, true, num_items)
307+
-- M.resize(list, true, num_items)
303308
end
304309
return
305310
end
306311

307-
cmd(list .. 'open ' .. get_height(list, num_items))
308-
309-
if stay then
310-
cmd "noau wincmd p"
311-
end
312-
313312
if opts.close_other then
314313
if list == 'c' then
315314
cmd 'lclose'
316315
elseif list == 'l' then
317316
cmd 'cclose'
318317
end
319318
end
319+
320+
cmd(list .. 'open ' .. get_height(list, num_items))
321+
322+
if stay then
323+
cmd "wincmd p"
324+
end
325+
320326
end
321327

322328
-- Close list
@@ -689,22 +695,30 @@ end
689695

690696
-- Set location or quickfix list items
691697
-- Invalidates follow cache
692-
function M.set(list, items)
698+
function M.set(list, items, title, winid)
693699
list = fix_list(list)
694700

695701
if list == 'c' then
696-
fn.setqflist(items)
702+
vim.fn.setqflist({}, 'r', {
703+
title = title or '',
704+
items = items;
705+
})
697706
else
698-
fn.setloclist('.', items)
707+
vim.fn.setloclist(winid or 0, {}, 'r', {
708+
title = title or '',
709+
items = items;
710+
})
699711
end
700712

701713
local opts = M.config[list]
702714
opts.last_line = nil
703715

704-
if #items == 0 and opts.auto_close then
716+
if #items == 0 and opts.auto_close then
705717
M.close(list)
718+
-- elseif M.list_visible(list) then
719+
-- M.resize(list, true, #items)
706720
elseif opts.auto_open then
707-
M.open(list, true)
721+
M.open(list, true, #items)
708722
end
709723
end
710724

0 commit comments

Comments
 (0)