Olical / aniseed

Neovim configuration and plugins in Fennel (Lisp compiled to Lua)
https://discord.gg/wXAMr8F
The Unlicense
610 stars 28 forks source link

(lua "return") escape hatch breaks aniseed? #89

Closed Grazfather closed 2 years ago

Grazfather commented 2 years ago

I was writing a macro to try! to require and to just end the module early in case of failure.

While debugging I noticed that adding (lua "return") anywhere breaks aniseed. Even something as simple as:

(module core.init)
(lua "return")                                                                                             

This yields:

local _2afile_2a = "/Users/g/.config/nvim/fnl/core/init.fnl"
local _2amodule_name_2a = "core.init"
local _2amodule_2a
do
  package.loaded[_2amodule_name_2a] = {}
  _2amodule_2a = package.loaded[_2amodule_name_2a]
end
local _2amodule_locals_2a                                                                                                                                                                              do                                                                                                                                                                                                       _2amodule_2a["aniseed/locals"] = {}                                                                                                                                                                    _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]                                                                                                                                               end                                                                                                                                                                                                    return nil                                                                                                                                                                                             return nil

Yet I still get this error:

Error detected while processing /Users/g/.local/share/nvim/site/pack/packer/start/aniseed/plugin/aniseed.vim:
line    2:
E5108: Error executing lua [string "luaeval()"]:1: Vim(echoerr):E121: Undefined variable: vim
stack traceback:
        [C]: in function 'init'
        [string "luaeval()"]:1: in main chunk
Press ENTER or type command to continue
Olical commented 2 years ago

Hm, I've never used this before, I've never used the Lua escape hatch for anything as I see it as something that should only be used if there is absolutely no other way of doing something. Is there any way you can implement your control flow without a return? I've never had to use one despite all of the Fennel I've worked with.

If there's absolutely no other way I can take a deeper look but I am not surprised that something like this causes issues really, I'd just highly recommend never ever leaning on that and encoding all of your control flow in Fennel. Which may mean a recursive call with a base case to exit at some point. Or even a Lua while loop?

Grazfather commented 2 years ago

Yeah it can certainly be done without, but basically (for my use) it would mean everything that can only be done with a plugin installed would have to be nested within the sexp that tries to import it.

I was basically trying to

treesitter.fnl

(module stuff)

; This will return from the module if treesitter can't be imported.
(try-or-die-require {: :treesitter})

(treesitter.setup {...})

I can do something like

(module stuff)

(with-require {: :treesitter}
  (treesitter.setup {...}))

I just wanted to avoid, and still thought it was worth reporting that something as simple as (lua "return") breaks.

Feel free to close if you don't care to investigate or support (lua ...) stuff.

harrygallagher4 commented 2 years ago

FWIW (lua "return") at the top level of a file gives bad output even without aniseed.

(require "fennel.view")
(lua "return")

gives you:

require("fennel.view")
return
return nil

which will give you an error if you try to run it

Grazfather commented 2 years ago

Ah! I don't know lua well. Apparently lua doesn't like more than one return statement at the top level of a module.

Maybe it just manifests in a weird way with aniseed.

Olical commented 2 years ago

Going to close this issue since I don't really plan on doing anything about this (I also don't know what I could do 😬 ) I hope that's okay!

Grazfather commented 2 years ago

No sweat.