Skip to content

Beautiful code snippet images right in the most epic editor :chef_kiss:

License

Notifications You must be signed in to change notification settings

0oAstro/silicon.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

52 Commits

Repository files navigation

silicon.lua

silicon is a lua plugin for neovim to generate beautiful images of code snippet using silicon

recording.mp4

✨ Features

  • beautiful images of source code, saved to preferred place.
  • copy to clipboard

⚡️ Requirements

📦 Installation

Install the plugin with your preferred package manager:

-- Luause{"narutoxy/silicon.lua", requires={"nvim-lua/plenary.nvim" }, config=function() require('silicon').setup({}) end }
" Vim Script Plug 'nvim-lua/plenary.nvim' Plug 'narutoxy/silicon.lua'luarequire('silicon').setup({})

⚙️ Configuratioon

silicon comes with the following defaults:

{theme="auto", output="SILICON_${year}-${month}-${date}_${time}.png", -- auto generate file name based on time (absolute or relative to cwd)bgColor=vim.g.terminal_color_5, bgImage="", -- path to image, must be pngroundCorner=true, windowControls=true, lineNumber=true, font="monospace", lineOffset=1, -- from where to start line numberlinePad=2, -- padding between linespadHoriz=80, -- Horizontal paddingpadVert=100, -- vertical paddingshadowBlurRadius=10, shadowColor="#555555", shadowOffsetX=8, shadowOffsetY=8, gobble=false, -- enable lsautogobble like featuredebug=false, -- enable debug output }

🚀 Usage

Keymaps

-- Generate image of lines in a visual selectionvim.keymap.set('v', '<Leader>s', function() silicon.visualise_api({}) end ) -- Generate image of a whole buffer, with lines in a visual selection highlightedvim.keymap.set('v', '<Leader>bs', function() silicon.visualise_api({to_clip=true, show_buf=true}) end ) -- Generate visible portion of a buffervim.keymap.set('n', '<Leader>s', function() silicon.visualise_api({to_clip=true, visible=true}) end ) -- Generate current buffer line in normal modevim.keymap.set('n', '<Leader>s', function() silicon.visualise_api({to_clip=true}) end )

Command line

Calling silicon.visualise_api with lua in command line doesn't work due to lua not supporting ranges.
This means that the moment you hit enter, you leave visual mode before lua function is called. While this populates two registers, using them doesn't work with "v" mode maps.
A workaround has been implemented, and a shorthand that forces it is available as .visualise_cmdline:

  • Generate image of lines in a visual selection

    luarequire('silicon').visualise_cmdline({})
  • Generate image of a whole buffer, with lines in a visual selection highlighted

    luarequire('silicon').visualise_cmdline({to_clip=true, show_buf=true})
  • Generate visible portion of a buffer

    luarequire('silicon').visualise_cmdline({to_clip=true, visible=true})

Notes

  • The default path of image is the current working directory of the editor, but you can change it by

    require("silicon").setup({output="/home/astro/Pictures/SILICON_$year-$month-$date-$time.png"), })

Colorscheme reloading

Autogenerated silicon themes are unaware of dark/light variants. Utility functions had been exposed that allow regenerating theme on demand:

  • require("silicon.utils").build_tmTheme() builds a new tmTheme file from current colorscheme
  • require("silicon.utils").reload_silicon_cache() calls silicon --build-cache

This lets one regenerate theme when switching background setting or otherwise reloading ColorScheme:

vim.api.nvim_create_augroup('SiliconRefresh',{clear=true }) vim.api.nvim_create_autocmd({'ColorScheme' },{group='SiliconRefresh', callback=function() silicon_utils.build_tmTheme() silicon_utils.reload_silicon_cache({async=true}) end, desc='Reload silicon themes cache on colorscheme switch', } )

About

Beautiful code snippet images right in the most epic editor :chef_kiss:

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7