prettyprint.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 10 Feb 2018 01:49:07 +0200
changeset 2230 9e6ad6607a9e
parent 2228 837f1337c59b
child 2285 41b2a3652b35
permissions -rw-r--r--
Fixed formatting.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1334
9bf0d5a1f0cf Include common header with quick links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1326
diff changeset
     1
.. -*- coding: utf-8; -*-
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
===========================
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
 Pretty print source code.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
===========================
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
.. contents::
1905
fba288d59662 Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1334
diff changeset
     7
   :local:
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
1326
8aac6cb8518d About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1323
diff changeset
     9
About pretty printing.
8aac6cb8518d About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1323
diff changeset
    10
======================
8aac6cb8518d About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1323
diff changeset
    11
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
Code formatter, beautifier, pretty printer.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    14
http://en.wikipedia.org/wiki/Pretty-printer
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    15
  Wiki article on pretty printing.
1326
8aac6cb8518d About pretty printing.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1323
diff changeset
    16
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    17
json
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
====
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
2097
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    20
With ``jq`` (available in Debian/Cygwin)::
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    21
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    22
  $ jq  $FILE
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    23
  $ curl -s http://.../... | jq
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    24
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    25
By default ``jq`` produce colorized output in terminal!
614569553a08 Pretty print json with jq.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2096
diff changeset
    26
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    27
With Python 2.6+::
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    28
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    29
  $ python -m simplejson.tool  $FILE
2098
1a896c3e47c2 Alternative Python module to pretty-print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2097
diff changeset
    30
  $ python -m json.tool  $FILE
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    31
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    32
In terminal you can add color support with ``pygmentize``::
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    33
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    34
  $ curl -s http://.../... | python -m simplejson.tool | pygmentize -l json
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    35
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    36
xml
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    37
===
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    38
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    39
With tidy::
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
  $ tidy -xml -i -utf8 -o out.xml in.xml
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
or in Emacs::
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
  C-x h C-x <RET> c utf-8 <RET> C-u M-| tidy -q -xml -i -utf8 -
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    47
With xmllint::
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
  $ xmllint --format file.xml
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    51
or in Emacs::
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
  : C-x h C-u M-| xmllint --format - <RET>
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    55
With Emacs and nxml you need introduce line-breaks and then::
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57
  C-x h C-M-\
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    58
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    59
http://tidy.sourceforge.net
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    60
  Home page.
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    61
http://www.emacswiki.org/cgi-bin/wiki/tidy.el
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    62
  Emacs bindings.
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    63
http://xmlindent.sourceforge.net/
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    64
  xmlindent home page.
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    65
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    66
c/c++/java/c#.
1323
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
    67
==============
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    68
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    69
Artistic Style, astyle.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    70
-----------------------
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    71
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    72
A Free, Fast and Small Automatic Formatter for C, C++, C#, and Java Source Code.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    73
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    74
There are exist package for Cygwin, Debian.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    75
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    76
http://astyle.sourceforge.net/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    77
  home page
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    78
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    79
Uncrustify.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    80
-----------
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
Source Code Beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and VALA.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
Exist package for Windows (binary from home page), Debian.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    86
http://uncrustify.sourceforge.net/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    87
  home page
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    88
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    89
jpplib.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    90
-------
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    91
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    92
Pretty Printer Library.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    94
http://jpplib.sourceforge.net/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    95
  Home page.
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    96
1323
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
    97
Perl.
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
    98
=====
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
    99
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   100
http://perltidy.sourceforge.net/
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   101
  Home page.
1323
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
   102