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 |
;; +-----------------------------------------------------------------+
(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."