# How to trace macro'ed define to it's original location

**URL:** <https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102>\
**Category:** Questions & Answers\
**Created:** [August 16, 2024, 6:49am UTC](https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102 "2024-08-16T06:49:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zeb](https://avatars.discourse-cdn.com/v4/letter/z/57b2e6/32.png) [@Zeb](https://racket.discourse.group/u/Zeb)\
**Post date:** [August 16, 2024, 6:49am UTC](https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102/1 "2024-08-16T06:49:59Z")

</div>

If a define is introduced by a macro, how do I trace that back to it's original location? And I want is to do this in a tool analyzing a racket file where these macros exist. It won't be during compiling+running the file. I want to compile and analyze the file.

My overall goal is to use ctags with racket bc I use racket on smaller less powerful machines like old phones and small computers like SOC computers. They can barely handle a language server. I wanna make sure it captures defines introduced by macros.

I don't have anything so far, I haven't tried. I'm looking for an example of the tracing to help me start. And how would I read a file in as a syntax object? Is there like a read as syntax function?

---

<div class="post-metadata">

**Author:** ![Zeb](https://avatars.discourse-cdn.com/v4/letter/z/57b2e6/32.png) [@Zeb](https://racket.discourse.group/u/Zeb)\
**Post date:** [August 17, 2024, 9:29am UTC](https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102/2 "2024-08-17T09:29:32Z")

</div>

I started playing around with ctags and while it was more robust than I thought, it misses definitions from structs.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [August 17, 2024, 1:47pm UTC](https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102/3 "2024-08-17T13:47:58Z")

</div>

I'd been meaning to write in about [Universal Ctags](https://ctags.io), which I use personally. According to `ctags --list-maps`, it detects `*.rkt` files as Scheme.

The [current parser](https://github.com/universal-ctags/ctags/blob/f158eb88c08927445d83bc082626e011a011b2d4/parsers/scheme.c#L55) just looks for `(def` and `(set` to create tags. Handling structs is harder because of all the introduced names; a quick test shows that this (which you can place in `~/.ctags.d` somewhere) captures the struct name:

```scheme
--regex-Scheme=/\([\t]*struct[\t]+([^[:space:]]+)/\1/f,function/

```

It probably doesn't handle `|names with spaces|`. With `--mline-regex-<LANG>` you might be able to write a clever pattern to capture the struct name and fields and construct `struct-field` tags.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [August 17, 2024, 1:49pm UTC](https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102/4 "2024-08-17T13:49:17Z")

</div>

Oh, but having just the struct name is OK if you don't mind doing `:tag name` instead of C-] on `name-field`; you can also Visually select `name` for C-].

---

<div class="post-metadata">

**Author:** ![Zeb](https://avatars.discourse-cdn.com/v4/letter/z/57b2e6/32.png) [@Zeb](https://racket.discourse.group/u/Zeb)\
**Post date:** [August 17, 2024, 10:45pm UTC](https://racket.discourse.group/t/how-to-trace-macroed-define-to-its-original-location/3102/5 "2024-08-17T22:45:39Z")

</div>

Hm. Ykw, I goofed. This post ought to be titled "using ctags with racket", because ctags tricks are good answers too. However I feel like getting a list of all the names in sticking them in a ctags file is better. Like for structs I don't want to manually have to think about if function is derived and look up part of the name. And there's no automatic way to figure that out without a list of defines.

I also wonder if ctags handles define-values right.
