From f33b0cd695cc06929889dcc36db5fbf07396b3ba Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sat, 2 Apr 2022 23:37:19 -0400 Subject: [PATCH] Add lite command to unload macros --- wrap.fnl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wrap.fnl b/wrap.fnl index 17b5069..3fcbe07 100644 --- a/wrap.fnl +++ b/wrap.fnl @@ -7,22 +7,31 @@ (local keymap (require :core.keymap)) (local translate (require :core.doc.translate)) +(fn get-modname [] + (-> core.active_view.doc.filename + (: :gsub "%.%a+$" "") + (: :gsub "/" ".") + (: :gsub "^data%." "") + (: :gsub "%.init$" ""))) + (command.add "core.docview" { "fennel:eval" #(editor.inline-eval #(fv (fennel.eval $1 {:env _G :compiler-env _G}) {})) "lume:hotswap" (fn [] - (local modname - (-> core.active_view.doc.filename - (: :gsub "%.%a+$" "") - (: :gsub "/" ".") - (: :gsub "^data%." "") - (: :gsub "%.init$" ""))) + (local modname (get-modname)) (core.log (.. "Hotswapping " modname)) (local (mod err) (util.hotswap modname)) (when (not= err nil) (print err) (error err))) + "fennel:unload-macro" (fn [] + (let [modname (get-modname)] + (if (. fennel.macro-loaded modname) + (do (core.log (.. "Unloading macro module " modname)) + (tset fennel.macro-loaded modname nil)) + (core.log (.. modname " was not a loaded macro module"))))) }) (keymap.add { "alt+e" "fennel:eval" "alt+r" "lume:hotswap" + "alt+u" "fennel:unload-macro" }) {}