Being partial to the full-REPL-reboot style of development (ala DrRacket) for most situations I wanted the same thing in Emacs with sml-mode. The value add is that you know all of your files are saved and that your environment is in a fresh and known state. I came up with this:
(defun gcr/sml-eval-buffer () "Intelligently evaluate a SML buffer." (interactive) (gcr/save-all-file-buffers) (let ((sml-process (get-process "sml"))) (when sml-process (quit-process sml-process))) (sleep-for 0.25) (let ((sml-buffer (get-buffer "*sml*"))) (when sml-buffer (kill-buffer sml-buffer))) (sml-prog-proc-load-file buffer-file-name t))
Only to be delighted (though not surprised) to find yet another nearly identical approach here by wenjun.yan:
(defun isml () "If sml repl exists, then restart it else create a new repl" (interactive) (when (get-buffer "*sml*") (with-current-buffer "*sml*" (when (process-live-p "sml") (comint-send-eof))) (sleep-for 0.2)) (sml-run "sml" ""))
My urge to attain Emacs Comint mastery only grows.