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 initial indent of text when using latexindent #204

Open
GohioAC opened this issue Jan 7, 2019 · 4 comments
Open

Preserve initial indent of text when using latexindent #204

GohioAC opened this issue Jan 7, 2019 · 4 comments

Comments

@GohioAC
Copy link

GohioAC commented Jan 7, 2019

I currently use latexindent to format only portions of my LaTeX source code, mostly text blocks in between the mathematical stuff. When running :Neoformat on an indented visual selection the formatter removes the indentation.

Before:

    PDF (Portable Document Format) is a file format that has captured all the
    elements of a printed document as an electronic image that you can view,
    navigate, print, or forward to someone else. It is one of the most widely
    used formats for storing and exchanging technical literature and poses
    significant challenges to semantic parsing, since, they do not store any
    structural information that can help identify different segments of a
    document as text, equation, or other mathematical constructs.

After:

PDF (Portable Document Format) is a file format that has captured all the
 elements of a printed document as an electronic image that you can view,
 navigate, print, or forward to someone else.
It is one of the most widely used formats for storing and exchanging technical
 literature and poses significant challenges to semantic parsing, since, they
 do not store any structural information that can help identify different
 segments of a document as text, equation, or other mathematical constructs.

It would be nice, if, when running the formatter on a visual selection, the initial indentation level is preserved. Since this might not be the preferred default for everyone, maybe this feature can be incorporated as an option?

@resolritter
Copy link

I'm having the same issue because I extract portions of the code (JSX inside of Javascript React files) using syntax markers and throw it into html-beautifier, but the result comes back without the block's indentation.

When I faced a similar problem using another tool, I'd compare the indent of the previous line and add the amount + &shiftwidth to all lines in the formatter's output. Would that be a proper solution, or does it need to more (e.g. look further than the immediately previous line)?

@GohioAC
Copy link
Author

GohioAC commented Jan 14, 2019

Looking at the indent of the first line of the visual selection solves my problem. But there might be other use cases, that require different handling.

@resolritter
Copy link

I've developed a naive code that repeats the indent character (spaces or tabs) N times + 1 based on the previous line, but I think it would be better to instead support any user-defined post-processing function through a formatter option, and have the indentation function around as a helper function like any other. Nevertheless, I'll look to open the PR later.

@raine
Copy link

raine commented Jan 15, 2019

I would like to see an option for preserving indentation when using Neoformat to format visual line selection. My use case is similar to http://github.com/prettier/prettier/issues/1324 but maybe this would make sense if built into neoformat instead of formatting tools.

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