aboutsummaryrefslogtreecommitdiffstats
path: root/home-manager/soispha
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-08-25 23:05:19 +0200
committerSoispha <soispha@vhack.eu>2023-08-25 23:05:19 +0200
commit79c9e4213a2bd69f82df777ba18ed6142d9d58c2 (patch)
tree6d4032015ff9b8625f2351dabb99dcf507193e7c /home-manager/soispha
parentFix(flake/packages): Make it obvious that 'vim' is actually 'nvim' (diff)
downloadnixos-config-79c9e4213a2bd69f82df777ba18ed6142d9d58c2.zip
Feat(hm/conf/neovim/plugins/femaco): Init
Diffstat (limited to 'home-manager/soispha')
-rw-r--r--home-manager/soispha/config/neovim/nixvim/plugins/femaco/default.nix24
-rw-r--r--home-manager/soispha/config/neovim/nixvim/plugins/femaco/lua/femaco.lua49
2 files changed, 73 insertions, 0 deletions
diff --git a/home-manager/soispha/config/neovim/nixvim/plugins/femaco/default.nix b/home-manager/soispha/config/neovim/nixvim/plugins/femaco/default.nix
new file mode 100644
index 00000000..7e641da4
--- /dev/null
+++ b/home-manager/soispha/config/neovim/nixvim/plugins/femaco/default.nix
@@ -0,0 +1,24 @@
+{
+ pkgs,
+ lib,
+ ...
+}: {
+ programs.nixvim = {
+ # TODO package femaco though a module
+ extraConfigLuaPost = ''
+ ${lib.strings.fileContents ./lua/femaco.lua}
+ '';
+ extraPlugins = [
+ pkgs.vimPlugins.nvim-FeMaco-lua
+ ];
+ maps = {
+ normal = {
+ "<leader>cc" = {
+ action = "require('femaco.edit').edit_code_block()";
+ lua = true;
+ desc = "edit a [c]ode blo[c]k with femaco";
+ };
+ };
+ };
+ };
+}
diff --git a/home-manager/soispha/config/neovim/nixvim/plugins/femaco/lua/femaco.lua b/home-manager/soispha/config/neovim/nixvim/plugins/femaco/lua/femaco.lua
new file mode 100644
index 00000000..42ec73c1
--- /dev/null
+++ b/home-manager/soispha/config/neovim/nixvim/plugins/femaco/lua/femaco.lua
@@ -0,0 +1,49 @@
+require('femaco').setup({
+ -- should prepare a new buffer and return the winid
+ -- by default opens a floating window
+ -- provide a different callback to change this behaviour
+ -- @param opts: the return value from float_opts
+ prepare_buffer = function(opts)
+ local buf = vim.api.nvim_create_buf(false, false)
+ return vim.api.nvim_open_win(buf, true, opts)
+ end,
+ -- should return options passed to nvim_open_win
+ -- @param code_block: data about the code-block with the keys
+ -- * range
+ -- * lines
+ -- * lang
+ float_opts = function(code_block)
+ return {
+ relative = 'cursor',
+ width = clip_val(5, 120, vim.api.nvim_win_get_width(0) - 10), -- TODO how to offset sign column etc?
+ height = clip_val(5, #code_block.lines, vim.api.nvim_win_get_height(0) - 6),
+ anchor = 'NW',
+ row = 0,
+ col = 0,
+ style = 'minimal',
+ border = 'rounded',
+ zindex = 1,
+ }
+ end,
+ -- return filetype to use for a given lang
+ -- lang can be nil
+ ft_from_lang = function(lang)
+ return lang
+ end,
+ -- what to do after opening the float
+ post_open_float = function(winnr)
+ vim.wo.signcolumn = 'no'
+ end,
+ -- create the path to a temporary file
+ create_tmp_filepath = function(filetype)
+ return os.tmpname()
+ end,
+ -- if a newline should always be used, useful for multiline injections
+ -- which separators needs to be on separate lines such as markdown, neorg etc
+ -- @param base_filetype: The filetype which FeMaco is called from, not the
+ -- filetype of the injected language (this is the current buffer so you can
+ -- get it from vim.bo.filetyp).
+ ensure_newline = function(base_filetype)
+ return false
+ end,
+})