diff --git a/README b/README index 3c8e718..2f81c21 100644 --- a/README +++ b/README @@ -66,18 +66,8 @@ url: https://forge.ocamlcore.org/projects/utop/ You can replace the default toplevel used by the tuareg mode by utop, for that add the following lines to your ~/.emacs file: - (autoload 'utop-eval-region "utop" "Toplevel for OCaml" t) - (autoload 'utop-eval-phrase "utop" "Toplevel for OCaml" t) - (autoload 'utop-eval-buffer "utop" "Toplevel for OCaml" t) - - (defun tuareg-utop-hook () - (local-set-key "\M-\C-x" 'utop-eval-phrase) - (local-set-key "\C-x\C-e" 'utop-eval-phrase) - (local-set-key "\C-c\C-e" 'utop-eval-phrase) - (local-set-key "\C-c\C-r" 'utop-eval-region) - (local-set-key "\C-c\C-b" 'utop-eval-buffer)) - - (add-hook 'tuareg-mode-hook 'tuareg-utop-hook) + (autoload 'utop-tuareg-setup "utop" "Toplevel for OCaml" t) + (add-hook 'tuareg-mode-hook 'utop-tuareg-setup) * Development: diff --git a/man/utop.1 b/man/utop.1 index 7887dcf..d86669b 100644 --- a/man/utop.1 +++ b/man/utop.1 @@ -80,18 +80,8 @@ lines to your .I ~/.emacs file: - (autoload 'utop-eval-region "utop" "Toplevel for OCaml" t) - (autoload 'utop-eval-phrase "utop" "Toplevel for OCaml" t) - (autoload 'utop-eval-buffer "utop" "Toplevel for OCaml" t) - - (defun tuareg-utop-hook () - (local-set-key "\\M-\\C-x" 'utop-eval-phrase) - (local-set-key "\\C-x\\C-e" 'utop-eval-phrase) - (local-set-key "\\C-c\\C-e" 'utop-eval-phrase) - (local-set-key "\\C-c\\C-r" 'utop-eval-region) - (local-set-key "\\C-c\\C-b" 'utop-eval-buffer)) - - (add-hook 'tuareg-mode-hook 'tuareg-utop-hook) + (autoload 'utop-tuareg-setup "utop" "Toplevel for OCaml" t) + (add-hook 'tuareg-mode-hook 'utop-tuareg-setup) .SH OPTIONS Same as diff --git a/src/emacs/utop.el b/src/emacs/utop.el index 02e1263..c1b547d 100644 --- a/src/emacs/utop.el +++ b/src/emacs/utop.el @@ -445,7 +445,7 @@ sub-process." "Eval the current region in utop." (interactive "r") (utop-prepare-for-eval) - (utop-eval (start end))) + (utop-eval start end)) (defun utop-eval-phrase () "Eval the surrounding Caml phrase (or block) in utop." @@ -465,6 +465,26 @@ sub-process." (utop-prepare-for-eval) (utop-eval (point-min) (point-max))) +(defun utop-tuareg-setup () + "Override tuareg interactive functions by utop ones. + +You can call this function after loading the tuareg mode to let +it use utop instead of its builtin support for interactive +toplevel. + +To automatically do that just add these lines to your .emacs: + + (autoload 'utop-tuareg-setup \"utop\" \"Toplevel for OCaml\" t) + (add-hook 'tuareg-mode-hook 'utop-tuareg-setup)" + (interactive) + (defun tuareg-eval-phrase () (interactive) (utop-eval-phrase)) + (defun tuareg-eval-region (start end) (interactive "r") (utop-eval-region start end)) + (defun tuareg-eval-buffer () (interactive) (utop-eval-buffer)) + (defun tuareg-interrupt-caml () (interactive) (utop-interrupt)) + (defun tuareg-kill-caml () (interactive) (utop-kill)) + (defun tuareg-run-caml () (interactive) (utop)) + nil) + ;; +-----------------------------------------------------------------+ ;; | Edition functions | ;; +-----------------------------------------------------------------+