Olical / nfnl

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

Cannot find macros from local repo #28

Closed katawful closed 11 months ago

katawful commented 11 months ago

I'm starting to rewrite my config with nfnl, and I have a repo of macros (here) that I want so use from my local git repo of it. I have added the package to my runtime, and also installed with lazy.nvim afterwards, but nfnl just can't find them:

;init.fnl
(comment "Create necessary paths")
(local lazy-path (.. (vim.fn.stdpath :data) :/lazy/lazy.nvim))
(local package-path (.. (vim.fn.stdpath :data) :/lazy))
(local config-name :nvim-new)
(local nfnl-path (.. vim.env.HOME :/.config/ config-name :/.nfnl.fnl))
(local macros-repo (.. vim.env.HOME "/Repos/NEOVIM/nvim-anisole-macros"))

(comment "Install lazy for later. This is the recommended install method, not fennel specific")
(fn lazy-install []
  (when (not (vim.loop.fs_stat lazy-path))
    (vim.fn.system [:git
                    :clone
                    "--filter=blob:none"
                    :--single-branch
                    "https://github.com/folke/lazy.nvim.git"
                    lazy-path])))

(comment "Allow installation of bootstrapping plugins
      Macros and nfnl for compilation are installed this way")
(fn ensure [repo package dir]
 (if (not dir)
     (do
       (vim.fn.system [:git
                       :clone
                       "--filter=blob:none"
                       :--single-branch
                       (.. "https://github.com/" repo :.git)
                       (.. package-path "/" package)])
       (vim.opt.runtimepath:prepend (.. package-path "/" package)))
     (let [install-path (string.format "%s/%s" package-path
                         package)]
       (vim.fn.system (string.format "rm -r %s" install-path))
       (vim.fn.system (string.format "ln -s %s %s" repo
                       package-path))
       (vim.opt.runtimepath:prepend install-path))))

(comment "nfnl requires a config file to work, simply add that")
(fn nfnl-config []
  (when (not (vim.loop.fs_stat nfnl-path))
    (vim.fn.system (.. "touch " nfnl-path))
    (vim.fn.system (.. "bash -c 'echo \"{}\" >> " nfnl-path "'"))))

(comment "Run bootstrapping process")
(lazy-install)
(ensure macros-repo :nvim-anisole-macros true)
(ensure :Olical/nfnl :nfnl)
(nfnl-config)
(vim.opt.runtimepath:prepend lazy-path)
((. (require "lazy") :setup) :plugins)
Error detected while processing BufWritePost Autocommands for "<buffer=1>":                                                                               
/home/kat/.config/nvim-new/fnl/globals/options.fnl:1:0 Compile error: unknown:376:? Compile error: nvim-anisole.macros.options module not found.          

^[[7m(import-macros option :nvim-anisole.macros.options)^[[0m

File I am compiling:

(import-macros option :nvim-anisole.macros.options)
(option.set {mouse :nvi
             number true
             relativenumber true
             modeline true
             undofile true
             virtualedit "block"
             hidden false
             updatetime 100
             cmdheight 2
             title true})

.nfnl.fnl

{:fennel-macro-path "./?.fnl;./?/init-macros.fnl;./?/init.fnl;./fnl/?.fnl;./fnl/?/init-macros.fnl;./fnl/?/init.fnl;./fnl/?/macros/?.fnl"}
Olical commented 11 months ago

Your macro path is all relative, so it's all using ./ and is only looking in the CWD. You'll need to add relative or absolute paths that point to your other directory.

When setting :fennel-macro-path in the .nfnl.fnl file you're overriding the default (which you can access by requiring nfnl.config and calling the default function in there). The default behaviour is actually mapping items from your run time path (list of plugin dirs) into the fennel module and macro search paths for you.

https://github.com/Olical/nfnl/blob/cff757857c1bc95769af2016762061269b7290b6/fnl/nfnl/config.fnl#L68-L94

So setting this might help:

(local core (require :nfnl.core)
(local config (require :nfnl.config))
(local default (config.default {})

{:rtp-patterns (core.concat default.rtp-patterns ["/nvim-anisole-macros$"])}

Which should then include your other plugin in the Fennel + Neovim RTP integration. It's an allowlist based on Lua patterns so you could just set the list to [".*"] to add ALL of your plugin dirs to your Fennel search paths, it just might slow things down.

This doesn't allow you to add custom dirs within each of the RTP dirs though, like your /macros dir, that's non standard so nfnl doesn't add that to the path for you. You'd have to append to the path yourself somehow I think.

The gist of this though is that you should add your plugin to the allow list and then it should be integrated into the path automatically with the normal set of paths.

Olical commented 11 months ago

The confusing thing here is that Aniseed added your WHOLE runtimepath into the Fennel search paths by default and gave you no power over what is added. Now I keep that list smaller to keep things efficient and let you opt into making it more inclusive where required. This should help remove any chance of accidental module naming clashes across plugins etc.

katawful commented 11 months ago
(local core (require :nfnl.core))
(local config (require :nfnl.config))
(local fs (require :nfnl.fs))
(local default (config.default {}))

{:rtp-patterns (core.concat default.rtp-patterns ["/nvim-anisole-macros$"])
 :fennel-macro-path (.. default.fennel-macro-path ";" vim.env.HOME "/Repos/NEOVIM/nvim-anisole-macros/fnl/nvim-anisole/macros/?.fnl;")}

i can't seem to find a way to get it to compile still (i added in the :fennel-macro-path call after what you suggested didn't work)

katawful commented 11 months ago

I think I found a way to add the macros to the path appropiately:

(local core (require :nfnl.core))
(local config (require :nfnl.config))
(local fs (require :nfnl.fs))
(local default (config.default {}))
(tset default :rtp-patterns [(.. (fs.path-sep) "nfnl$")])

(tset default :rtp-patterns (core.concat default.rtp-patterns ["/nvim-anisole-macros$"]))
(tset default :fennel-macro-path (.. default.fennel-macro-path ";" vim.env.HOME "/Repos/NEOVIM/nvim-anisole-macros/fnl/?.fnl"))
(tset default :compiler-options {:compilerEnv _G})

default

It lets me add the macros i need with (import-macros sym nvim-anisole.macros.the_macro)

Olical commented 11 months ago

Ah! Sorry I gave you the wrong code, the way to generate the default config with more runtimepath directories included is with this:

(local config (require :nfnl.config))

(config.default {:rtp-patterns ["/nfnl$" "/nvim-anisole-macros$"]})

With that config.default call returning your new config and that is returned from you .nfnl.fnl file. Sorry I didn't test what I sent you before because I was travelling, I've actually checked this one.

The difference is rtp-patterns are an option provided to config.default, they are not in themselves a config value, they're an option used when building the default table.

Olical commented 11 months ago

I'm glad you found a solution, but yeah, rtp-patterns is an input to the function, not a part of the config itself. I was misremembering and didn't take the time to check, sorry for misleading.

Olical commented 11 months ago

I'm updating the readme on this.