typerex mode integration

Ignore-this: 75eac634eda3b909b6cac3ad1e6bab64

darcs-hash:20120222191910-c41ad-efba56e4d469a58b5595c992d1473768d38578c1
This commit is contained in:
Jeremie Dimino 2012-02-22 20:19:10 +01:00
parent a196bb8802
commit d8dae4ac5f
3 changed files with 50 additions and 28 deletions

12
README
View File

@ -61,13 +61,15 @@ url: https://forge.ocamlcore.org/projects/utop/
Then you can run utop by executing the command "utop" in emacs. Then you can run utop by executing the command "utop" in emacs.
* Integration with the tuareg mode: * Integration with the tuareg/typerex mode:
You can replace the default toplevel used by the tuareg mode by You can replace the default toplevel used by the tuareg or typerex
utop, for that add the following lines to your ~/.emacs file: mode by utop, for that add the following lines to your ~/.emacs
file:
(autoload 'utop-tuareg-setup "utop" "Toplevel for OCaml" t) (autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)
(add-hook 'tuareg-mode-hook 'utop-tuareg-setup) (add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)
* Development: * Development:

View File

@ -75,13 +75,14 @@ file:
then you can run utop by pressing M-x and typing "utop". utop support then you can run utop by pressing M-x and typing "utop". utop support
completion in emacs mode. Just press Tab to complete a word. You can completion in emacs mode. Just press Tab to complete a word. You can
also integrate it with the tuareg mode. For that add the following also integrate it with the tuareg or typerex mode. For that add the
lines to your following lines to your
.I ~/.emacs .I ~/.emacs
file: file:
(autoload 'utop-tuareg-setup "utop" "Toplevel for OCaml" t) (autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)
(add-hook 'tuareg-mode-hook 'utop-tuareg-setup) (add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)
.SH OPTIONS .SH OPTIONS
Same as Same as

View File

@ -548,9 +548,27 @@ If ADD-TO-HISTORY is t then the input will be added to history."
(process-send-string utop-process "end:\n"))))) (process-send-string utop-process "end:\n")))))
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Tuareg integration | ;; | Tuareg/Typerex integration |
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
(defun utop-choose (symbol)
(cond
((eq major-mode 'tuareg-mode)
(intern (concat "tuareg-" symbol)))
((eq major-mode 'typerex-mode)
(intern (concat "typerex-" symbol)))
(t
(error (concat "unsupported mode: " (symbol-name major-mode) ", utop support only tuareg and typerex modes")))))
(defmacro utop-choose-symbol (symbol)
(utop-choose symbol))
(defmacro utop-choose-call (symbol &rest args)
(cons (utop-choose symbol) args))
(defmacro utop-choose-defun (symbol &rest args)
(cons 'defun (cons (utop-choose symbol) args)))
(defun utop-prepare-for-eval () (defun utop-prepare-for-eval ()
"Prepare utop for evaluation." "Prepare utop for evaluation."
(save-excursion (save-excursion
@ -581,16 +599,16 @@ If ADD-TO-HISTORY is t then the input will be added to history."
(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
(setq tuareg-interactive-last-phrase-pos-in-source start) (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
;; Search the start and end of the current paragraph ;; Search the start and end of the current paragraph
(goto-char start) (goto-char start)
(tuareg-skip-blank-and-comments) (utop-choose-call "skip-blank-and-comments")
(setq start (point)) (setq start (point))
(goto-char end) (goto-char end)
(tuareg-skip-to-end-of-phrase) (utop-choose-call "skip-to-end-of-phrase")
(setq end (point)) (setq end (point))
(buffer-substring-no-properties start end)))) (buffer-substring-no-properties start end))))
(with-current-buffer utop-buffer-name (with-current-buffer utop-buffer-name
@ -618,10 +636,10 @@ If ADD-TO-HISTORY is t then the input will be added to history."
(utop-prepare-for-eval) (utop-prepare-for-eval)
(let ((end)) (let ((end))
(save-excursion (save-excursion
(let ((pair (tuareg-discover-phrase))) (let ((pair (utop-choose-call "discover-phrase")))
(setq end (nth 2 pair)) (setq end (nth 2 pair))
(utop-eval (nth 0 pair) (nth 1 pair)))) (utop-eval (nth 0 pair) (nth 1 pair))))
(if tuareg-skip-after-eval-phrase (if (utop-choose-symbol "skip-after-eval-phrase")
(goto-char end)))) (goto-char end))))
(defun utop-eval-buffer () (defun utop-eval-buffer ()
@ -630,27 +648,28 @@ If ADD-TO-HISTORY is t then the input will be added to history."
(utop-prepare-for-eval) (utop-prepare-for-eval)
(utop-eval (point-min) (point-max))) (utop-eval (point-min) (point-max)))
(defun utop-tuareg-setup () (defun utop-setup-ocaml-buffer ()
"Override tuareg interactive functions by utop ones. "Override tuareg/typerex interactive functions by utop ones.
You can call this function after loading the tuareg mode to let You can call this function after loading the tuareg/typerex mode
it use utop instead of its builtin support for interactive to let it use utop instead of its builtin support for interactive
toplevel. 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-tuareg-setup \"utop\" \"Toplevel for OCaml\" t) (autoload 'utop-setup-ocaml-buffer \"utop\" \"Toplevel for OCaml\" t)
(add-hook 'tuareg-mode-hook 'utop-tuareg-setup)" (add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)"
(interactive) (interactive)
;; Redefine tuareg functions ;; Redefine tuareg functions
(defun tuareg-eval-phrase () (interactive) (utop-eval-phrase)) (utop-choose-defun "eval-phrase" () (interactive) (utop-eval-phrase))
(defun tuareg-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))
(defun tuareg-eval-buffer () (interactive) (utop-eval-buffer)) (utop-choose-defun "eval-buffer" () (interactive) (utop-eval-buffer))
(defun tuareg-interrupt-caml () (interactive) (utop-interrupt)) (utop-choose-defun "interrupt-caml" () (interactive) (utop-interrupt))
(defun tuareg-kill-caml () (interactive) (utop-kill)) (utop-choose-defun "kill-caml" () (interactive) (utop-kill))
(defun tuareg-run-caml () (interactive) (utop)) (utop-choose-defun "run-caml" () (interactive) (utop))
;; Redefine this variable so menu will work ;; Redefine this variable so menu will work
(setq tuareg-interactive-buffer-name utop-buffer-name) (set (utop-choose "interactive-buffer-name") utop-buffer-name)
nil) nil)
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+