branch: elpa/tuareg
commit 8152aee976d786da589e827f8e103f6f55f3b8b3
Author: Mattias EngdegÄrd <[email protected]>
Commit: Mattias EngdegÄrd <[email protected]>
Repair `tuareg-eval-region`
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 #273, #231).
Rewrite to follow the spirit of the original code: extend the region
to contain all phrases it intersects.
---
tuareg.el | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/tuareg.el b/tuareg.el
index 52c9896..2d35dbc 100644
--- a/tuareg.el
+++ b/tuareg.el
@@ -3683,15 +3683,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")