add support the caml-mode

Ignore-this: b691ce8780c5d177ab69d0f00b521e5c

darcs-hash:20120716151404-c41ad-658717281b5b9ce73a0e5ac9cc219d700d8aee2a
This commit is contained in:
Jeremie Dimino 2012-07-16 17:14:04 +02:00
parent 51f7caafb5
commit 0d5e593728
1 changed files with 20 additions and 15 deletions

View File

@ -650,23 +650,26 @@ If ADD-TO-HISTORY is t then the input will be added to history."
(utop-send-string "end:\n"))))) (utop-send-string "end:\n")))))
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Tuareg/Typerex integration | ;; | Caml/Tuareg/Typerex integration |
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
(defun utop-choose (symbol) (defun utop-choose (symbol)
"Be best at resolving tuareg or typerex dependencies even when "Be best at resolving caml, tuareg or typerex dependencies even
byte-compiling." when byte-compiling."
(cond (cond
((eq major-mode 'tuareg-mode) ((eq major-mode 'tuareg-mode)
(intern (concat "tuareg-" symbol))) (intern (concat "tuareg-" symbol)))
((eq major-mode 'typerex-mode) ((eq major-mode 'typerex-mode)
(intern (concat "typerex-" symbol))) (intern (concat "typerex-" symbol)))
(t ((eq major-mode 'caml-mode)
(if (require 'typerex nil t) (intern (concat "caml-" symbol)))
(intern (concat "typerex-" symbol)) ((require 'tuareg nil t)
(if (require 'tuareg nil t) (intern (concat "tuareg-" symbol)))
(intern (concat "tuareg-" symbol)) ((require 'typerex nil t)
(error (concat "unsupported mode: " (symbol-name major-mode) ", utop support only tuareg and typerex modes"))))))) (intern (concat "typerex-" symbol)))
((require 'caml nil t)
(intern (concat "caml-" symbol)))
(error (concat "unsupported mode: " (symbol-name major-mode) ", utop support only caml, tuareg and typerex modes"))))
(defmacro utop-choose-symbol (symbol) (defmacro utop-choose-symbol (symbol)
(utop-choose symbol)) (utop-choose symbol))
@ -707,7 +710,8 @@ byte-compiling."
(defun utop-eval (start end) (defun utop-eval (start end)
"Eval the given region in utop." "Eval the given region in utop."
;; From tuareg ;; From tuareg
(set (utop-choose "interactive-last-phrase-pos-in-source") start) (unless (eq major-mode 'caml-mode)
(set (utop-choose "interactive-last-phrase-pos-in-source") start))
;; Select the text of the region ;; Select the text of the region
(let ((text (let ((text
(save-excursion (save-excursion
@ -757,19 +761,20 @@ byte-compiling."
(utop-eval (point-min) (point-max))) (utop-eval (point-min) (point-max)))
(defun utop-setup-ocaml-buffer () (defun utop-setup-ocaml-buffer ()
"Override tuareg/typerex interactive functions by utop ones. "Override caml/tuareg/typerex interactive functions by utop ones.
You can call this function after loading the tuareg/typerex mode You can call this function after loading the caml/tuareg/typerex
to let it use utop instead of its builtin support for interactive mode to let it use utop instead of its builtin support for
toplevel. interactive toplevel.
To automatically do that just add these lines to your .emacs: To automatically do that just add these lines to your .emacs:
(autoload 'utop-setup-ocaml-buffer \"utop\" \"Toplevel for OCaml\" t) (autoload 'utop-setup-ocaml-buffer \"utop\" \"Toplevel for OCaml\" t)
(add-hook 'caml-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer) (add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)" (add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)"
(interactive) (interactive)
;; Redefine tuareg functions ;; Redefine caml/tuareg/typerex functions
(utop-choose-defun "eval-phrase" () (interactive) (utop-eval-phrase)) (utop-choose-defun "eval-phrase" () (interactive) (utop-eval-phrase))
(utop-choose-defun "eval-region" (start end) (interactive "r") (utop-eval-region start end)) (utop-choose-defun "eval-region" (start end) (interactive "r") (utop-eval-region start end))
(utop-choose-defun "eval-buffer" () (interactive) (utop-eval-buffer)) (utop-choose-defun "eval-buffer" () (interactive) (utop-eval-buffer))