Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with loading macros #128

Closed
shaunsingh opened this issue Aug 7, 2022 · 13 comments
Closed

Issues with loading macros #128

shaunsingh opened this issue Aug 7, 2022 · 13 comments
Labels
bug Something isn't working

Comments

@shaunsingh
Copy link

shaunsingh commented Aug 7, 2022

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
Copy link

Related #62

@shaunsingh
Copy link
Author

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
Copy link
Author

Nevermind, similar error even after doing that. I don't think #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
Copy link

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

@Olical
Copy link
Owner

Olical commented Aug 14, 2022

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

@shaunsingh
Copy link
Author

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

@Olical
Copy link
Owner

Olical commented Aug 24, 2022

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
Copy link
Owner

Olical commented Aug 24, 2022

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
Copy link

bangedorrunt commented Aug 24, 2022

@Olical
This might be in relation to
rktjmp/hotpot.nvim#76
and
rktjmp/hotpot.nvim#77

@Olical
Copy link
Owner

Olical commented Aug 24, 2022 via email

@Olical
Copy link
Owner

Olical commented Sep 17, 2022

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

@Olical Olical added the bug Something isn't working label Sep 17, 2022
@rktjmp
Copy link

rktjmp commented Nov 11, 2022

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

(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.

rktjmp/fennel-cljlib@8b58117

(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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants