Comment start is misaligned when entering newlines for intented comments #1118

Closed
bitonic opened this Issue Jan 10, 2017 · 4 comments

Projects

None yet

4 participants

@bitonic
bitonic commented Jan 10, 2017

See https://asciinema.org/a/4mtl3cyadva0tuuqdpdik2tw6. Reproduced on 9f0bca5 , I've tried with Haskell and C.

@mawww
Owner
mawww commented Jan 11, 2017

Argh, thats due to 5ddc28e that now pastes at line begin, so before the indent.

A solution is to do the comment prefix copy hook before copying the indent from previous line. I am testing that to see if it works fine or if it breaks some other indent behavious.

@danr
Contributor
danr commented Jan 11, 2017

I'm sorry about this mess, I'm working on a fix and I think I have it. Give me a few more.

@danr danr added a commit to danr/kakoune that referenced this issue Jan 11, 2017
@danr danr Fix fix of autoinsertion of comment starts
Hopefully fixes #1118

If the previous line is a comment, we copy everything
from it until the text in the comment start and paste
it on the new line.

One would think that `x` would be enough to select
but this fails when the line is empty. This happens
for instance when `O`pening above or doing `i<ret>` on
a line that starts with a comment.
So we use `X<a-s><a-space>` instead, which selects
the line with the sole `\n` if there is one.
a636fbb
@doppioandante
Contributor

@mawww maybe we should abstract the autoindentation.
What about something like this:

  1. an option to retain indentation from previous line, which could be useful per se for langauges that still don't have a rc script
  2. a way for scripts dictate when to indent or deindent, based on previous line ( e.g. '{' at the end, or 'def' at the beginning, or any pattern) or based on current line (e.g. C++ 'public:', 'end' or '}')

Is there any shortcoming? Replicating the actual commands to indent in every script is bad.

@danr danr added a commit to danr/kakoune that referenced this issue Jan 11, 2017
@danr danr Fix fix of autoinsertion of comment starts
Hopefully fixes #1118

If the previous line is a comment, we copy everything
from it until the text in the comment start and paste
it on the new line.

One would think that `x` would be enough to select
but this fails when the line is empty. This happens
for instance when `O`pening above or doing `i<ret>` on
a line that starts with a comment.
So we use `X<a-s><a-space>` instead, which selects
the line with the sole `\n` if there is one.
017a658
@mawww
Owner
mawww commented Jan 11, 2017

@doppioandante Long time ago there was some additional abstraction in Kakoune for indentation, but then I realized we could implement it using normal mode commands. Its been a very good validation that the editing model was expressive enough.

Its something I dont plan to change, a possibility would be to introduce a .kak file that provides all the building block for auto indentation. But I am not convinced its worth it yet.

@mawww mawww closed this in 5989903 Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment