Run a macro on all code evaluated by julia

Let’s say I have a function that transforms julia code, and I want to prerun it on any code ever evaluated by Julia. Is there a way to do this? If not, it seems like a great way to customize the Julia experience

1 Like

What are you trying to achieve?

You could very easily create a macro @c so that any command prefixed with those two characters is subject to your customization. Apply this to an entire module with:

@c module my_module
lots of
customized 
code
end

I don’t think most people would want to have a 100% transparent way of altering how julia works. Programmers like to be able to look at a piece of code and know what it does. Having to add at least two characters when you want your code parsed in your own fashion is a small price to pay for that. (The reason why macros calls are prefixed with the @ character is to warn the reader to expect the unexpected.)

1 Like

This would not be terribly hard to insert into the REPL code. It’s a bit strange though. It would, of course, only be useful for syntactic transformations, but I can imagine using it, e.g., for backwards compatibility support.

Said macro already exists, and inspired this thread!

https://github.com/JunoLab/Atom.jl/pull/79/files

I’m sure something similar could be done for the REPL but this is good enough for me rn