# Vim-racket: improved indentexpr

**URL:** <https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908>\
**Category:** Show & Tell\
**Tags:** vim\
**Created:** [May 1, 2023, 9:45pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908 "2023-05-01T21:45:26Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [May 1, 2023, 9:45pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908/1 "2023-05-01T21:45:26Z")

</div>

Been working on an improved indentexpr for vim-racket; if anyone is interesting in helping me dogfood it, please LMK and I'll clean it up and push a branch. Vim 9+ required.

Current improvements: handles `{}` and `#<<herestrings` correctly; indents `(foo\nbar)` correctly (`b` under `f` instead of under `o` ). Current issues: speed when reindenting whole files (small functions have been fine so far). I've one last "trick" to port from the C source for `get_lisp_indent` to try to speed things up which effectively uses the buffer contents like a cache; this should solve the speed problems.

---

<div class="post-metadata">

**Author:** ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)\
**Post date:** [May 2, 2023, 8:50pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908/2 "2023-05-02T20:50:27Z")

</div>

> [@benknoble](#):
>
> Vim 9+ required.

Are there any plans regarding Neovim support?

For me personally, it's not very important. I'm set with the plugin version I currently have, but it wouldn't be nice if I updated and the whole plugin stopped working.

---

<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:** [May 3, 2023, 4:30pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908/3 "2023-05-03T16:30:48Z")

</div>

I don't plan on doing anything special for NeoVim (like using Lua), but I should be able to add a guard to only use the vim9 indentexpr if vim9script is available (so you can keep updating).

---

<div class="post-metadata">

**Author:** ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)\
**Post date:** [May 3, 2023, 6:35pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908/4 "2023-05-03T18:35:47Z")

</div>

> [@benknoble](#):
>
> add a guard to only use the vim9 indentexpr if vim9script is available (so you can keep updating).

Yes, that would be fine with me. Thanks! 🙂

---

<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:** [July 6, 2023, 6:06pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908/5 "2023-07-06T18:06:03Z")

</div>

Hm. I've fallen off a bit on this. Adding to my todo list so I don't forget.

---

<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:** [July 17, 2023, 4:12pm UTC](https://racket.discourse.group/t/vim-racket-improved-indentexpr/1908/6 "2023-07-17T16:12:50Z")

</div>

This is available experimentally as [GitHub - benknoble/vim-racket at indentexpr](https://github.com/benknoble/vim-racket/tree/indentexpr) and is only enabled when vim9script is available.

- There are some slight issues with `cond` and `match` that I haven't figured out yet (I need test cases first…).
- Indenting extremely large blocks correctly is slow, so there are 2 hacks to help. One limits the "context" of the indent to about 100 lines when looking for the outer brackets of an expression; if that ends up merging, I'll make it user configurable and document it. The other tries to use the previous line for indent if possible, but IIRC it's subject to the 100-line limit first.
- Still, it's a marked improvement over `lispindent`, which fails to get `for/fold`, `{}`, and some other Racket-specific syntax right.
