Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Remove empty lines in editor - code beautifier - REPOST



  • I am reposing SAME request instead of tagging it on the old thread.

    My intend is still same - find a WORKING solution to remove empty lines in editor - (C/C++) code beautifier.

    Since I have used "artistic" style I would prefer that as a solution.

    Here is a summary of what transpired since my initial request.

    1. Qt IDE still has no option to "remove empty lines " from editor.
    2. There MAY BE "plug-ins" beautifiers with such option. The key word is
      MAYBE.
    3. There is a link to "astyle", but few months ago somebody posted a note it is no longer actively maintained . ? Not a good incentive to download etc...

    http://astyle.sourceforge.net/

    So the bottom line - again - can anybody point me to an integrated solution with Qt?
    It does not matter what it is called - plug-in etc. - but it has to have an option to remove empty lines from editor.

    Yes, I prefer precompiled Linux version, I am not that good in "configuring".


  • Lifetime Qt Champion

    Moved to tools since it's a question wrt QtCreator.


  • Lifetime Qt Champion

    Hi
    Astyle is a fine formatter. used it for a decade.
    Yes its not been updated much but still does a better job than clang-format and all the new ones.

    You can use it with
    --delete-empty-lines
    (and other formatting options you want )

    alt text



  • @mrjj Thanks for your post.
    Can you instruct me how to ADD it to QtCreator?

    I got as far as "add plug-in" and obviously going it wrong .
    It sure looks Qt is adding Astyle for its own plug-in data not from the file downloaded.

    03b20562-5fe5-43d9-91c2-adc73bac404a-image.png


  • Lifetime Qt Champion

    @AnneRanch
    Hi
    well its both a plugin and a download.
    1:
    Goto About->plugins

    then we get the (Install plugin window)

    alt text

    I then search for "be" to get the beautifier plugin.
    I enable that and restart producer

    2:
    then i goto
    https://sourceforge.net/projects/astyle/files/
    and download the code (if linux) and build the exe. (easy)
    OR
    sudo apt-get install astyle
    (its often in the repro)

    3:
    The in Creator
    I go to tools -> Options

    alt text

    Now you need to tell it where to find the "exe".

    Also we need to add Formatting settings.
    So we press Add to make a new "config" and use this.

    I use

    --indent-switches
    --indent-col1-comments
    --pad-oper
    --align-pointer=type
    --indent=spaces=2
    --max-instatement-indent=80
    --style=attach
    --pad-comma
    --add-braces
    --delete-empty-lines
    

    but you should ofc change it to fit your style.
    Many dont like --add-braces
    as it will add {} to a single line if which some find annoying and so on.

    Press ok. and it should work now.

    4: This is optional :)
    Assign a key to format the current file

    in Tools->options
    alt text

    I hope this make sense and you get it running :)



  • @mrjj Thanks appreciate all - especially the add to format current file.
    Doing it Qt way gets tiresome...

    75e35bfc-8019-48b7-b624-a85b4b19902c-image.png

    Just because I tried to add some text to "documentation" but it won't take anything.

    It gets little hard to reply and implement it , so I'll get back to you when I get it all put together.

    As another matter -
    since you mentioned brackets
    I like to cut and paste - there is a trick to put mouse behind starting bracket and "select until next bracket " .

    I have been looking for similar to actually select between #iifdef .. #endif . I know the Qt editor puts different background color to show the #ifdef... #endif but I like to copy such range.


Log in to reply