# Any way to hook running a quickscript script on events in Dr. Racket?

**URL:** https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887
**Category:** Questions & Answers
**Created:** [April 21, 2023, 6:20am UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887 "2023-04-21T06:20:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)
#### Post date: [April 21, 2023, 6:20am UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887/1 "2023-04-21T06:20:29Z")

</div>

For example, I have a script to remove trailing whitespace from lines; I'd like to have it automatically run before saving a file.

---

<div class="post-metadata">

### Author: ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)
#### Post date: [April 21, 2023, 7:17am UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887/2 "2023-04-21T07:17:15Z")

</div>

Currently there's no straightforward way to do this in Quickscript.

One workaround is to write a quickscript that removes the trailing whitespaces and then saves the file (either by calling the correct method, or by automatically navigating the menus). I'm not sure if overloading the default Ctrl+s shortcut would work (worth a try), so maybe a different keybinding is needed.

---

<div class="post-metadata">

### Author: ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)
#### Post date: [April 22, 2023, 6:41am UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887/3 "2023-04-22T06:41:48Z")

</div>

That approach worked for this particular case (Though it won't just replace the existing Ctrl-S binding; had to use something else), but a more generic hook system would still be nice...

---

<div class="post-metadata">

### Author: ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)
#### Post date: [April 22, 2023, 12:28pm UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887/4 "2023-04-22T12:28:28Z")

</div>

I certainly agree in principle. I'm wondering what the best approach would be though, as it doesn't seem like there's a unified approach to handle a number of events all at once. So I worry that each hook callback would have to be inserted manually at the point of interest, which sounds prone to problems and adds constraints (such as backward compatibility) on the hooked event.

If you have other hooks you're thinking, let me know. That would help me figure out what approach to take.

---

<div class="post-metadata">

### Author: ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)
#### Post date: [April 23, 2023, 6:26am UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887/5 "2023-04-23T06:26:15Z")

</div>

I'd just look at whatever emacs provides and pick out anything relevant to DrRacket.

---

<div class="post-metadata">

### Author: ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)
#### Post date: [September 10, 2023, 3:08pm UTC](https://racket.discourse.group/t/any-way-to-hook-running-a-quickscript-script-on-events-in-dr-racket/1887/6 "2023-09-10T15:08:34Z")

</div>

🎉 The snapshot version of Racket (≥ v8.10.0.3) now features Quickscript [hooks](https://users.cs.utah.edu/plt/snapshots/current/doc/quickscript/index.html#%28part._.Hooks%29) 🎉

Here's a first script (to install just like other quickscripts) that automatically [removes trailing spaces on saving](https://gist.github.com/Metaxal/2628c2d4909cee135e5f6dd8254602a0) a file. Make sure to reload the scripts with `Scripts | Manage | Reload menu` once the script is installed.

This is a first attempt and I might make breaking changes before the next official Racket release (8.11, probably). So now is a good time to test it and send feedback! 🙂
