michaelrommel / nvim-silicon

neovim plugin to create code images using the external silicon tool.
MIT License
118 stars 9 forks source link

Cannot capture the image twice #20

Closed Retaehc-pop closed 1 month ago

Retaehc-pop commented 1 month ago

After i use the silicon command to capture the code in nvim i cannot use the command in the second time with the error

[error] Failed to save image to v:true: The image format could not be determined

here is my setup in lazyvim

return {
  {
    "michaelrommel/nvim-silicon",
    lazy = true,
    cmd = "Silicon",
    main = "nvim-silicon",
    opts = {
      disable_defaults = true,
    },
    init = function()
      local wk = require("which-key")
      wk.add({
        { "<leader>sc", ":Silicon<CR>", desc = "Snapshot Code", mode = "v" },
      })
    end,
    config = function()
      require("nvim-silicon").setup({
        background = "#eeeeee",
        theme = "Monokai Extended Light",
        font = "Hack Nerd Font Mono=20;Noto Color Emoji=20",
      })
    end,
  },
}

the problem resolve itself when i reopen nvim.

ps. i also tried to use it in nvchad but same result arise.

michaelrommel commented 1 month ago

Hi Papop,

thanks for reporting. Indeed I needed to wrap the M.start call in another call that makes a deep copy of the global options table. Should now be fixed in the latest release. One note, though:

Above in your initialization code you supply an opts = { ... } table as well as a config function, that calls setup() with another opts table. I believe - depending on your package manager inside your lazyvim installation - that this will not work and the disable_defaults will be discarded. So I suggest, that you move that disable_defaults to the setup function, right before the background setting. But another caveat: if you do so and disable_defaults takes effect, then you are missing an output function or a to_clipboard directive. If both are missing and defaults disabled, nothing will be produced.

Take a shot at the updated version and report if that fixes your issue!

Thanks,

Michael.

michaelrommel commented 1 month ago

After i use the silicon command to capture the code in nvim i cannot use the command in the second time with the error

Hi @Retaehc-pop, did you have the chance to test the new version?

FireDrop6000 commented 1 month ago

I get the same error. Upon taking a second screenshot, I am hit with filetype not supported error and the error that has been specified above. I am running the latest version, and this is my plugin code:

{
    "michaelrommel/nvim-silicon",
    lazy = true,
    cmd = "Silicon",
    -- init = function()
    --   local wk = require "which-key"
    --   wk.register({
    --     ["<leader>sc"] = { ":Silicon<CR>", "Snapshot Code" },
    --   }, { mode = "v" })
    -- end,
    config = function()
      require("silicon").setup {
        font = "FiraCode Nerd Font=34;Noto Color Emoji=34",
        theme = "Material-Darker",
        background = "#FAFAFA",
        window_title = function()
          return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), ":t")
        end,
        -- language = function()
        --   return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), ":e")
        -- end,
      }
    end,
  },``
michaelrommel commented 1 month ago

@Retaehc-pop @FireDrop6000: Oh heaven, I was pushing to the wrong branch. Now I have merged it and it should be fixed now. Big apologies! Could you try again - Lazy should show the hash as: 0b31fc6

FireDrop6000 commented 1 month ago

@michaelrommel thank you very much sir, its working perfectly for me after update. IMG-20240730-WA0006.png

Retaehc-pop commented 1 month ago

Works on my machine. Thank you for the update, really appreciate it 👍🏻