Function: tuareg-region-of-defun
tuareg-region-of-defun is a natively compiled function defined in
tuareg.el.
Signature
(tuareg-region-of-defun &optional POS)
Documentation
Return a couple (BEGIN . END) for the OCaml phrase around POS,
including comments after the phrase. In case of error, move the
point at the beginning of the error and return nil.
Source Code
;; Defined in /nix/store/6mbh851dhnag8f92qfrlh9ckldzwf6c6-emacs-packages-deps/share/emacs/site-lisp/elpa/tuareg-20260626.936/tuareg.el
(defun tuareg-region-of-defun (&optional pos)
"Return a couple (BEGIN . END) for the OCaml phrase around POS,
including comments after the phrase. In case of error, move the
point at the beginning of the error and return `nil'."
(let ((complete-phrase t)
begin end)
(save-excursion
(if pos (goto-char pos))
;; If the beginning of the defun was an "and", try again until we
;; get to the start of the phrase.
(while (equal (tuareg-backward-beginning-of-defun t) "and")
(forward-char -1))
(setq begin (point))
;; Go all the way to the end of the phrase (not just the defun,
;; which could end at an "and").
(let ((head (tuareg-smie-forward-token)))
(unless (member head '("type" "d-let" "let" "and" "exception" "module"
"class" "val" "external" "open"))
;; Expression phrase.
(goto-char begin)))
(smie-forward-sexp ";;")
(tuareg--skip-forward-comments-semicolon)
(setq end (point))
;; Check if we were not stuck (after POS) because the phrase was
;; not well parenthesized.
(when (and complete-phrase (< (point) (point-max)))
(smie-forward-sexp 'halfsexp)
(when (= end (point)); did not move
(setq complete-phrase nil))))
(if complete-phrase
(cons begin end)
(goto-char end)
nil)))