Function: tuareg-eval-phrase

tuareg-eval-phrase is an interactive and natively compiled function defined in tuareg.el.

Signature

(tuareg-eval-phrase)

Documentation

Eval the surrounding OCaml phrase (or block) in the OCaml REPL.

If the region is active, evaluate all phrases intersecting the region.

Key Bindings

tuareg-mode-map C-M-x tuareg-mode-map C-c C-e tuareg-mode-map C-x C-e

Source Code

;; Defined in /nix/store/6mbh851dhnag8f92qfrlh9ckldzwf6c6-emacs-packages-deps/share/emacs/site-lisp/elpa/tuareg-20260626.936/tuareg.el
(defun tuareg-eval-phrase ()
  "Eval the surrounding OCaml phrase (or block) in the OCaml REPL.
If the region is active, evaluate all phrases intersecting the region."
  (interactive)
  (let ((opoint (point))
        start end)
    (cond
     ((region-active-p)
      (let ((rbeg (region-beginning))
            (rend (region-end)))
        (setq start rbeg)
        (setq end rend)
        ;; Extend the region at the endpoints if they are in a phrase.
        (save-excursion
          (dolist (pos (list rbeg rend))
            (goto-char pos)
            (let* ((phrase (tuareg-discover-phrase))
                   (beg-phrase (car phrase))
                   (end-phrase (cadr phrase)))
              (when (and phrase
                         (> end-phrase rbeg)
                         (< beg-phrase rend))
                ;; A phrase intersects the region; extend.
                (setq start (min start beg-phrase))
                (setq end (max end end-phrase))))))))
     (t
      (let ((phrase (tuareg-discover-phrase)))
        (unless phrase
          (user-error "Expression after the point is not well braced"))
        (setq start (car phrase))
        (setq end (cadr phrase)))))
    (tuareg-interactive--send-region start end)
    (if tuareg-skip-after-eval-phrase
        (progn
          (when (region-active-p)
            ;; We are moving point and the user probably doesn't
            ;; expect the region to be affected.
            (deactivate-mark))
          (goto-char end)
          (tuareg-skip-blank-and-comments))
      (goto-char opoint))))