dtrt-indent icon indicating copy to clipboard operation
dtrt-indent copied to clipboard

Support for different js-mode offset variables

Open notetiene opened this issue 3 years ago • 5 comments

Since js-mode has different offset variables, I was wondering if we could support those also.

Currently, if I use this file:

function test(arg) {
    switch(arg) {
      case 'foo':
          return 'bar'
      default:
          return 'baz'
    }
}

the guessed indentation is 2.

The problem is that js-switch-indent-offset was set to 2.

notetiene avatar May 18 '22 01:05 notetiene

Sure, we can support multiple variables (see the sgml-mode settings for an example). Feel free to submit a patch.

rrthomas avatar May 18 '22 08:05 rrthomas

Sorry, I'm not sure where to look for that. Do you mean web-mode offsets? The example I showed used an js-indent-level of 4 while having js-switch-indent-offset of 2.

notetiene avatar May 18 '22 17:05 notetiene

Sorry, I mean web-mode, yes. You can set multiple variables to the same value. Is that not enough for you?

rrthomas avatar May 18 '22 18:05 rrthomas

You can set multiple variables to the same value.

That makes sense. I was wondering if dtrt-indent could support multiple indentation values to multiple variables or at least guess the main indentation (js-indent-level) by excluding some contexts (like the switch block). That's currently not the case.

In order to do so, we would have to implement some parsing mechanism.

The issue isn't just related to js-mode (or derived modes), but also to web-mode and even c-mode as well. I'm not sure if you're open for language specific parser to fix heuristics.

notetiene avatar May 18 '22 19:05 notetiene

This sort of guessing seems to me better left to more specialised modes like smie-mode with smie-config-guess.

rrthomas avatar May 18 '22 21:05 rrthomas