# Navigation through (top-level) definitions in DrRacket

**URL:** <https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807>\
**Category:** Questions & Answers\
**Created:** [March 19, 2024, 11:18am UTC](https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807 "2024-03-19T11:18:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yossarian](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yossarian](https://racket.discourse.group/u/yossarian)\
**Post date:** [March 19, 2024, 11:18am UTC](https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807/1 "2024-03-19T11:18:17Z")

</div>

Hi,

As a new user of (Dr)Racket I really miss a keyboard-based way to navigate through the different definitions of a .rkt file. I often forgot the name (or the existence) of a function that I have written before, and getting a quick overview of the defined functions/variables would be very handy.

In DrRacket there is a a button in the toolbar which enables to click on it and show all definitions, but this is not ideal: how to make a keyboard shortcut for it, and could the nested definitions (the defines in another define) be hidden?

---

<div class="post-metadata">

**Author:** ![yossarian](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yossarian](https://racket.discourse.group/u/yossarian)\
**Post date:** [March 22, 2024, 8:14am UTC](https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807/2 "2024-03-22T08:14:46Z")

</div>

For those who are interested: I found a reasonably good solution using quickscript (which seems to be the drracket scripting framework): the quickscript-competition-2020 package of quickscripts contains a script "defines" which provides exacly that ("List, search, and go to the top level definitions").

In combination with the quickscript for the command pallette from [Quickscript Scripts for DrRacket · racket/racket Wiki · GitHub](https://github.com/racket/racket/wiki/Quickscript-Scripts-for-DrRacket), and some keybindings, you can let drracket behave a bit like VS Code or Sublime regarding looking for commands or symbols/definitions.

---

<div class="post-metadata">

**Author:** ![yossarian](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yossarian](https://racket.discourse.group/u/yossarian)\
**Post date:** [March 29, 2024, 3:25pm UTC](https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807/3 "2024-03-29T15:25:55Z")

</div>

I am further looking into similar solutions for emacs (new user as well): how to get a list of top-level definitions?

Given the code from the referred drracket script (line 15-41 of the [script](https://github.com/Quickscript-Competiton/July2020entries/blob/master/scripts/defines.rkt)), it should be possible to make a script/extension in emacs such that it shows up as a search menu on the bottom part of the emacs windows.

Could someone give me a hint on how to do this as an extension in emacs ? [Racket-mode](https://racket-mode.com) does not seem to have such an obvious? overview of definitions?

---

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [April 16, 2024, 8:34pm UTC](https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807/4 "2024-04-16T20:34:16Z")

</div>

The regex could probably be improved, but this should be a good starting point:

```scheme
(defun my-racket-show-definitions ()
  "Show all definitions in the current buffer.

This includes functions, variables, constants, etc."
  (interactive)
  (occur "\\(^\s*(define\\|^(struct\\)"))

```

And of course, bind that to whatever keybinding you like. I use a Racket-specific menu (Hydra). If you'd like to see an example, here's [my Racket config](https://github.com/countvajhula/.emacs.d/blob/master/my-packages/my-racket.el).

---

<div class="post-metadata">

**Author:** ![yossarian](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yossarian](https://racket.discourse.group/u/yossarian)\
**Post date:** [April 16, 2024, 8:59pm UTC](https://racket.discourse.group/t/navigation-through-top-level-definitions-in-drracket/2807/5 "2024-04-16T20:59:14Z")

</div>

Thanks, that could indeed be a reasonably simple hack. Thanks to the racket-mode creator, I discovered that emacs [imenu](https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html) is the typical way to support this. Works very well!
