Skip to content

Commit

Permalink
Repair tuareg-eval-region
Browse files Browse the repository at this point in the history
Set `tuareg-interactive-last-phrase-pos-in-source` to the actual start
of the region sent to the REPL. Previously, the incorrect position
caused error locations to be off, causing
`tuareg-interactive-next-error-source` to fail (see ocaml#273, ocaml#231).

Rewrite to follow the spirit of the original code: extend the region
to contain all phrases it intersects.
  • Loading branch information
mattiase committed Sep 3, 2021
1 parent e067bc8 commit 24fd5fa
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tuareg.el
Original file line number Diff line number Diff line change
Expand Up @@ -3589,15 +3589,16 @@ It is assumed that the range START-END delimit valid OCaml phrases."
(defun tuareg-eval-region (start end)
"Eval the current region in the OCaml REPL."
(interactive "r")
;; Use the smallest region containing the phrase(s) at either endpoint.
(dolist (pos (list start end))
(save-excursion
(goto-char pos)
(let ((phrase (tuareg-discover-phrase)))
(when phrase
(setq start (min start (car phrase)))
(setq end (max end (cadr phrase)))))))
(setq tuareg-interactive-last-phrase-pos-in-source start)
(save-excursion
(goto-char start)
(tuareg-backward-beginning-of-defun)
(setq start (point))
(setq end (cdr (tuareg-region-of-defun end)))
(if end
(tuareg-interactive--send-region start end)
(message "The expression after the point is not well braced."))))
(tuareg-interactive--send-region start end))

(define-obsolete-function-alias 'tuareg-narrow-to-phrase #'narrow-to-defun
"Apr 10, 2019")
Expand Down

0 comments on commit 24fd5fa

Please sign in to comment.