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] Save Quickfix List #173

Open
ariel-frischer opened this issue Sep 19, 2022 · 9 comments
Open

[FEATURE] Save Quickfix List #173

ariel-frischer opened this issue Sep 19, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@ariel-frischer
Copy link

Is your feature request related to a problem? Please describe.
I want to be able to save the quickfix list for each session and maybe even location list.

Describe the solution you'd like
Saving the quickfix list in the session file.

@ariel-frischer ariel-frischer added the enhancement New feature or request label Sep 19, 2022
@rmagatti
Copy link
Owner

rmagatti commented Sep 19, 2022

Hey @ariel-frischer essentially there is currently no sessionoptions for quickfix in Vim. I agree it would be a welcome addition, in fact there is an old open issue about it in neovim/neovim#7602 about this very thing. Hopefully we can get some traction on that.

As for somehow implementing this through auto-session, it's not one of the goals of this plugin to implement its own session management separately from what Neovim has to offer, that said, one could use probably the session hooks to achieve saving and reloading the quickfix window while there isn't any upstream support for it.

@ariel-frischer
Copy link
Author

ariel-frischer commented Sep 19, 2022

@rmagatti Thanks for the response, that issue does seem super old though (2017!) so I'll look into using the session hook. Really loving the repository though it works great out of the box!

@rmagatti
Copy link
Owner

I'll just keep this open though for tracking

@rmagatti rmagatti reopened this Sep 19, 2022
@rbmarliere
Copy link

rbmarliere commented Sep 12, 2024

For reference, you can use pre_save_cmds and post_restore_cmds to achieve that, I implemented it here.

@cameronr
Copy link
Collaborator

cameronr commented Sep 12, 2024

(accidentally deleted my earlier reply)

@rbmarliere nice solution! if you don't want to handle the file management, you could leverage the save_extra_cmds auto-session hook to automatically create a <session_file>x.vim file on save and it'll automatically source it on restore. for example, from your dotfiles, you could do this:

    save_extra_cmds = {
      function()
        local _qflist = vim.fn.getqflist()
        if #_qflist == 0 then return nil end
        local _qfinfo = vim.fn.getqflist({ title = 1 })

        for _, entry in ipairs(_qflist) do
          -- the goal is to use SaveQf across nvim instances,
          -- so use filename instead of bufnr
          entry.filename = vim.api.nvim_buf_get_name(entry.bufnr)
          entry.bufnr = nil
        end

        local _setqflist = string.format('call setqflist(%s)', vim.fn.string(_qflist))
        local _setqfinfo = string.format('call setqflist([], "a", %s)', vim.fn.string(_qfinfo))
        return { _setqflist, _setqfinfo, 'copen' }
      end,
    },

@rmagatti
Copy link
Owner

As for somehow implementing this through auto-session, it's not one of the goals of this plugin to implement its own session management separately from what Neovim has to offer, that said, one could use probably the session hooks to achieve saving and reloading the quickfix window while there isn't any upstream support for it.

I am revisiting my position on this particular feature request. While it still holds true that extending auto-session to support session features that aren't nvim-out-of-the-box-supported is still a non-goal, perhaps this could be a worthwhile exception given that quickfix would 1. be very useful 2. is a vim staple feature 3. is fairly simple to implement

@cameronr
Copy link
Collaborator

cameronr commented Dec 3, 2024

@rmagatti couple of questions:

  1. are you ok with using save_extra_cmds as shown above?
  2. assuming yes, did you want quick fix saving default on or default off? if default on, i'd make something like save_extra_cmds = { require('auto-session').save_quickfix } the default config value. if someone wants to disable, they could set save_extra_cmds = {}. if they want to add their own things to save, they'd have to make sure they also add save_quickfix when extending save_extra_cmds. if default off, then i'd just update the documentation to mention setting save_extra_cmds as above. Or did you quickfix to be part of a separate config parameter that doesn't use save_extra_cmds (but still uses the x.vim extra session file)?
  3. I'll also have to take a look at clearing / closing quickfix when switching sessions

@rbmarliere
Copy link

Ideally the history would be saved too. So that :colder etc. is usable across sessions.

@rmagatti
Copy link
Owner

Good points @cameronr.

  1. Yes, that's probably the best way to get this going.

if someone wants to disable, they could set save_extra_cmds = {}

  1. ^ yes, on by default would be good, also, save_extra_cmds = false should disable as well

Sorry about the delay here, busy couple of weeks at work!

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

4 participants