                     (substring-no-properties output (match-end 0)))
             (1+ (match-beginning 0))))))
 
-(defun fstar-literate--toggle (flag setup-fn)
-  "Run converter with FLAG, fill buffer with output, and run SETUP-FN."
+(defun fstar-literate--toggle (flag new-mode)
+  "Run converter with FLAG, fill buffer with output, and run NEW-MODE."
   (pcase-let* ((modified (buffer-modified-p))
                (`(,rst . ,point)
                 (fstar--widened-excursion (fstar-literate--run-converter flag))))


;;; Literate F*

;; FIXME undoing past translation yields wrong mode

(defvar-local fstar-literate--fst-name nil)
(put 'fstar-literate--fst-name 'permanent-local t)


      (erase-buffer)
      (insert rst))
    (goto-char point)
    (push `(apply ,major-mode) buffer-undo-list)
    (funcall new-mode)
    (set-buffer-modified-p modified)))

(defun fstar-literate--rst-save ()
