# Run a macro on all code evaluated by julia

**URL:** https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633
**Category:** General Usage
**Created:** [March 13, 2017, 4:48am UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633 "2017-03-13T04:48:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [March 13, 2017, 4:48am UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633/1 "2017-03-13T04:48:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 13, 2017, 6:26am UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633/2 "2017-03-13T06:26:00Z")

</div>

What are you trying to achieve?

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [March 13, 2017, 9:09am UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633/3 "2017-03-13T09:09:43Z")

</div>

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:

```julia
@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.)

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [March 13, 2017, 1:51pm UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633/4 "2017-03-13T13:51:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [March 13, 2017, 2:50pm UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633/5 "2017-03-13T14:50:57Z")

</div>

Said macro already exists, and inspired this thread!

---

<div class="post-metadata">

### Author: ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)
#### Post date: [March 13, 2017, 3:06pm UTC](https://discourse.julialang.org/t/run-a-macro-on-all-code-evaluated-by-julia/2633/6 "2017-03-13T15:06:04Z")

</div>

[https://github.com/JunoLab/Atom.jl/pull/79/files](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
