Olical / nfnl

Enhance your Neovim with Fennel
The Unlicense
235 stars 8 forks source link

Any way to disable compile on save? #17

Closed csy19960309 closed 1 year ago

csy19960309 commented 1 year ago

It seems that compile on save conflicts with my format on save so I wish to trigger compiling manually. How do I set up the configuration to achieve that?

Olical commented 1 year ago

Oh interesting, kinda against the ethos of the plugin but I think it can be supported fairly easily. Not possible just yet, but I'll add it for you.

What conflict are you seeing? An error every time you write a file? Would love some more context here because maybe both can be supported easily.

Olical commented 1 year ago

Hmm, do you think this config should be project by project (i.e. you set something in your .nfnl.fnl file for the project) orrr should it be an argument passed to require("nfnl").setup({...}) that works globally. I'm leaning towards global setup call since that integrates nicely with things like lazy.nvim, but I'm not sure.

Maybe it should just be a g:nfnl#compile_on_write variable like the good old days 😅

Olical commented 1 year ago

Until there's a native option (would like feedback on if that being in .nfnl.fnl or .setup() feels right first) you could delete the autocmd group which is created with (vim.api.nvim_create_augroup (.. "nfnl-dir-" root-dir) {}). (the augroup is created on fennel filetype autocmd)

That means if you're editing in /foo/bar your augroup will be called nfnl-dir-/foo/bar. You can (vim.api.nvim_del_augroup_by_id ID) that augroup to remove it after a buffer loads / before save, but it's not ideal.

Another part of this will be adding a function to compile a single file... maybe. I actually recommend you call require("nfnl")["compile-all-files"]() because that kinda just does the right thing and it exists already. If you absolutely need something more targeted I can try and work that out and add a function for it.

Olical commented 1 year ago

Alongside what error you're running into, I'd also like to know which formatter you're using / how. Like are you formatting the fennel on save? Or the Lua file? I guess the fennel and I'm interested into how that's hooked up and how that could possibly cause an issue with this other autocmd, it's pretty unobtrusive 🤔

csy19960309 commented 1 year ago

Thank you for your interest in my issue and I am sorry for my late reply! I am using a plugin elentok/format-on-save.nvim to format my fennel code with the formatter fnlfmt. I find that problems occur when there are compiling errors. When I save my code, all my later modifications are wiped if I make errors after my last saving. So a possible solution is preventing formatting if there is any compiling error. As I am learning towards lua programming, it may take me some time to adjust my config to meet my needs. Furthermore I will take some time to study your suggestions.

Olical commented 1 year ago

Have you tried repeating this without nfnl enabled? So saving a Fennel file with no nfnl but with fnlfmt? I'd like to isolate this to check if it's just the formatter behaving strangely and not nfnl. I personally can't see how nfnl could cause this behaviour since all it does is:

nfnl does not ever touch your Fennel buffer or trigger actual Lua errors that would interrupt any other Neovim processes. It's essentially just echoing / printing errors. So no other plugins or systems should be affected.

I suspect the issue lies with the formatting alone and not nfnl, so I'd like to rule that out. I could be wrong and you could've already checked this of course, I'm sorry if so. Just need to be thorough because I'd like to avoid adding options unless I absolutely need to.

Once the floodgate of configuration opens, it only gets more complex and difficult to manage + document. So the less options and the more "It Just Works" the better in my opinion.

csy19960309 commented 1 year ago

Have you tried repeating this without nfnl enabled? So saving a Fennel file with no nfnl but with fnlfmt? I'd like to isolate this to check if it's just the formatter behaving strangely and not nfnl. I personally can't see how nfnl could cause this behaviour since all it does is:

  • Read the buffer content.
  • Compile to Lua in memory.
  • Print errors if there are using the notify system (which ends up in :messages / notify popups if you have a plugin to display them like that https://github.com/rcarriga/nvim-notify)
  • Write the resulting Lua to the appropriate Lua file if it compiled okay.

nfnl does not ever touch your Fennel buffer or trigger actual Lua errors that would interrupt any other Neovim processes. It's essentially just echoing / printing errors. So no other plugins or systems should be affected.

I suspect the issue lies with the formatting alone and not nfnl, so I'd like to rule that out. I could be wrong and you could've already checked this of course, I'm sorry if so. Just need to be thorough because I'd like to avoid adding options unless I absolutely need to.

Once the floodgate of configuration opens, it only gets more complex and difficult to manage + document. So the less options and the more "It Just Works" the better in my opinion.

Thanks for the suggestions and it is found you are right -- the buffer content is rolled back because formatting fails. As I am able to undo the rolling back with U, the only unresolved problem is under the circumstance where I make compiling errors, nfnl does not print out what compiling errors are. Do you have any idea about that?

Olical commented 1 year ago

Hm, nfnl should be showing you compilation errors already, it does for me. Have you checked your :messages? It notifies you with the vim.notify system (:h vim.notify) which will go into your :messages if you don't have a UI for it installed.

Olical commented 1 year ago

It may well be sending it to messages but the window at the bottom is getting cleared by the formatter or some other plugin before you get to read it 🤔

csy19960309 commented 1 year ago

Hm, nfnl should be showing you compilation errors already, it does for me. Have you checked your :messages? It notifies you with the vim.notify system (:h vim.notify) which will go into your :messages if you don't have a UI for it installed.

:messages doesn't show me the compiling errors. I guess they are cleared by the formatting plugin indeed. As it turns out to be an issue of another plugin, should I close this issue?

Olical commented 1 year ago

Oh no, that's weird! So if you have the formatter disabled do the errors show up on file write? Would be good to rule that out.

Olical commented 1 year ago

Going to close this issue but please do re-open if you're still using this, having issues and think it's something I could help fix. Hope things are going well for you!

csy19960309 commented 1 month ago

Thanks for caring about this issue. As a tip for those who face the same issue, I finally solved it by switch my formatting plugin to https://github.com/stevearc/conform.nvim. In this way I can compile and format my code with a single save.