Edit functions from your REPL
EditCreated: 2021/1/20
Updated: 2021/1/20
So, in janet, bindings are stored in an environment (which is attached to a fiber, but more on that another day). Because Janet bindings contain a :source-map entry, you can use this to write an edit macro to allow you to open the file a function is contained in.
Feel free to add this to your profile.janet
(def EDITOR "kate")
(defmacro edit
"Won't work for everything, but should work for installed libraries"
[symb]
~(if-let [
source-map (-> (dyn (quote ,symb)) (get :source-map))
[loc line char] source-map
finfo (os/stat loc)
_is_file (= (finfo :mode) :file)
]
(os/shell (string EDITOR " " loc))
(print "Couldn't find a file to edit for " (string ,symb))
)
)