Adding keybindings to debug

44 views
Skip to first unread message

James Zollinger

unread,
Oct 28, 2021, 1:10:13 PM10/28/21
to Racket Users
I'm a happy user of DrRacket, plowing through the MIT SICP (Structure and Interpretation of Computer Programs.) As I'm learning Scheme, I'm spending more time than I'd like to admit in the debugger. I'm more used to emacs/bash but really liking the DrRacket IDE (using graphical libs to display output, for example) and would really like to stick with it, but I'm struggling with the keybindings...

but I don't see a way to add keyboard shortcuts in the debugger. I'd like to add shortcuts for GUI buttons "Go", "Step", "Over", etc. as well as context menus "Print return value to console", "Pause at this point", etc.

Any help would be greatly appreciated.
James

Laurent

unread,
Oct 28, 2021, 3:37:41 PM10/28/21
to James Zollinger, Racket Users
There may be a better way to do it, but here's at least a working solution:

It's a quickscript (https://docs.racket-lang.org/quickscript/index.html) so it gives you a new submenu in the Scripts menu, with associated keybindings:
Shift-F1: Start Debug
Shift-F2: Step
Shift-F3: Over
Shift-F4: Out
Shift-F5: Go

It shouldn't be too hard to turn this is just keybindings into your keybinding file if you only want keybindings and not additional Script menu entries.

Sorry, I haven't tried too hard for "Print value..." and "Pause at this point" because these are context menus and the corresponding actions are not accessible programmatically as far as I can tell.

The script probably still needs some tweaking. Let me know if you improve it, or if you have issues with it.

HTH,
Laurent

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/c429d210-7392-4ad3-90db-b1e9edba08b2n%40googlegroups.com.

David Storrs

unread,
Oct 28, 2021, 3:58:10 PM10/28/21
to James Zollinger, Racket Users
I don't know if this fills the need but it's a useful thing to know regardless:  macOS will allow you to add a keyboard shortcut for any menu item in any application.  https://support.apple.com/guide/mac-help/create-keyboard-shortcuts-for-apps-mchlp2271/mac

James Zollinger

unread,
Oct 29, 2021, 5:47:26 PM10/29/21
to Racket Users
Thank you both for the thoughtful answers. I will take a look at the quickscript you sent, Laurent. The mac keyboard shortcut is a great feature. Makes me wonder about buying a mac again after quite a few years. (I use debian as my daily driver, at least for development.)

If anyone out there knows how to deal with context menus programmatically, please share.

Laurent

unread,
Oct 30, 2021, 6:37:47 AM10/30/21
to James Zollinger, Racket Users
On Fri, Oct 29, 2021 at 10:47 PM James Zollinger <mzo...@gmail.com> wrote:
Thank you both for the thoughtful answers. I will take a look at the quickscript you sent, Laurent. The mac keyboard shortcut is a great feature. Makes me wonder about buying a mac again after quite a few years. (I use debian as my daily driver, at least for development.)

Apparently it should be possible to do the same thing for Debian, depending on your window manager, with some caveats:
 
If anyone out there knows how to deal with context menus programmatically, please share.

The code of the debug-tool should be changed to make these reachable from the outside with a define/public. Somewhere around here:
but it's a little intricate because a set of specialized menu items are created after right-clicking when in debug mode.
 
Another possibility would be to simulate the mouse clicks, but that seems rather hacky and error-prone.

Mike Engelhart

unread,
Oct 30, 2021, 7:25:29 AM10/30/21
to Laurent, James Zollinger, Racket Users
On Mac OS I tried adding keyboard shortcuts using the linked Apple support document to allow for comment/uncomment bindings in DrRacket and it doesn't work (at least on Mac OS Monterey).  One thing I noticed is that if you go back to System Preferences->Keyboard->Shortcuts->App Shortcuts and look at DrRacket under App Shortcuts, unlike other Mac OS apps in the list, it only shows the name DrRacket but doesn't show any of the shortcuts you've added.  

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.

David Storrs

unread,
Oct 30, 2021, 9:03:18 AM10/30/21
to Mike Engelhart, Laurent, James Zollinger, Racket Users
The menu strings get very fussy, so check that you entered it exactly right, and do a very simple one to start. That's the usual cause in my experience.

Mike Engelhart

unread,
Oct 30, 2021, 9:46:16 AM10/30/21
to David Storrs, Laurent, James Zollinger, Racket Users
Thanks David.   The keyboard shortcuts do show in the menu next to the menu item text so they appear to be hooked in it just seems they don't actually work.  I'm wondering if it's the Monterey release that's causing this which is the OS I'm running.   Here's what I mean by them not "sticking" though.

Initial setup

Screen Shot 2021-10-30 at 7.22.00 AM.png

After closing System Preferences and opening it back up.

Screen Shot 2021-10-30 at 7.22.22 AM.png


David Storrs

unread,
Oct 31, 2021, 2:17:17 AM10/31/21
to Mike Engelhart, Laurent, James Zollinger, Racket Users
Maybe try choosing one that doesn't clash with an existing system shortcut? My guess is that macOS is reduplicating keyboard shortcuts and keeping its original version while dropping yours.

Mike Engelhart

unread,
Oct 31, 2021, 8:23:58 AM10/31/21
to David Storrs, Laurent, James Zollinger, Racket Users
Thanks David - Good idea.  Although in my tests, overriding system shortcuts works fine in other Mac apps so I'm not sure if that's the issue.   Anyway I just tried multiple different bindings of obscure Command-shift-Option-<key> and wasn't able to get it to work for comment/uncomment.. It almost seems as if there's something in particular going on with the editor swallowing keystrokes because if I also tried setting the same key commands to "About DrRacket" menu item it opens the About window with the editor window both in and out of focus and then I use that same command to Comment Out with Semicolons and it puts unicode junk into the editor or just makes a system sound.    Off topic a bit but was there a particular reason for not having keybindings associated with comment/uncomment? I can't recall using an IDE or code editor that doesn't have this functionality afforded via keybindings. 



Robby Findler

unread,
Oct 31, 2021, 8:28:38 AM10/31/21
to Mike Engelhart, David Storrs, James Zollinger, Laurent, Racket Users
We can definitely add keybindings. The two things to consider are the existing keybindings and the precedent in other IDEs.

Robby 


Mike Engelhart

unread,
Oct 31, 2021, 10:08:49 AM10/31/21
to Robby Findler, David Storrs, James Zollinger, Laurent, Racket Users
One thing that came to mind is that in Emacs and other editors (IntelliJ I believe also behaves this way by default) is that the keybinding for commenting and uncommenting is the same.  I'm not sure if that's potentially confusing to a new user of an IDE/Editor and for me personally it's not a big enough problem to warrant adding any complexity to the IDE if there's a downside to it.   

Mike

James Zollinger

unread,
Nov 1, 2021, 7:14:42 PM11/1/21
to Laurent, Racket Users
Thanks for the info, Laurent. I tried the trick outlined in the link you sent me on Debian 11 versions of Gnome 3.38.5 (just to test this) and MATE 1.24.1-2 (my preferred environment) without any success.

My LISP/scheme/racket skills are maturing but I'm not quite ready to tackle:
               (when (cons? stat)
                 (make-object menu-item%
                   "Print return value to console" menu
                   (lambda _ (send (get-tab) print-to-console
                                   (string-append "return val = " rendered-value)))))
and friends! (What is "lambda _"?!)

Any suggestions on how to quickly get up to speed to modify debug-tool.rkt beyond reading all of the Racket Documentation?

Laurent

unread,
Nov 2, 2021, 8:35:34 AM11/2/21
to James Zollinger, Racket Users
On Mon, Nov 1, 2021 at 11:14 PM James Zollinger <mzo...@gmail.com> wrote:
Thanks for the info, Laurent. I tried the trick outlined in the link you sent me on Debian 11 versions of Gnome 3.38.5 (just to test this) and MATE 1.24.1-2 (my preferred environment) without any success.

I haven't tried myself. For what it's worth, I wrote another quickscript called "command palette" that does exactly that, but of course specifically for DrRacket (*): 

Again it doesn't look into context (right click) menus as they are not easily accessible.

(*) Actually, it could be used with any Racket GUI app!
 
My LISP/scheme/racket skills are maturing but I'm not quite ready to tackle:
               (when (cons? stat)
                 (make-object menu-item%
                   "Print return value to console" menu
                   (lambda _ (send (get-tab) print-to-console
                                   (string-append "return val = " rendered-value)))))
and friends! (What is "lambda _"?!)

Yeah, that can seem weird, but it will make sense. Let me explain in examples:

(define f (lambda (x) (displayln x)))
(f 3) ; ok
(f 3 4 5) ; not ok
(f) ; not ok

(define g (lambda (x . rst) (displayln (list x rst))))
(g 3) ; ok, equiv to (displayln '(3 ()), rst is the empty list
(g 3 4 5) ; ok, equiv to (displayln '(3 (4 5)))
(g) ; not ok, needs at least 1 argument

(define h (lambda lst (displayln lst)))
(h 3) ; equiv to (displayln '(3))
(h 3 4 5) ; equiv to (displayln '(3 4 5))
(h) ; equiv to (displayln '())

Now, `_` is just an identifier like any other, like `lst`, but by (untold) convention it means "I won't use this argument". So 
(define k (lambda _ (displayln "hoy")))
(k) ; equiv to (displayln "hoy")
(k 3 4 5) ; equiv to (displayln "hoy")
 
Any suggestions on how to quickly get up to speed to modify debug-tool.rkt beyond reading all of the Racket Documentation?

debug-tool.rkt is probably not the best first encounter with Racket. It draws on many concepts (macros, classes, gui, etc.). Though if you do manage to make sense of it you may learn a lot :) 

For this particular task, even though the file contains "units", I think you shouldn't have to understand units, but you will certainly have to understand Racket classes:
and part of the GUI:

HTH,
Laurent

James Zollinger

unread,
Nov 3, 2021, 9:41:55 AM11/3/21
to Laurent, Racket Users
Your explanation of "lambda _" jogged my memory. I'm remembering long ago Haskell learnings where the underscore is used in much the same way.

I'll take a look at the two references you shared. This is a really useful starting point. Thank you again, Laurent.

James Zollinger

unread,
Nov 8, 2021, 7:42:16 PM11/8/21
to Racket Users
I don't have the time to attempt modifications to DrRacket right now. Instead I've moved to emacs, which (to the question posed earlier by Robby Findler) does have keyboard shortcuts for running the debugger. I'm still using racket via emacs' racket-mode but trying to click on the very small green circles and rectangles in the DrRacket debug interface was just too much. I could probably figure out how to add keyboard shortcuts by inspecting the racket-mode code; that may happen later when I know my way around scheme/lisp much better.

Thanks for all the help on this thread. It's good to know there are helpful people in this community.

Reply all
Reply to author
Forward
0 new messages