Navigation through (top-level) definitions in DrRacket

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?

2 Likes

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, and some keybindings, you can let drracket behave a bit like VS Code or Sublime regarding looking for commands or symbols/definitions.

3 Likes

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), 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 does not seem to have such an obvious? overview of definitions?

1 Like

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

(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.

Thanks, that could indeed be a reasonably simple hack. Thanks to the racket-mode creator, I discovered that emacs imenu is the typical way to support this. Works very well!

1 Like