Giter VIP home page Giter VIP logo

zprint's Introduction

zprint

zprint is a library and command line tool providing a variety of pretty printing capabilities for both Clojure code and Clojure/EDN structures. It can meet almost anyone's needs. As such, it supports a number of major source code formattng approaches.

cljdoc badge

See zprint:

  • classic zprint -- ignores whitespace in function definitions and formats code with a variety of heuristics to look as good as hand-formatted code (see examples)
  • respect blank lines -- similar to classic zprint, but blank lines inside of function defintions are retained, while code is otherwise formatted to look beautiful (see examples)
  • indent only -- very different from classic zprint -- no code ever changes lines, it is only correctly indented on whatever line it was already on (see examples)

In addition, zprint is very handy to use at the REPL.

Use zprint:

Get zprint:

Get something other than the default formatting:

Without learning how to configure zprint:

Maybe one of the existing "styles" will meet your needs. All you have to do is put {:style ...} on the command line or as the third argument to a zprint call. For example, {:style :community} or {:style :respect-bl}.

Some commonly used styles:

Learn how to alter zprint's formatting behavior:

I want to change...

Usage

cljdoc badge

Clojure 1.9, 1.10, 1.10.1:

Leiningen (via Clojars)

Clojars Project

Clojurescript:

zprint has been tested in each of the following environments:

  • Clojurescript 1.10.520
    • figwheel 0.5.19
    • shadow-cljs 2.8.62
  • lumo 1.10.1
  • planck 2.24.0

It requires tools.reader at least 1.0.5, which all of the environments above contain.

Clojure 1.8:

The last zprint release built with Clojure 1.8 was [zprint "0.4.15"].

In addition to the zprint dependency, you also need to include the following library when using Clojure 1.8:

[clojure-future-spec "1.9.0-alpha17"]

The zprint Reference

Contributors

A number of folks have contributed to zprint, not all of whom show up on GitHub because I have integrated the code or suggestions manually. Thanks for all of the great contributions!

  • --url and --url-only: @coltnz
  • Suggestion/encouragement to implement :respect-bl: @griffis
  • :option-fn and :fn-format for enhanced vector formatting: @milankinen
  • Fixed missing require in spec.cljc: @Quezion
  • Corrected readme: @griffis
  • Fixed nested reader conditional: @rgould1
  • Clarified and added useful example for clj usage: @bherrmann7
  • Suggested fix for international chars and graalVM native image: @huahaiy

Thanks to everyone who has contributed fixes as well as everyone who has reported an issue. I really appreciate all of the help making zprint better for everybody!

Acknowledgements

At the core of zprint is the rewrite-clj library by Yannick Scherer, which will parse Clojure source into a zipper. This is a great library! I would not have attempted zprint if rewrite-clj didn't exist to build upon. The Clojurescript port relies on Magnus Rundberget's port of rewrite-clj to Clojurescript, rewrite-cljs. It too worked with no issues when porting to Clojurescript!

License

Copyright © 2016-2020 Kim Kinnear

Distributed under the MIT License. See the file LICENSE for details.

zprint's People

Contributors

kkinnear avatar mynomoto avatar arichiardi avatar bhurlow avatar coltnz avatar ekinnear avatar martinklepsch avatar milankinen avatar pesterhazy avatar quezion avatar vemv avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.