Getting consistent indentation

Posted on
  • So I edit code in Sublime Text... and it puts tabs in for indentation. But the IDE, both Espruino's and Arduino's use 2 spaces.

    The switching back and forth between editing in the IDE's and Sublime Text results in all my source files slowly degrading to unreadability, as both sides argue over how to indent lines. Sublime tries to copy what the function already has, if it sees it, but neither of the IDEs do, and Sublime often gets confused. I've turned to copy/pasting tabs while working in IDEs, which is agonizing.

    How do other people deal with development tools that fight over how to indent?

    Is there any existing tool to fix indentations like this?

    What is the correct indentation to use, anyway? This seems like something that would be written of in the script ures, but surprisingly, it isn't one of the command ments...

    As for why I don't just use the IDE's, I find Sublime Text much more comfortable to read with the skinning + font options, plus it will rescue me if I don't save with hot_exit (while Espruino's behavior is inconsistent) and has a full-featured find/replace and can freely use the local file system. It lets me open multiple files at once (which I always need), and it doesn't have a left-hand side taking up screen space when I'm on the road writing without an espruino to send data to. The Espruino IDE is fine for tweaking and quick things, but for real coding I do it in sublime. The Arduino IDE's code editor is just a piece of insufferable shit (imo).

    Edit: Damnit, these forums won't let you italicize part of a word....

  • @DrAzzy, as you may have noticed, I use in my code the continuation comma on the continuation line - especially when doing the object-oriented look of code - for which I IDE picks up an indentation fight as well. More over, because JS is such a micro element language, that I put physical micro statements on one line to build a logical statement or macro statement. IDE picks that up and aligns the next lines indentation with the second+ of the previous line...

    This is all fine to get someone going with programming. With the screens getting wider and wider versus height, I cannot see enough code when putting just one micro thing on a line. Yes, I know, I can rotate the screen by 90 degrees and get it better for coding... (except for my laptop).

    Therefore, an editor should have at least two modes: support for all who need or like a thinking editor... and for others, just a frugal support of indentation... similar to Eclipse - even though Eclipse has it's issues as well of meddling with the indentation (when copying).

    But when just simple coding, it looks at the previous line and picks up the same indentation, and if a block has been opened, it adds a level. It even keeps the structure of the indentation which can be spaces and tabs, and it has a setting to use either tabs or spaces. If it gets to messy for me, I copy all I have into Eclipse or Textwrangler, do my advanced editing, and copy the whole thing back into IDE.

    In an earlier post I suggested to make the IDE look at the file time stamp on disk when getting the focus (and on interval timeout) , and if it has changed it would ask in a pop-up to update to what is on disk. This way any editor could run, and IDE would be used to upload and access board. It's not the best solution but way better than copying back and forth.

  • There are probably two settings that you'd want to change. I'm afraid they are hard coded in the ide so you'll have to change them in sublime though.

    There's a tab size - how big a tab character in a file is rendered. I use 4 in the IDE, and sublime may default to 8 which is why your files are breaking.

    Possibly I should change the ide as I think the default in most applications is 8.

    Then there's also how much of an indent you use, and the IDE uses 2. That would only have any effect when editing though.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Getting consistent indentation

Posted by Avatar for DrAzzy @DrAzzy

Actions