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

qf.below/qf.above not working when called from inside the quickfix buffer #10

Open
mawkler opened this issue May 11, 2023 · 2 comments
Open

Comments

@mawkler
Copy link
Contributor

mawkler commented May 11, 2023

qf.below/qf.above don't seem to be working when called from inside the quickfix list buffer. When triggered, qf jumps to the line under the cursor, not the next/previous one. I took a look at the code and it seems to be looking for the item's buffer number and comparing it to the quickfix buffer's buffer number, which will never match.

Here's a lazy.nvim config to reproduce:

{
  'ten3roberts/qf.nvim',
  config = function()
    local qf = require('qf')
    qf.setup()

    vim.keymap.set('n', '<C-j>', qf.below)
    vim.keymap.set('n', '<C-k>', qf.above)
    vim.keymap.set('n', 'Q', function ()
      local current_buf = vim.api.nvim_get_current_buf()
      vim.fn.setqflist({
        { filename = vim.fn.bufname(current_buf), lnum = 1, text = "first line" },
        { filename = vim.fn.bufname(current_buf), lnum = 2, text = "second line" },
      })
    end)
  end
}

You can use the Q mapping to populate the quickfix list with the first two lines of the current buffer.

@mawkler mawkler changed the title qf.below/qf.above not working qf.below/qf.above not working when called from inside the quickfix buffer May 11, 2023
@ten3roberts
Copy link
Owner

Yes, the above/below emulate :cabove and :cbelow but allow navigating across buffer boundaries and multiple errors per single line.

							*:cbel* *:cbelow*
:[count]cbel[ow]	Go to the [count] error below the current line in the
			current buffer.  If [count] is omitted, then 1 is
			used.  If there are no errors, then an error message
			is displayed.  Assumes that the entries in a quickfix
			list are sorted by their buffer number and line
			number.  If there are multiple errors on the same
			line, then only the first entry is used.  If [count]
			exceeds the number of entries below the current line,
			then the last error in the file is selected.

As the below item is based on the current buffer and position, it is not well defined when the buffer isn't in the quickfix entries. What it does now is compare the bufnr numerically as they are sorted in the quickfix list.

If the current buffer > entry buffer the buffer was not present in the list.

However, if the current buffer is the higher than any item in the list it reaches the end of the loop.

What do you think it should do?

For quickfix buffers it could fall back to next/prev, but for normal buffers not in the entry it will currently select the next higher bufnr that is in the list

@mawkler
Copy link
Contributor Author

mawkler commented May 26, 2023

@ten3roberts

What do you think it should do?

For quickfix buffers it could fall back to next/prev

Yes, that sounds reasonable to me 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants