Giter VIP home page Giter VIP logo

Comments (2)

rrthomas avatar rrthomas commented on September 27, 2024

This is dtrt-indent working as intended (and the diagnosis tells you what's going on). It can't distinguish between the case where there are a few odd 2-indents somewhere in the middle of a long file (where an indent of 4 is what you really want), and the case where there are a few symmetric ones at each end (as here).

I thought this issue seemed familiar, and indeed, see #29. I'd rather not make dtrt-indent cleverer. On the other hand, decreasing the value of dtrt-indent-max-merge-deviation only works up to a certain point: for arbitrarily long JSON files you'd have to set it to zero.

I can't think of a simple analytical solution to this problem in general that doesn't involve understanding the syntax of the file.

One way to do it by trial and error: run indent-buffer with the first-guessed setting. If the buffer doesn't change, then keep the setting. This could be done in dtrt-indent-analyze when considering whether to merge two settings.

from dtrt-indent.

NateEag avatar NateEag commented on September 27, 2024

Thanks for the explanation, @rrthomas . That makes sense, and it seemed like a maybe-expected result of the design, but it also surprised me, hence my filing the issue.

I didn't find dtrt-indent-max-merge-deviation when I skimmed for something I could tweak that might help, so thanks, that looks useful.

I don't see a robust, correct analytical answer to the problem either.

Maybe an (opt-in?) dumb heuristic could be good enough. Before merging a lower indent level into a compatible higher indent level, check whether the file's first and last indents match the lower level?

If they do, on average, I bet the lower indent level would be correct.

Your trial-and-error suggestion also makes sense.

from dtrt-indent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.