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

[Feature Proposal] Separate macros from normal scripts #30

Closed
alexmozaidze opened this issue Nov 22, 2023 · 3 comments
Closed

[Feature Proposal] Separate macros from normal scripts #30

alexmozaidze opened this issue Nov 22, 2023 · 3 comments

Comments

@alexmozaidze
Copy link
Contributor

Problem

Currently, in order to mark a file as a macro, you are required to suffix it with -macros.fnl, which is not ideal.

Normal script files and macro files get mixed up, ending up in a hard-to-read project structure.

Proposal

Separate normal files and macro files into fnl/ and macros/ folders respectively.

Doing so would make it easier to understand which files are to be treated as macros, and which need to be compiled into Lua.

@udayvir-singh
Copy link
Owner

udayvir-singh commented Dec 11, 2023

@alexmozaidze After some prototyping and thinking about the proposed solution, I have decided to not add a separate macros/ directory as it is a non-standard solution. However, I have added a new compiler.adviser option in tangerine's config, and you can use it to manually add the macros/ directory in macro-path option on fennel compiler:

tangerine.setup {
  compiler = {
    adviser = function(fennel)
      local dir = vim.fn.stdpath [[config]] .. "/macros"
      local path = string.format(";%s/?.fnl;%s/?/init-macros.fnl", dir, dir)

      fennel["macro-path"] = fennel["macro-path"] .. path

      return fennel
    end,
  }
}

@alexmozaidze
Copy link
Contributor Author

Works wonders, thanks! I have to wonder, is there a benefit to returning fennel in the function? One might forget to return it, so it would be nice to have the fennel be default in case function returns nil, a check as such would be nice:

(or (config.adviser fennel) fennel)

This would make the function more fool-proof.

@udayvir-singh
Copy link
Owner

@alexmozaidze I don't like adding indirection in code, so I would leave it as is. I don't expect normal users to ever touch this feature anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants