# \`with-editor-sequence\`

**URL:** <https://racket.discourse.group/t/with-editor-sequence/1125>\
**Category:** Show & Tell\
**Tags:** macro\
**Created:** [July 6, 2022, 4:06pm UTC](https://racket.discourse.group/t/with-editor-sequence/1125 "2022-07-06T16:06:37Z")\
**Posts on this page:** 2\
**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:** [July 6, 2022, 4:06pm UTC](https://racket.discourse.group/t/with-editor-sequence/1125/1 "2022-07-06T16:06:37Z")

</div>

I almost can't believe this isn't in the standard library, so here it is:

```scheme
(define (call-with-editor-sequence editor f)
  (send editor begin-edit-sequence)
  (f)
  (send editor end-edit-sequence))

(require syntax/parse/define)

(define-syntax-parse-rule (with-editor-sequence editor:expr body:expr ...+)
  (call-with-editor-sequence editor (λ () body ...)))

```

Example use:

```scheme
(define t (new text%))
(send t begin-edit-sequence)
(send t insert "a")
(send t insert "b")
(send t insert "c" 0 0)
(send t end-edit-sequence)
;; becomes
(with-editor-sequence t
  (send t insert "a")
  (send t insert "b")
  (send t insert "c" 0 0))

```

It would be natural to add support for the arguments to `begin-edit-sequence`. I opted not to do anything crazy (anaphoric or otherwise `send*`-like) with the `editor` because (in my case) I need to trigger the editor sequence on an editor that is held by an [`editor-canvas%` subclass](https://docs.racket-lang.org/mrlib/hierarchical-list_.html) before operating on the subclass instance and nodes in its object graph, not the editor itself.

---

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [July 6, 2022, 10:24pm UTC](https://racket.discourse.group/t/with-editor-sequence/1125/2 "2022-07-06T22:24:38Z")

</div>

I wonder about exceptions / continuations, maybe using `dynamic-wind` would be better?  
But I don't know the details about begin/end-edit-sequence and whether it would make sense in this context / in the context of your application.
