ocaml / tuareg

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

"tuareg-eval-phrase" and the double-semicolon ;; #259

Closed Fourchaux closed 3 years ago

Fourchaux commented 3 years ago

( tuareg 20210709.321 - OCaml 4.12.0 - Emacs 28.0.50 )

e.g.

let _ = 1 ;;
let _ = 2

After a "tuareg-eval-phrase" the cursor jumps to the beginning of the next phrase. OK.

- Exception 1:

let _ = 1
;;
let _ = 2

The cursor jumps to ;; and stays there.

- Exception 2:

let _ = 1 (* comment *) ;;
let _ = 2

Idem.

Note:

let _ = 1 ;; (* comment *)
let _ = 2

This is OK. The cursor jumps to the second line.

Do you think it would be possible to correct these movements?

mattiase commented 3 years ago

Yes, I noticed that too and agree it's a bit annoying when evaluating several phrases in a row with C-M-x and suddenly getting stuck because of a ;; on a line of its own.

From looking at the source it might be intentional – see tuareg--skip-backward-comments-semicolon and tuareg--skip-forward-comments-semicolon for example. There could be subtleties involved. Let's hear what the maintainers have to say about it.

monnier commented 3 years ago

I doubt these subtleties in those functions are meant to provide the behavior under discussion.

But FWIW, I'm probably not the right person to answer since I consider double-semi-colons in files to be non-kosher.

mattiase commented 3 years ago

I think most people avoid ;;, but they often remain when they do get inserted for whatever reason – as when the compiler throws a seemingly nonsensical error that needs to be narrowed down. They are also very common in test suites, which can be quite useful to run piecemeal using C-M-x.

Double-semis are also used a lot by students learning the language and we should be nice to them once in a while.

monnier commented 3 years ago

Double-semis are also used a lot by students learning the language and we should be nice to them once in a while.

I'm not arguing in favor of Tuareg misbehaving in the presence of double-semis; I was just pointing out that I never use them so I don't have a reliable intuition for what Tuareg should do with them.

Fourchaux commented 3 years ago

@mattiase Skipping lines that only contain ;; would already be a very big improvement.

BTW, this "style" is used by some big guns: X. Leroy: https://github.com/ocaml/ocaml/blob/trunk/parsing/location.ml or D.Doligez: https://github.com/ocaml/ocaml/blob/trunk/driver/main_args.ml (for the first reason you give - improving the error messages - I suppose).