Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-25628

Autodetect indentation

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Editors
    • None

    Description

      The indentation settings in Qt Creator appear in different places - Text Editor -> Behavior, C++ -> Code Style, Qt Quick -> Code Style, and all of these can also be overridden in the project settings.

      This confuses many users. For example, when they edit a js file (we don't use Qml at all), they're expected to discover that the indentation settings are in Qt Quick.

      Moreover, a project can have different styles of indentation, so every time I save a file, I have to verify that I didn't break the indentation. For example, we indent with tabs in Qmake pro files, but shell scripts are indented with spaces (and some other shell scripts have tabs ).

      I want to suggest a new "auto" mode (that should be the default IMO) for all these settings (Text, C++ and Qt Quick). In this mode, the indentation will be automatically detected, it will appear in the status bar, allowing the user to quickly change it (and possibly persist the setting by filename).

      That's how indentation is configured in VS Code, and I find it very convenient.

      Auto detection can be basic. You can find the first line that starts with either a space or a tab. If it's a space, count the spaces until the first non-space. Otherwise, the indentation is with tabs.

      Advanced: The tab size can also be autodetected by heuristics. You can try finding a line that has tabs followed by spaces, and match it against the previous line. For example, if the previous line has an opening parenthesis and the text of the current line with the spaces can be aligned with this parenthesis, you can infer the tab size.

      For example:

      void func(int foo,
      <\t><\t>  int bar);
      

      We can determine that the tab size is probably 4.

      And of course the user can always change this easily if the detection was wrong.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            davschul David Schulz
            orgads Orgad Shaneh
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes