From aaea68fa5603d07728a6b392a619f10e1ddb02c7 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Wed, 27 Jul 2011 13:18:18 +0200 Subject: [PATCH] tuareg integration Ignore-this: b4dff4fa5d5eec908e25e8c0f66d1db5 darcs-hash:20110727111818-c41ad-361cfb6e535e60a8a223f70c6fca972f1da3a865 --- src/utop.el | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/utop.el b/src/utop.el index de0d4d9..c9ebe2d 100644 --- a/src/utop.el +++ b/src/utop.el @@ -277,23 +277,40 @@ sub-process." ;; | Tuareg integration | ;; +-----------------------------------------------------------------+ +(defun utop-start () + "Start utop if not already started." + ;; Create the utop buffer if it does not exists, otherwise just + ;; retreive it + (let ((buf (get-buffer-create utop-buffer-name))) + ;; Make it appear + (display-buffer buf) + ;; Set the utop mode in that buffer if not already done + (with-current-buffer buf (unless (eq major-mode 'utop-mode) (utop-mode))))) + (defun utop-eval-region (start end) "Eval the current region in utop." (interactive "r") - (save-excursion (utop)) + ;; Start utop if needed + (save-excursion (utop-start)) + ;; From tuareg (setq tuareg-interactive-last-phrase-pos-in-source start) - (save-excursion - (goto-char start) - (tuareg-skip-blank-and-comments) - (setq start (point)) - (goto-char end) - (tuareg-skip-to-end-of-phrase) - (setq end (point)) - (let ((text (buffer-substring-no-properties start end))) - (with-current-buffer utop-buffer-name - (goto-char (point-max)) - (insert text ";;") - (utop-send-input))))) + ;; Select the text of the region + (let ((text + (save-excursion + ;; Search the start and end of the current paragraph + (goto-char start) + (tuareg-skip-blank-and-comments) + (setq start (point)) + (goto-char end) + (tuareg-skip-to-end-of-phrase) + (setq end (point)) + (buffer-substring-no-properties start end)))) + (with-current-buffer utop-buffer-name + ;; Insert it at the end of the utop buffer + (goto-char (point-max)) + (insert text ";;") + ;; Send input to utop now + (utop-send-input)))) (defun utop-eval-phrase () "Eval the surrounding Caml phrase (or block) in utop."