0

As title. I have to use some colorscheme to make my reading experience better on certain filetype. I have made an auto session plugin myself but I don't know how to store the colorscheme info I'm currently on into it. Is there any native way for doing so?

My trying: The following are the only two lines that might be related to what will be stored into the session:

vim.opt.ssop:append({ 'localoptions', 'globals' })
vim.opt.ssop:remove({ 'buffers' })

As I assumed colorscheme is some global variable. But by grepping inside the session file created, I didn't find any string colorscheme.

Might not be related, but I'm using NeoVim.

4
  • @romainl: I have checked :h ssop before, but I'm not sure about which one is related to colorscheme. I have updated my question. Commented Jan 4, 2023 at 15:27
  • Oops, it seems that :h ssop doesn't help with this problem. I don't think other options that I haven't appended are related to colorscheme. Maybe you should try your attempt before answering people's questions. Commented Jan 4, 2023 at 15:39
  • Comment != answer. Also I wanted to make sure you did due diligence before asking your question.
    – romainl
    Commented Jan 4, 2023 at 15:45
  • 1
    The edits seem to have clarified the question. @romainl asking for clarification and pointing to resources are fine, but please avoid any condescension or suggestion that the OP cannot read… that is quite rude. (Perhaps "Do you need help interpreting these help documents" is better?)
    – D. Ben Knoble
    Commented Jan 4, 2023 at 21:07

1 Answer 1

0

So, I just made a post on another forum and got some practical advice there, and finally achieved the feature I want and added it to my plugin. Here is how I did that:

  1. Let me quote a part of the advice first:

    I use a session manager known as possession. Possession lets me saves the session data in a json file and allows me to save custom data as well. It also provides hooks to [...]

  2. So here is a part of my implementation: (For simplicity, only posting write process here)

    1. These are some utils to abstract the json-write process:
    local function write_to_project_json(data)
      if type(data) ~= 'table' then return false end
      local fp = io.open(get_project_json_path(), 'w+')
      if not fp then return false end
      fp:write(vim.json.encode(data))
      fp:close()
      return true
    end
    
    1. Then you can do something like this:
    -- store data
    local succeed, data = get_or_create_project_file_data()
    if succeed and type(data) == 'table' then
      data.colors_name = vim.g.colors_name
      write_to_project_json(data)
    end
    
1
  • Really impressive (for me)
    – gildux
    Commented Jan 27, 2023 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.