# Fixing Whitespace Automatically¶

This page describes how to use Universal Indent GUI and Uncrustify to automatically fix whitespace such that code resembles the C++ Code Style more closely.

• Uncrustify is a command line program that is given a style definition and a source file and reformats the source file according to the configuration.
• Universal Indent GUI is a graphical front-end to Uncrustify with life preview that allows to manipulate the configuration and immediately see the results.

## Installing Universal Indent GUI¶

This one is pretty easy. On Ubuntu and other Linux systems, you can use the package management system to install the GUI and the reformatting programs. The Universal Indent GUI download page has binaries for Mac Os X and Windows.

## Preview with Universal Indent GUI¶

When started, the program will present you with a window like the following.

First, we set the indenter to Uncrustify.

Then, we load SeqAn’s uncrustify.cfg which is located in ${CHECKOUT}/misc. We can do so by selecting Indenter > Load Indenter Config File in the program menu. Then, we load a file from the SeqAn repository, for example apps/sak/sak.cpp. Now, we can toy around with the reformatter by checking Live Indent Preview. The settings on the left panel allow us to tweak the style to our liking. Any changes can be stored by selecting Indenter > Load Indenter Config File in the program menu. The source can also be stored, using File > Save Source File and File > Save Source File As…. ## Using The Command Line¶ Uncrustify can also be used via the command line. This is best done after a rough visual verification that the uncrustify.cfg yields works for your sources using the Universal Indenter UI. Work on a single file: # uncrustify -c${CHECKOUT}/misc/uncrustify.cfg --replace -f path/to/file.cpp


Batch work:

# find path/to -name '*.cpp' > list.txt
# uncrustify -c \${CHECKOUT}/misc/uncrustify.cfg --replace -F list.txt


## Automatically fix whitespaces in Xcode¶

Uncrustify can also be used directly from Xcode. With Xcode 4 Apple introduced so called “Behaviors” that can be executed using for instance keyboard shortcuts. To use Uncrustify you can add a new behavior in the Xcode Preferences (tab Behaviors) and select “Run”. Here you add the attached ruby script.

Note

The script does not uncrustify the currently opened source file but all source files that were changed in your current branch. Xcode does not provide the information which source file is currently opened.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.34370505809783936, "perplexity": 7381.658172980629}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-18/segments/1555578528430.9/warc/CC-MAIN-20190419220958-20190420002958-00136.warc.gz"}