ocaml / tuareg

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

'tuareg-eval-phrase' no longer works as before #250

Closed Fourchaux closed 3 years ago

Fourchaux commented 3 years ago

Emacs 28.0.50 - Tuareg 20210605.1629 - OCaml 4.12.0

e.g.

let _ = print_int 123 ;;
let _ = print_string "Oulah" ;;

After a 'tuareg-eval-phrase' of the phrase 1, the cursor moves to the beginning of the phrase 2 but all subsequent 'tuareg-eval-phrase' return the evaluation of the phrase 1. Moving the cursor to the right (at least 1 character) allows the evaluation of the phrase 2.

(No need to move the cursor before).

mattiase commented 3 years ago

This is squarely my fault, thanks for noticing! Very sorry about that. Would pull request #251 help?

Fourchaux commented 3 years ago

Oups, I don't know how to apply your PR...

Trying
$ opam pin add tuareg --dev

Or
$ opam pin add tuareg https://github.com/mattiase/tuareg.git

gives
...
The following actions will be performed:
  ∗ install   conf-emacs 1      [required by tuareg]
  ∗ install   tuareg     2.2.0*
  ↻ recompile user-setup 0.7    [uses tuareg]
===== ∗ 2   ↻ 1 =====
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved user-setup.0.7  (cached)
[ERROR] The compilation of conf-emacs.1 failed at "emacs --version".
⬇ retrieved tuareg.2.2.0  (no changes)
... 
╶─ No changes have been performed
mattiase commented 3 years ago

The pull request is on a separate branch and according to the Opam docs you would say something like opam pin add tuareg https://github.com/mattiase/tuareg.git#defun-separator but I haven't tested it myself.

You could also work outside Opam, cloning the branch directly:

$ git clone https://github.com/mattiase/tuareg.git
$ cd tuareg
$ git checkout defun-separator

and then tell your Emacs to use files from that directory. Do say if you need more directions.

Fourchaux commented 3 years ago

Note: I also try opam pin add tuareg https://github.com/mattiase/tuareg.git#defun-separator but the install pb is still present.

Now, working and testing outside opam seems OK. Great. :+1:

mattiase commented 3 years ago

Thanks for testing! Let's see if we can receive assistance in the merge of #251 then. @monnier?

Fourchaux commented 3 years ago

Found something else (with 'and'). Damn...

e.g.: let a = 1 and b = 2 in a + b

'tuareg-eval-phrase' gives:
# let a = 1;;  
val a : int = 1

with the cursor jumping to the beginning of 'and'.
A second 'tuareg-eval-phrase' gives a Parse error:

# and b = 2;;
Toplevel input:
# and b = 2;;
  ^^^
Parse error: illegal begin of top_phrase

Do you have the same problem?

mattiase commented 3 years ago

Thank you, and confirmed. This calls for some more careful testing. Even though a declarative let... and... now consists of two separate defuns, it should as you noted be a single phrase since that is the smallest unit that can be evaluated.

There is more to it than meets the eye. I shall prepare an improved patch as soon as time permits.

mattiase commented 3 years ago

The pull request has been updated; do take a look. (And sorry about the delay.)

Fourchaux commented 3 years ago

This patch solves the 'and' problem. Very good.

Now, I have tried the first examples from the OCaml manual and, unfortunately, several problems exist. e.g.: https://www.ocaml.org/manual/coreexamples.html#s:datatypes

(1 < 2) = false;;

'a';;

"Hello" ^ " " ^ "world";;

{|This is a quoted string, here, neither \ nor " are special characters|};;

{|"\\"|}="\"\\\\\"";;

In all these examples, if the cursor is on the first character, a 'tuareg-eval-phrase' does not evaluate the phrase.

Could having a non-alphanumeric first character be a problem?

mattiase commented 3 years ago

Good catch, thank you! This time, for sure...

Fourchaux commented 3 years ago

This time, for sure... YES. Thank you. :+1:

Quick note: if you have free time, could you give a look at: https://github.com/ocaml/tuareg/issues/239 (yet another one, sorry !)

https://www.ocaml.org/manual/objectexamples.html#s:class-interfaces (Error with tuareg-eval-phrase)

type restricted_point_type =
  object
    method get_x : int
    method bump : unit
  end;;

Line 1, characters 5-7:
1 | class;;
         ^^
Error: Syntax error

OK with tuareg-eval-region :

class type restricted_point_type =
  object method bump : unit method get_x : int end
mattiase commented 3 years ago

It looks like this bug has been fixed; close it if you agree.

Fourchaux commented 3 years ago

OK. Done.