Olical / aniseed

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

Issues with loading macros #128

Closed shaunsingh closed 1 year ago

shaunsingh commented 2 years ago

Hi, I'm trying out aniseed again on my config, which you can see here: https://github.com/shaunsingh/nyoom.nvim/tree/aniseed-support

The macros in question are here: https://github.com/shaunsingh/nyoom.nvim/tree/aniseed-support/fnl/macros

Essentially, aniseed can recognize command-macros event-macros and all of the top-level macros just fine. However, those depend on other macros as well: these which aniseed can't find. How should I proceed with this, is this something aniseed should solve or rather is there a certain way I should name/redo those macros?

Here is the resulting error:

Error detected while processing /Users/shauryasingh/.local/share/nvim/site/pack/packer/start/aniseed/plugin/aniseed.vim:
line    3:
Compile error in /Users/shauryasingh/.config/nvim/fnl/core/commands.fnl:2
  .../shauryasingh/.config/nvim/fnl/macros/command-macros.fnl:1: module 'macros.lib.types' not found:
^Ino field package.preload['macros.lib.types']
^Ino file './share/lua/5.1/macros/lib/types.lua'
^Ino file './macros/lib/types.lua'
^Ino file './macros/lib/types/init.lua'
^Ino file './lib/lua/5.1/macros/lib/types.so'
^Ino file './macros/lib/types.so'
^Ino file './lib/lua/5.1/loadall.so'
^Ino file './lib/lua/5.1/macros.so'
^Ino file './macros.so'
^Ino file './lib/lua/5.1/loadall.so'
stack traceback:
^I[C]: in function 'require'
^I.../shauryasingh/.config/nvim/fnl/macros/command-macros.fnl:1: in function 'loader'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:1996: in function 'require-macros'
^Isrc/fennel/macros.fnl:322: in function <src/fennel/macros.fnl:317>
^I[C]: in function 'xpcall'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2634: in function 'macroexpand_2a'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2820: in function 'compile1'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:784: in function 'special'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2658: in function 'compile1'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:3054: in function 'compileString'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:50: in function <...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:49>
^I[C]: in function 'str'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:57: in function 'file'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:75: in function 'glob'
^I.../nvim/site/pack/packer/start/aniseed/lua/aniseed/env.lua:57: in function 'init'
^I[string ":lua"]:1: in main chunk
                                      ^
runtime error: module 'macros.lib.seq' not found:
^Ino field package.preload['macros.lib.seq']
^Ino file './share/lua/5.1/macros/lib/seq.lua'
^Ino file './macros/lib/seq.lua'
^Ino file './macros/lib/seq/init.lua'
^Ino file './lib/lua/5.1/macros/lib/seq.so'
^Ino file './macros/lib/seq.so'
^Ino file './lib/lua/5.1/loadall.so'
eyboard interrupt
stack traceback:
  [C]: in function 'getcwd'
  ...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:25: in function 'wrap_macros'
  ...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:50: in function ?
  [C]: in function 'str'
  ...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:57: in function 'file'
  ...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:75: in function 'glob'
  .../nvim/site/pack/packer/start/aniseed/lua/aniseed/env.lua:57: in function 'init'
  [string ":lua"]:1: in main chunk
Compile error in /Users/shauryasingh/.config/nvim/fnl/core/keybinds.fnl:2
  .../shauryasingh/.config/nvim/fnl/macros/keybind-macros.fnl:1: module 'macros.lib.types' not found:
^Ino field package.preload['macros.lib.types']
^Ino file './share/lua/5.1/macros/lib/types.lua'
^Ino file './macros/lib/types.lua'
^Ino file './macros/lib/types/init.lua'
^Ino file './lib/lua/5.1/macros/lib/types.so'
^Ino file './macros/lib/types.so'
^Ino file './lib/lua/5.1/loadall.so'
^Ino file './lib/lua/5.1/macros.so'
^Ino file './macros.so'
^Ino file './lib/lua/5.1/loadall.so'
stack traceback:
^I[C]: in function 'require'
^I.../shauryasingh/.config/nvim/fnl/macros/keybind-macros.fnl:1: in function 'loader'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:1996: in function 'require-macros'
^Isrc/fennel/macros.fnl:322: in function <src/fennel/macros.fnl:317>
^I[C]: in function 'xpcall'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2634: in function 'macroexpand_2a'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2820: in function 'compile1'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:784: in function 'special'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2658: in function 'compile1'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:3054: in function 'compileString'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:50: in function <...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:49>
^I[C]: in function 'str'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:57: in function 'file'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:75: in function 'glob'
^I.../nvim/site/pack/packer/start/aniseed/lua/aniseed/env.lua:57: in function 'init'
^I[string ":lua"]:1: in main chunk
(import-macros {: let!} :macros.variable-macros)
bangedorrunt commented 2 years ago

Related https://github.com/Olical/aniseed/issues/62

shaunsingh commented 2 years ago

I'll try putting everything under the macros/ folder, rather than some under macros/lib and some under macros/. It would be nice to have support for the later case as well though

shaunsingh commented 2 years ago

Nevermind, similar error even after doing that. I don't think https://github.com/Olical/aniseed/issues/62 was actually fixed

Error detected while processing /Users/shauryasingh/.local/share/nvim/site/pack/packer/start/aniseed/plugin/aniseed.vim:
line    3:
Compile error in /Users/shauryasingh/.config/nvim/fnl/core/commands.fnl:2
  .../shauryasingh/.config/nvim/fnl/macros/command-macros.fnl:1: module 'macros.types-macros' not found:
^Ino field package.preload['macros.types-macros']
^Ino file './share/lua/5.1/macros/types-macros.lua'
^Ino file './macros/types-macros.lua'
^Ino file './macros/types-macros/init.lua'
^Ino file './lib/lua/5.1/macros/types-macros.so'
^Ino file './macros/types-macros.so'
^Ino file './lib/lua/5.1/loadall.so'
^Ino file './lib/lua/5.1/macros.so'
^Ino file './macros.so'
^Ino file './lib/lua/5.1/loadall.so'
stack traceback:
^I[C]: in function 'require'
^I.../shauryasingh/.config/nvim/fnl/macros/command-macros.fnl:1: in function 'loader'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:1996: in function 'require-macros'
^Isrc/fennel/macros.fnl:322: in function <src/fennel/macros.fnl:317>
^I[C]: in function 'xpcall'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2634: in function 'macroexpand_2a'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2820: in function 'compile1'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:784: in function 'special'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:2658: in function 'compile1'
^I...te/pack/packer/start/aniseed/lua/aniseed/deps/fennel.lua:3054: in function 'compileString'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:50: in function <...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:49>
^I[C]: in function 'str'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:57: in function 'file'
^I...m/site/pack/packer/start/aniseed/lua/aniseed/compile.lua:75: in function 'glob'
^I.../nvim/site/pack/packer/start/aniseed/lua/aniseed/env.lua:57: in function 'init'
^I[string ":lua"]:1: in main chunk
                                      ^
runtime error: module 'macros.seq-macros' not found:
^Ino field package.preload['macros.seq-macros']
^Ino file './share/lua/5.1/macros/seq-macros.lua'
^Ino file './macros/seq-macros.lua'
^Ino file './macros/seq-macros/init.lua'
^Ino file './lib/lua/5.1/macros/seq-macros.so'
^Ino file './macros/seq-macros.so'
^Ino file './lib/lua/5.1/loadall.so'
bangedorrunt commented 2 years ago

That's why I put everything into one macros file. Hope @Olical will fix later.

Olical commented 2 years ago

I'll try and fix this for good soon, just focusing on some Conjure stuff at the moment.

shaunsingh commented 2 years ago

Loving the work on conjure, for now I just moved everything into one file and it works perfectly. Take your time, no worries

Olical commented 2 years ago

So I think this was to do with Aniseed not creating intermediate directories when copying macro files over into your compiled lua output directory. I've since fixed that and I can now refer to nested macro files!

If you can still reproduce it, please let me know. I'm trying to reproduce it still but I feel like I'm missing something. I think I've fixed one issue but there may be another lurking that I can't quite repro.

Olical commented 2 years ago

So this works, but you NEED to use import-macros, if you just require then it's going to try and load a lua module which won't work since you can't have a macro file that is compiled lua. Macros MUST always be uncompiled fnl.

If this statement is wrong and this does work in some other system please let me know! But I think the only way to load other macro files into your macro file and use them is to use import-macros etc. I've fixed the nested dirs of macros issue, so maybe that was it?

Here's a small snippet of me requiring a sub-macro file and using it. It works for me! Although not super useful, I think it's just a limitation of Fennel, you can't just infinitely require and next macros and have it resolve them all as you would in Clojure... I think. I could just be wrong!

; (local {: bad-add} (require :./misc.other-macros.fnl))
(import-macros {: bad-add} :dotfiles.misc.other-macros)

{:adder-b (fn [a b]
            `(+ 1 ,a ,b ,(bad-add 1 2)))

...
bangedorrunt commented 2 years ago

@Olical This might be in relation to https://github.com/rktjmp/hotpot.nvim/issues/76 and https://github.com/rktjmp/hotpot.nvim/issues/77

Olical commented 2 years ago

Yep! That sounds like the same problem! Which to me sounds like a Fennel usage problem? Like we need to work out patterns that work for Fennel. I don't think I can work around that limitation?

I think I've fixed aniseeds bug to do with nested dirs though!

On Thu, 25 Aug 2022, 00:03 Thanh Dung TRUONG, @.***> wrote:

@Olical https://github.com/Olical Might related to rktjmp/hotpot.nvim#76 https://github.com/rktjmp/hotpot.nvim/issues/76

— Reply to this email directly, view it on GitHub https://github.com/Olical/aniseed/issues/128#issuecomment-1226578539, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACM6XKKGA7GL66QETGSFCTV22S4VANCNFSM5522DVZA . You are receiving this because you were mentioned.Message ID: @.***>

Olical commented 2 years ago

We're now on fennel 1.2.0 on the develop branch, not sure if that helps at all...

rktjmp commented 1 year ago

edit: sorry, just assumed this issue was about cljlib because it was linked!, not the broader (require :macro) behaviour! :flushed:

(x-post from hotpot issue)

I think if you use this fork https://github.com/rktjmp/fennel-cljlib/ cljlib should now work?

The install instructions have changed since this was opened, you how have to set the package.path.

Internally it makes a direct (require :lazy-seq) call, so you must update the package path as instructed. For me that was:

(let [root (vim.fn.stdpath :config)
      path (.. root :/fnl/cljlib)]
  (set package.path (string.format "%s;%s;%s"
                                   (.. path "/?/init.lua")
;; readme doesn't say to add this one but it's idiomatic to include both the `?.lua` and `?/init.lua` paths.
                                   (.. path "/?.lua")
                                   package.path)))

(local clj (require :cljlib))
(import-macros cljm :cljlib)

(print (clj.add 1 2 3))
(cljm.time (do
  (for [i 1 10000000] i)))

I just cloned it into .config/nvim/fnl/cljlib (and got the submodules) which effectively puts it in the main cljlib package in "neovims lua package root" if you want to call it that. If you put it in some nested subdir you might have to muck around with package.path a bit more.

Hopefully the patch can be up streamed, have to check with Andre if he has opinions on the change.

https://github.com/rktjmp/fennel-cljlib/commit/8b58117962c51f72da211ea0c06e4c0aea3f74e9

(note this doesn't fix calling `(require :some-macro) inside a import-macro in aniseed/hotpot obviously, imo that behaviour is out of spec)

shaunsingh commented 1 year ago

Considering require-macros is deprecated anyways, and that aniseed works just fine with multiple macro files and import-macros, I'll consider this fixed for my own use case.