# How to determine where a macro is defined?

**URL:** https://discourse.julialang.org/t/how-to-determine-where-a-macro-is-defined/31637
**Category:** General Usage
**Tags:** macros, metaprogramming
**Created:** [November 28, 2019, 10:24pm UTC](https://discourse.julialang.org/t/how-to-determine-where-a-macro-is-defined/31637 "2019-11-28T22:24:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gcv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcv/32/11086_2.png) [@gcv](https://discourse.julialang.org/u/gcv)
#### Post date: [November 28, 2019, 10:24pm UTC](https://discourse.julialang.org/t/how-to-determine-where-a-macro-is-defined/31637/1 "2019-11-28T22:24:22Z")

</div>

I figured out how to find where a method is defined: `methods(generic_function).ms` returns a handy array of objects which have `file` and `line` properties.

I’m now trying to do the same thing for macros. For example, `Printf.@sprintf` — where is it defined? `methods` and `code_lowered` don’t work, since they only understand generic functions.

**Edit:** Clarification: I’m looking for a general way to find the definition of something known in the Julia environment given its name. Ideally, I’d like to use a Symbol to find it, so something like `methods(:+)` or `methods("+")` (which does not work) would be preferred to `methods(+)`.

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [November 29, 2019, 12:04am UTC](https://discourse.julialang.org/t/how-to-determine-where-a-macro-is-defined/31637/2 "2019-11-29T00:04:52Z")

</div>

You can use

```julia
julia> methods(var"@info")
# 1 method for macro "@info":
[1] @info( __source__ ::LineNumberNode, __module__ ::Module, exs...) in Base.CoreLogging at logging.jl:214

```

Or in Julia \< 1.3

```nohighlight
julia> methods(getproperty(Main, Symbol("@info")))
# 1 method for macro "@info":
[1] @info( __source__ ::LineNumberNode, __module__ ::Module, exs...) in Base.CoreLogging at logging.jl:214

```

FYI, you can also do `@search @info` with [https://github.com/tkf/InteractiveCodeSearch.jl](https://github.com/tkf/InteractiveCodeSearch.jl)

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [November 29, 2019, 12:45am UTC](https://discourse.julialang.org/t/how-to-determine-where-a-macro-is-defined/31637/3 "2019-11-29T00:45:09Z")

</div>

See also the macros `@which,@edit`

---

<div class="post-metadata">

### Author: ![gcv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcv/32/11086_2.png) [@gcv](https://discourse.julialang.org/u/gcv)
#### Post date: [November 29, 2019, 5:07pm UTC](https://discourse.julialang.org/t/how-to-determine-where-a-macro-is-defined/31637/4 "2019-11-29T17:07:33Z")

</div>

That works. Thank you!
