tuareg integration

Ignore-this: b4dff4fa5d5eec908e25e8c0f66d1db5

darcs-hash:20110727111818-c41ad-361cfb6e535e60a8a223f70c6fca972f1da3a865
This commit is contained in:
Jeremie Dimino 2011-07-27 13:18:18 +02:00
parent a1ebb70cb6
commit aaea68fa56
1 changed files with 30 additions and 13 deletions

View File

@ -277,23 +277,40 @@ sub-process."
;; | Tuareg integration | ;; | 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) (defun utop-eval-region (start end)
"Eval the current region in utop." "Eval the current region in utop."
(interactive "r") (interactive "r")
(save-excursion (utop)) ;; Start utop if needed
(save-excursion (utop-start))
;; From tuareg
(setq tuareg-interactive-last-phrase-pos-in-source start) (setq tuareg-interactive-last-phrase-pos-in-source start)
(save-excursion ;; Select the text of the region
(goto-char start) (let ((text
(tuareg-skip-blank-and-comments) (save-excursion
(setq start (point)) ;; Search the start and end of the current paragraph
(goto-char end) (goto-char start)
(tuareg-skip-to-end-of-phrase) (tuareg-skip-blank-and-comments)
(setq end (point)) (setq start (point))
(let ((text (buffer-substring-no-properties start end))) (goto-char end)
(with-current-buffer utop-buffer-name (tuareg-skip-to-end-of-phrase)
(goto-char (point-max)) (setq end (point))
(insert text ";;") (buffer-substring-no-properties start end))))
(utop-send-input))))) (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 () (defun utop-eval-phrase ()
"Eval the surrounding Caml phrase (or block) in utop." "Eval the surrounding Caml phrase (or block) in utop."