michaelrommel / nvim-silicon

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

Is it possible pass some options when using command :Silicon just like vim-silicon #17

Closed JiuRanYa closed 1 month ago

JiuRanYa commented 2 months ago

Just like this

:Silicon --language=js

Pass some options when code higlighting not work;

By the way, awasome plugin for me!

michaelrommel commented 2 months ago

Thanks for the suggestion, I will look into it!

michaelrommel commented 2 months ago

Hello JiuRan,

I had a look into it, generally it is possible, but I still wonder about the underlying use cases. If you just want to supply a different language for a buffer, where the autodetect fails for some reason, you could just use a lua function, that asks the user in case the buffer has certain properties. For instance I use this function with good success:

language = function()
    if vim.bo.filetype == nil or vim.bo.filetype == "" then
        local lang = vim.fn.input("Language: ", "js")
        if lang and lang ~= "" then
            return lang
        else
            return "md"
        end
    else
        return vim.bo.filetype
    end
end,

Do you have other use cases in mind that cannot be fulfilled without commandline arguments? Would love to hear from you!

Michael.

JiuRanYa commented 2 months ago

@michaelrommel Sorry about replying now and @.

Sometimes, I don't want to using file type highlighting.

Eg this file example.vue:

<template></template>

<script lang="ts" setup>
const a: number = 1
</script>

As you can see, there is typescript code in script tag; Now i want to silicon this code, default it's using .vue highlight by vim.bo.filetype

Actually, if I can pass some options, I would able to :silicon language=ts.

It's better for passing some options not only language cause it's complex for Imagine the user's usage scenario.

michaelrommel commented 2 months ago

@JiuRanYa thank you very much for the explanation. I understand now the use case. Why I am hesitating is, that I have no good way to parse those arguments properly. If I just take them verbatim without parsing, they would conflict with other default arguments and the command would fail. So I would need to understand exactly which arguments they override and delete those from the constructed command line. It would make the code more complex and testing it would be harder and harder.

language = function()
    local lang = nil
    if vim.bo.filetype == nil or vim.bo.filetype == "" then
        -- if we cannot determine the filetype supply no default argument
        lang = vim.fn.input("Language: ", "")
    else
        -- otherwise have the filetype as preset for most cases
        lang = vim.fn.input("Language: ", vim.bo.filetype)
    end
    if lang and lang ~= "" then
        return lang
    else
        -- dialog was cancelled
        return "md"
    end
end,

Could you try this in your plugin setup? This would always prompt you for a language with the filetype as default (but you could change that as well). In your case you can just press backspace three times, type ts and return. This is six keystrokes.

Or you can press Ctrl-f o ts which is 5 keystrokes. Which is a lot less than if you had to type out the command line arguments yourself.

At the moment the code checks for function()s only for "language", "output", "window_title" and "line_offset", so if there are other options, where you would like to have such an input function, let me know.

Can you give it a try, please? I am really trying to keep the code and tests maintainable.

Thanks a lot!

Michael.

JiuRanYa commented 2 months ago

Thanks fro your reply. I'll try later.

michaelrommel commented 1 month ago

Hi,

I am now using the above mentioned language functions myself on a daily basis and found that this would cover probably most people's need. Feel free to comment in the newly created discussion of release v1.0.0 if you are unhappy with my decision!

Also as I said: please raise an issue, if you need further options to accept lua functions instead of strings/booleans/numbers. I am happy to amend that if needed!

Thanks for your suggestions and the constructive discussion!

Michael.