2012-09-05

OCamlのtoplevelを再起動するための設定

#quit;;してM-x tuareg-run-ocamlするのが面倒になってきたので。Emacs Lispは詳しくないから間違った作法とかがあるかも。(特にプロセスの終了を待つあたりとか)

(defun restart-ocaml-toplevel ()
  (interactive)
  (let ((buffer (get-buffer tuareg-interactive-buffer-name)))
    (cond ((null buffer) (tuareg-run-ocaml))
          (t
           (let ((process (get-buffer-process buffer)))
             (when process
               (comint-simple-send process "#quit;;")
               (with-timeout (10)
                 (while (comint-check-proc buffer)
                   (sleep-for 0 500)))))
           (goto-char (point-max))
           (tuareg-run-ocaml)))))

(defun introduce-tuareg-toplevel-restart ()
  (define-key tuareg-mode-map "\C-cr" 'restart-ocaml-toplevel))

(add-hook 'tuareg-mode-hook 'introduce-tuareg-toplevel-restart)

0 件のコメント: