Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment indentation problems #145

Open
robgev opened this issue Aug 29, 2017 · 7 comments
Open

Comment indentation problems #145

robgev opened this issue Aug 29, 2017 · 7 comments

Comments

@robgev
Copy link

robgev commented Aug 29, 2017

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.
peek 2017-08-15 13-06

@yogin25
Copy link

yogin25 commented Sep 5, 2017

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.

@Chris00
Copy link
Member

Chris00 commented Sep 6, 2017

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).

@yogin25
Copy link

yogin25 commented Sep 11, 2017

thanks @Chris00

@erikmd
Copy link
Contributor

erikmd commented Sep 14, 2017

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.

@erikmd
Copy link
Contributor

erikmd commented Sep 14, 2017

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)))

@yogin25
Copy link

yogin25 commented Sep 25, 2017

thank's for the hint

@erikmd
Copy link
Contributor

erikmd commented Sep 25, 2017

@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.
[...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants