acksld / nvim-femaco.lua Goto Github PK
View Code? Open in Web Editor NEWCatalyze your Fenced Markdown Code-block editing!
Catalyze your Fenced Markdown Code-block editing!
I'm trying to create a language specific settings for FeMaco
and rust
. So far I got this working, but it seems pretty hacky. Is there a better, idiomatic way to configure language specific behavior in FeMaco
?
I have also thought about creating a user command
, but this was easier.
require('femaco').setup({
-- return filetype to use for a given lang
-- lang can be nil
ft_from_lang = function(lang)
Language = lang
return lang
end,
-- what to do after opening the float
post_open_float = function(winnr)
if Language == "rust" then
require('rust-tools.standalone').start_standalone_client()
end
end
})
Hello AcksID, thanks for writing such a cool plugin. I think it paves the way for a feature I see (in due time) being in the neovim ecosystem: fully supported injection LSP seamlessly integrated with code editing.
I have two questions for now:
Thanks for your work!
Hello!
This plugin looks nice & simple 👍
Have you considered making it work in all files (not just markdown), to support any language block injected in a base language using treesitter ?
I use default configure with setup, but will cause error:
Error executing Lua callback: /usr/share/nvim/runtime/lua/vim/treesitter.lua:189: attempt to index local 'node_or_range' (a nil value)
stack traceback:
/usr/share/nvim/runtime/lua/vim/treesitter.lua:189: in function 'get_match_range'
...ocal/share/nvim/lazy/nvim-FeMaco.lua/lua/femaco/edit.lua:84: in function 'get_match_at_cursor'
...ocal/share/nvim/lazy/nvim-FeMaco.lua/lua/femaco/edit.lua:156: in function 'edit_code_block'
...ocal/share/nvim/lazy/nvim-FeMaco.lua/lua/femaco/init.lua:12: in function <...ocal/share/nvim/lazy/nvim-FeMaco.lua/lua/femaco/init.lua:12>
I can confirm:
Hi there,
at the moment in order to change border configuration user has to provide all of the other required keys in table returned from float_opts
. It would be better user experience if returned table got merged with default one so only keys that user wants changing would have to be supplied. At the moment users might want to keep an eye on internal implementation and maintain its copy within their configurations.
Thanks for great plugin!
Hey there! This is a really cool plugin. Thank you for sharing it!
When I try to use it by running :FeMaco
with the cursor in a code block, I get this error:
Error executing Lua callback: ...te/pack/packer/start/nvim-FeMaco.lua/lua/femaco/edit.lua:33: attempt to call field 'get_node
_range' (a nil value)
stack traceback:
...te/pack/packer/start/nvim-FeMaco.lua/lua/femaco/edit.lua:33: in function 'get_match_range'
...te/pack/packer/start/nvim-FeMaco.lua/lua/femaco/edit.lua:79: in function 'get_match_at_cursor'
...te/pack/packer/start/nvim-FeMaco.lua/lua/femaco/edit.lua:139: in function 'edit_code_block'
...te/pack/packer/start/nvim-FeMaco.lua/lua/femaco/init.lua:10: in function <...te/pack/packer/start/nvim-FeMaco.lua/
lua/femaco/init.lua:10>
I'm on neovim v0.7.2 on Linux. I used Packer to install the plugin as shown in the README, and I do have treesitter set up.
Any idea what's going wrong? Happy to provide additional info and help troubleshoot however I can.
Thanks for this plugin.
I have a slight issue with Femaco, when I use FeMaco to edit inline code block in a floating window, the formatter tool don't be affected by config (e.g., .stylua.tomal
for stylua). I realized that FeMaco create temp file use os.tmpname()
default, which return /temp/lua_xxxx
, it is out of source folder.
So I add customize post_open_float
and create_tmp_filepath
for the purpose of creating tempfile in source folder
local function femaco()
local cache_filename
require("femaco").setup({
post_open_float = function(winnr)
print(string.format("post_open_float: %s", winnr))
vim.api.nvim_create_autocmd("WinClosed", {
pattern = "*",
callback = function()
local closed_win = vim.fn.expand("<amatch>")
if tonumber(closed_win)== winnr then
print(string.format("remove temp file %s", cache_filename))
vim.loop.fs_unlink(cache_filename)
end
end,
})
end,
create_tmp_filepath = function(filetype)
cache_filename = string.format("%s/.femaco_%d_%s", vim.fn.getcwd(), math.random(100, 999), filetype)
return cache_filename
end,
})
end
everything works perfect until I open multiple FeMaco floating windows to edit different code blocks. the cache_filename
will be override, so some tempfile will not be clean right.
could FeMaco
add ability to cleanup temp file?
Refer to null-ls.nvim
, which need tempfile to format file sameily
I have just installed your plugin, so I am not very familiar with the code yet, but I had to change edit.lua:parse_match()
to use match._lang
instead of match.language
for the floating window to get the correct file type. I see for other types of documents they still use @language
, so maybe parse_match()
needs to account for that?
Thanks!
Hi there, really cool plugin! I love your idea of using floating windows.
I have been trying to implement code completion, dignostics and the likes for https://github.com/quarto-dev/quarto-nvim, the neovim plugin for quarto (plain text computational notebooks for R / python / julia / java script which you can render to any output format, such as presentations, websites, pdfs etc.).
Would you be open to contributions to increase interoperability between the plugins? For example, one feature I would love to port to your plugin is the ability to use the same buffer / temporary file for all code chunks of the same language within one document.
This would mean, that e.g.
```{python}
def hello():
print('hello')
```
```{python}
hello()
```
I have a function to create a hidden buffer (coupled to a file) with the language content of a file (via treesitter), that can be synchronized to the source document and shares line numbers because the non-language lines are simply set to empty lines: https://github.com/quarto-dev/quarto-nvim/blob/ab3995baa8e975718ba7023451b7a2a308a876e2/lua/quarto/init.lua#L134-L163
My struggle was with showing things from this hidden buffer in the main source document, but I think your idea solves this very elegantly!
Install using Lazy.nvim
as follow:
{'AckslD/nvim-FeMaco.lua', config = function()
require("femaco").setup{}
end, lazy = false},
Neovim version: 0.9.4
Hi @AckslD,
Really cool plugin 🚀 . I saw the initial announcement and someone suggested this idea which seemed really cool, but didn't raise an issue for it, so I thought I would to see what your thoughts are on it. I think it would be a really nice workflow/UI if rather than a floating window with a border the window overlaid the code block (if possible, could just be beneath if it is not multiline), and using virtual lines it expanded the buffer, so you could edit it as though it were part of the buffer.
I'm not sure if there are complex edge cases to consider here, but thought I'd raise it officially
Dimming main buffer when you're editing the code block in FeMaco will really help to focus on the code.
Something similar to what's called "overlay" in this plugin.
Hello, this plugin is great! However, I was wondering if there was an option to open the code in a separate buffer or split instead of a floating window, or if there were any plans to implement this feature.
org_indent_mode
to indent
ggVG=
):wq
command to write and replace prev src block#+title: Org FeMaco Indentation Repro
* Heading 1
** Heading 2
#+begin_src fennel
(let [x 5]
(+ x 2)) ;; Purposefully incorrectly indented
#+end_src
The indentation level after saving the FeMaco buffer should respect the original org-mode src block indentation
* Heading 1
** Heading 2
#+begin_src fennel
(let [x 5]
(+ x 2)) ;; Now correctly indented
#+end_src
The indentation level does not reflect the org-mode src block indentation:
* Heading 1
** Heading 2
#+begin_src fennel
(let [x 5]
(+ x 2)) ;; Now worse than before :(
#+end_src
org_indent_mode
to noindent
First of all thanks for this plugin, is a great idea.
My problem: when I edit a code block with require('femaco.edit').edit_code_block()
[1] the floating buffer recognizes the filetype (syntax highlighting works for example) but the LSP integration (nvim official) is not usable, depending on your configuraiton. For example, if normally errors will be shown in the gutter it won't be visible as there are no line numbers. Same thing with errors/warnings indicators in the status line or the quickfix (it's open in the buffer behing the floating one).
For example, I'd like to enable virtual text or underline to show errors but only in the floating buffer and disable some stuff.
It's possible to detect a "FeMaco" buffer when LSP attachs to it?
Thanks!
[1] the command FeMaco
does not exist for some reason, running neovim 0.8
Trying to use this with https://github.com/nvim-neorg/neorg
The good news is using :FeMaco
does work and displays the float with the code, and I think it's highlighted correctly.
The bad news if I invoke some form of :wq
after adding some lines, it replaces the @end
tag with the new line.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.