Have you read ``The Text Editor Sam'', by Rob Pike? (http://doc.cat-v.org/plan_9/4th_edition/papers/sam/)
A quick re-skim (especially around page 22) or so suggests that you'd want to look at the code for sam -r, and that you'll want to dig into the Rasp data structure, but (contrary to my memory), it might be possible without breaking the existing protocol. Good luck! *Chad