prettyprint.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 18 Dec 2018 13:06:21 +0200
changeset 2305 2d52dea2eee3
parent 2285 41b2a3652b35
permissions -rw-r--r--
Import data.
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
2285
41b2a3652b35 Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2228
diff changeset
    51
Pretty print XMLs in place::
41b2a3652b35 Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2228
diff changeset
    52
41b2a3652b35 Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2228
diff changeset
    53
  for f in *.xml; do xmllint -o $f --format $f; done
41b2a3652b35 Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2228
diff changeset
    54
41b2a3652b35 Pretty print XMLs in place.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2228
diff changeset
    55
In Emacs::
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-u M-| xmllint --format - <RET>
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
With Emacs and nxml you need introduce line-breaks and then::
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    61
  C-x h C-M-\
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    62
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    63
http://tidy.sourceforge.net
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    64
  Home page.
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    65
http://www.emacswiki.org/cgi-bin/wiki/tidy.el
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    66
  Emacs bindings.
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    67
http://xmlindent.sourceforge.net/
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    68
  xmlindent home page.
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    69
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    70
c/c++/java/c#.
1323
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
    71
==============
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    72
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    73
Artistic Style, astyle.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    74
-----------------------
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    75
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    76
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
    77
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    78
There are exist package for Cygwin, Debian.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    79
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    80
http://astyle.sourceforge.net/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    81
  home page
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
Uncrustify.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
-----------
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    86
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
    87
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    88
Exist package for Windows (binary from home page), Debian.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    89
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    90
http://uncrustify.sourceforge.net/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    91
  home page
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    92
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
jpplib.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    94
-------
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    95
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    96
Pretty Printer Library.
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    97
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    98
http://jpplib.sourceforge.net/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 2098
diff changeset
    99
  Home page.
1209
bb6eaf58a856 Pretty Printer Library.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   100
1323
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
   101
Perl.
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
   102
=====
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
   103
2096
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   104
http://perltidy.sourceforge.net/
bb22372fc204 Pretty print json.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   105
  Home page.
1323
1d94538d70c9 http://perltidy.sourceforge.net/
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1209
diff changeset
   106