Home | Arachnophilia | Documentation |     Share This Page
The Code Beautifier
Arachnophilia is © Copyright 2015, P. Lutus.

Arachnophilia is CareWare

Launched with the system macro [BeautifyCode], and by default mapped to Ctrl-H, the code beautifier will indent your document (or a selection) very quickly and with a reasonable amount of sophistication. It will work with C, C++, Java, JavaScript (including JavaScript sections embedded in HTML pages), Perl and most other languages with syntax similar to C.

Here is an example:

Before:


  1 #include <iostream>
  2 #include <iomanip>
  3 
  4 int main()
  5 {
  6 const int rows = 8;
  7 const int columns = 16;
  8 char ch = ' ';
  9 for(int r = 0;r < rows;r++) {
 10 for(int c = 0;c < columns;c++) {
 11 cout << ch++ << ' ';
 12 }
 13 cout << '\n';
 14 }
 15 return 0;
 16 }
    
After:


  1 #include <iostream>
  2 #include <iomanip>
  3 
  4 int main()
  5 {
  6    const int rows = 8;
  7    const int columns = 16;
  8    char ch = ' ';
  9    for(int r = 0;r < rows;r++) {
 10       for(int c = 0;c < columns;c++) {
 11          cout << ch++ << ' ';
 12       }
 13       cout << '\n';
 14    }
 15    return 0;
 16 }
    
The new code beautifier differs from that in the previous version — it can handle ambiguous cases that lack braces, like the ever-popular switch/case/default statements that typically lack much formal structure for guidance:


  1 void act2(int choice)
  2 {
  3    cout << "You chose " << choice << ", so I am ";
  4    switch(choice) {
  5       case 1:
  6          cout << "starting the coffee maker...\n";
  7       break;
  8       case 2:
  9          cout << "starting World War III...\n";
 10       break;
 11       case 3:
 12          cout << "starting the pencil sharpener...\n";
 13       break;
 14       default:
 15          cout << "very confused...\n";
 16    }
 17 }
 18 
    
Code beautifier also checks for trivial kinds of errors as it works — it tallies various kinds of enclosing marks, like brackets, braces and parentheses. If it finds their numbers are unequal, it reports this to you when it completes its work.

Code beautifier, like most Arachnophilia functions, works with the entire document if no selection is made, or it beautifies just your selection if you have made one. This lets you test long, complex lines for internal consistency — just select that line and run the code beautifier on it. If the number of parentheses or other delimiters is unbalanced, it will report this.

 

Home | Arachnophilia | Documentation |     Share This Page