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

feature request: jump to previous or next entry when the context is expanded #3

Closed
1 task done
TymekDev opened this issue Aug 7, 2024 · 2 comments
Closed
1 task done
Labels
enhancement New feature or request

Comments

@TymekDev
Copy link

TymekDev commented Aug 7, 2024

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

I think that either a function or a recipe for jumping to the previous or the next entry when the context is expanded would be useful!

Provide background

I came up with these entries for keys (< and > are the keybinds suggested in the READM). These work, but definitely feel hacky. Perhaps an out-of the box solution would be better?

 {
  "]q",
  function()
    vim.cmd.normal("<j")
    vim.cmd.normal(">")
  end,
},
{
  "[q",
  function()
    vim.cmd.normal("<k")
    vim.cmd.normal(">")
  end,
},

Note: it's deliberately split into two calls, because vim.cmd.normal("<j>") stopped at j when I had the cursor on the last row.

What is the significance of this feature?

nice to have

Additional details

No response

@TymekDev TymekDev added the enhancement New feature or request label Aug 7, 2024
@stevearc
Copy link
Owner

stevearc commented Aug 8, 2024

Usually I would use :cnext and :cprev for this, but that also jumps to those locations. If you just want to move the cursor in the quickfix window, try this:

require("quicker").setup({
  keys = {
    {
      "]q",
      function()
        local items = vim.fn.getqflist()
        local lnum = vim.api.nvim_win_get_cursor(0)[1]
        for i = lnum + 1, #items do
          if items[i].valid == 1 then
            vim.api.nvim_win_set_cursor(0, { i, 0 })
            return
          end
        end
      end,
    },
    {
      "[q",
      function()
        local items = vim.fn.getqflist()
        local lnum = vim.api.nvim_win_get_cursor(0)[1]
        for i = lnum - 1, 1, -1 do
          if items[i].valid == 1 then
            vim.api.nvim_win_set_cursor(0, { i, 0 })
            return
          end
        end
      end,
    },
  },
})

@stevearc stevearc added the question Further information is requested label Aug 8, 2024
@TymekDev
Copy link
Author

TymekDev commented Aug 8, 2024

Thanks! That's definitely cleaner than what I came up with.

I am well aware of :cnext and :cprev - I even have nifty mappings to make them wrap at the ends. As you said, though, these jump to locations. With context I can find the right entry and go directly there instead of jumping between locations to find the right one.

Thanks for help and an awesome plugin! 😁

Edit: if you would like the above solution to wrap around the start and the end of quickfix list, then change it to:

require("quicker").setup({
  keys = {
    {
      "]q",
      function()
        local items = vim.fn.getqflist()
        local lnum = vim.api.nvim_win_get_cursor(0)[1]
        for i = lnum + 1, #items do
          if items[i].valid == 1 then
            vim.api.nvim_win_set_cursor(0, { i, 0 })
            return
          end
        end
        -- Wrap around the end of quickfix list
        for i = 1, lnum do
          if items[i].valid == 1 then
            vim.api.nvim_win_set_cursor(0, { i, 0 })
            return
          end
        end
      end,
    },
    {
      "[q",
      function()
        local items = vim.fn.getqflist()
        local lnum = vim.api.nvim_win_get_cursor(0)[1]
        for i = lnum - 1, 1, -1 do
          if items[i].valid == 1 then
            vim.api.nvim_win_set_cursor(0, { i, 0 })
            return
          end
        end
        -- Wrap around the start of quickfix list
        for i = #items, lnum, -1 do
          if items[i].valid == 1 then
            vim.api.nvim_win_set_cursor(0, { i, 0 })
            return
          end
        end
      end,
    },
  },
})

@TymekDev TymekDev closed this as completed Aug 8, 2024
@github-actions github-actions bot removed the question Further information is requested label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants