Open robgev opened 7 years ago
I experimented the same thing but just inside a function that do a match over a variant. It seems to be that tuareg consider the comment as part of the match.
Yes. When there is no subsequent expression, the comment is reputed to belong to the previous expression. I'll see what I can do about that. (For now, I also tend to use the ;;
trick).
thanks @Chris00
Hi @yogin25 @robgev, You may also be interested by the following key-binding, which provides a workaround for your issue:
<C-return> runs the command electric-indent-just-newline, which is an
interactive compiled Lisp function in `electric.el'.
It is bound to <C-return>.
(electric-indent-just-newline ARG)
Insert just a newline, without any auto-indentation.
Actually I just realized that <C-return>
is not a standard key-binding, I had added this in my init.el
:
(add-hook 'tuareg-mode-hook (lambda ()
(local-set-key (kbd "<C-return>") #'electric-indent-just-newline)))
EDIT: on second thought it seems more natural to bind <C-return>
to completion (e.g. if one uses company), so maybe a better binding for 'electric-indent-just-newline
would be <S-return>
.
Thus I'm now using
(add-hook 'tuareg-mode-hook (lambda () (company-mode)
(local-set-key (kbd "<S-return>") #'electric-indent-just-newline)
(local-set-key (kbd "<C-return>") #'company-complete)))
thank's for the hint
@yogin25
To complement my previous post, it seems that my <S-return>
suggestion was not sufficient, as when one types the closing parenthesis, the comment is forcibly indented.
However typing 〈S-return〉 (* Puts here *〈C-q〉)
− that is Ctrl+Q before )
− seems to do the trick.
FYI here is the corresponding doc:
C-q runs the command quoted-insert, which is an interactive compiled
Lisp function in `simple.el'.
It is bound to C-q.
(quoted-insert ARG)
Read next input character and insert it.
This is useful for inserting control characters.
[...]
Hello, I am new trying to learn OCaml. While doing exercises from a book, I try to put comments for later reference. However, comment style/automatic indentation acts strangely. If you put
;;
at the end of the line it works fine, goes to the start of the new line where you can put comments normally. However, if you do not put them it indents comments as it's code.Note: in case if you write some code line and hit enter it transfers it to the start of the line, but in case of comments it acts the opposite way.
I've tried both opam and melpa versions of tuareg.
P.S. Here is a simple GIF showing what's the problem.