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

Preserve indentation of the first line to wrap #23

Closed
mschwerhoff opened this issue Jan 16, 2017 · 5 comments
Closed

Preserve indentation of the first line to wrap #23

mschwerhoff opened this issue Jan 16, 2017 · 5 comments

Comments

@mschwerhoff
Copy link

It would be handy, e.g. when working with LaTeX, Markdown or mark-up languages in general, if wrapping preserved the indentation of the first line. Ideally, lines such as

    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
    \item Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

    * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
    * Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

would be magically wrapped to

    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
          sed do eiusmod tempor incididunt ut labore et dolore
          magna aliqua
    \item Ut enim ad minim veniam, quis nostrud exercitation
          ullamco laboris nisi ut aliquip ex ea commodo consequat.

    * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
      do eiusmod tempor incididunt ut labore et dolore magna
      aliqua
    * Ut enim ad minim veniam, quis nostrud exercitation ullamco
      laboris nisi ut aliquip ex ea commodo consequat.

However, since this is probably difficult to achieve in general, it would already be great if the indentation of the first selected line were preserved when wrapping. E.g. selecting and wrapping the second line of the block

    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
          sed do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

would preserve the manually created indentation and yield

    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
          sed do eiusmod tempor incididunt ut labore et dolore
          magna aliqua excepteur sint occaecat cupidatat non
          proident, sunt in culpa qui officia deserunt mollit anim id
          est laborum.

This should also work if multiple lines are selected: e.g. selecting and wrapping the second and all subsequent lines of the block

    * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
      do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum, duis aute irure dolor in reprehenderit
    in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

should yield

    * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
      do eiusmod tempor incididunt ut labore et dolore magna
      aliqua excepteur sint occaecat cupidatat non proident, sunt in
      culpa qui officia deserunt mollit anim id est laborum, duis aute
      irure dolor in reprehenderit in voluptate velit esse cillum
      dolore eu fugiat nulla pariatur.
@stkb
Copy link
Owner

stkb commented Jan 17, 2017

Ok a few things going on here.

Firstly just taking Markdown for a moment, if there's something that's specifically not working there could you give me an example? For example, bullet points should already be working as you describe.

* Non elit aliqua ullamco nostrud. Excepteur officia do et officia sunt non voluptate mollit adipisicing dolore ex.

Wraps to:

* Non elit aliqua ullamco nostrud. Excepteur officia do et officia sunt
  non voluptate mollit adipisicing dolore ex.

I'm not sure if you're also using them in LaTeX, or another language.


Rewrap also already preserves the indentation of the second line elsewhere (eg multiline comments). So it wouldn't be out of the question to implement it in other places too.

Back to LaTeX: support is something that's been on the radar, but I've just been waiting for someone to request it. However, the extension currently doesn't recognise the language at all, which means it defaults to the Markdown processor, which won't always produce good results for LaTeX. I've now made a quick change in master, so that it recognises it as a source code file (with % for comments).

This will immediately change some behaviour and give some improvements. Eg this example will now work:

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat cupidatat non

Wraps to: 

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore
      magna aliqua excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id
      est laborum.

As long as the cursor is on the second line (or the whole thing is selected). This comes because the starting text is now already seen as 2 separate paragraphs, because of the difference in indentation.


The last example, with very messy lines:

    * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
      do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum, duis aute irure dolor in reprehenderit
    in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Again, this should already work in Markdown, so if you're using it somewhere else, maybe we can have it work automatically there too. I'd like to try that before creating extra behaviours depending on what is selected.

@stkb
Copy link
Owner

stkb commented Jan 18, 2017

I've just published v1.1.0, which contains the changes for LaTeX described above. Hopefully it should help.

@mschwerhoff
Copy link
Author

mschwerhoff commented Feb 9, 2017

Thanks for the quick reactions and sorry for the delay from my side. I also think that there was some confusion on my site: I wasn't aware that the wrapping is filetype-dependent (which makes perfect sense), and if I remember correctly, I tried the examples with a plain old text file (.txt).

Regarding Markdown: wrapping indeed works as expected, also with messy lines.

Regarding LaTeX (using plugin version 1.1.0 and file extension .tex): the non-messy case works, e.g.

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum, duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.

is wrapped to

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
      excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
      deserunt mollit anim id est laborum, duis aute irure dolor in
      reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
      pariatur. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

The messy case, however, doesn't wrap as expected. E.g.

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum, duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.

wraps to

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
      excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum,
    duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur.
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.

I tried selecting only the second and subsequent lines (and the other way round, to have the cursor on the second line) and also the whole block (including the first line), but the behaviour is always the same.

@stkb
Copy link
Owner

stkb commented Feb 9, 2017

Have just published v1.2.0 which contains some more improvements for LaTeX. The messy case will now work here.

tex

It's also now detected as a single paragraph so you only have to have your cursor in the paragraph to wrap the whole thing.

The indent of the 2nd+ lines is determined by the indent of the 2nd line. However if there's only 1 line to begin with, then following lines will have the same indent as that one.

Eg:

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore magna aliqua excepteur sint occaecat

Wraps to:

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
      sed do eiusmod tempor incididunt ut labore et dolore 
      magna aliqua excepteur sint occaecat

But

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt

Wraps to

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt

I've wondered in the past about adding a "default indent" setting for this case, so if you'd find it very helpful I could add that too.

@stkb
Copy link
Owner

stkb commented Feb 16, 2017

Closing as I think this is now fixed (since 1.2.0) but let me know if you're still having issues!

@stkb stkb closed this as completed Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants