ocaml / tuareg

Emacs OCaml mode
GNU General Public License v3.0
362 stars 79 forks source link

tuareg-eval-region applies to phrase instead of region #231

Closed MdeLv closed 2 years ago

MdeLv commented 4 years ago

Debian 10 Emacs 26.1 ocaml.4.07.1

tuareg-eval-phrase works well. However, I can't make tuareg-eval-region working. I select a region, then call this function (menu or shortcut) but it evaluates the phrase. Is there something to tweak?

Thanks.

MdeLv commented 4 years ago

Do you sometimes evaluate region?

Chris00 commented 4 years ago

Evaluating a region actually evaluates the smallest phrase containing that region.

MdeLv commented 4 years ago

I already use the following workaround: I copy the so-called "region" foo within a phrase such as let _ = foothat is correctly given to the Toplevel with (tuareg-eval-phrase), which makes editing heavy.

But do you see a simple way to instruct the tuareg extension that I want it to send only the marked text to the Toplevel? In other words, as the function is (tuareg-eval-region START END), how to send START and END parameters as those of the marked text? (and not START and END of OCaml containing phrase). Pls consider that I'm slightly aware of the related Elisp/Emacs syntax.

Thanks.

mattiase commented 3 years ago

In PR #274, tuareg-eval-region has been restored to its intended mode of operation: evaluate the smallest set of phrases intersecting the region.

However, it's not obvious that this is optimal: it's frequently useful to evaluate just a part of a phrase (an expression, for example), and we already have tuareg-eval-phrase for doing the containing-phrase thing. It's also quite easy to mark a defun or phrase (C-M-h).

Chris00 commented 3 years ago

@mattiase You are right. Let's extend tuareg-eval-phrase so it does the above when the region is active and let tuareg-eval-region just send the region (whether it is a valid expression or not). May you amend https://github.com/ocaml/tuareg/pull/274 for that?

mattiase commented 3 years ago

Certainly, have a look at this.

mattiase commented 2 years ago

I think this bug can be closed. Everything seems to be merged.