Code Monkey home page Code Monkey logo

jandent's Introduction

jandent

Indenter for Janet

Background

spork/fmt is a compact elegant formatter for Janet by bakpakin.

It works by parsing source while discarding whitespace (except newlines) and then emits newly formatted source possibly removing some newlines and inserting whitespace in appropriate locations.

It's fast, but it might discard some whitespace-related information that one might prefer preserved.

What

jandent is based on spork/fmt but it attempts to preserve whitespace information to the right of indentation, e.g.

     (+ 1 1)   # a comment
^^^^^       ^^^
| |          |
| |          --- whitespace is preserved
| |              (right of indentation)
| |
|  --- indentation
|
 --- beginning of line

See the Details section below for further examples.

Usage

The API is the same as spork/fmt:

  • format-print
  • format
  • format-file

There is also a standalone executable named jindt, which is essentially jfmt for jandent.

Features

  • Leave whitespace to the right of indentation alone
  • Handle "data" tuples
  • Prevents closing delimiters from living in the left-most column
  • Doesn't remove newlines
  • Doesn't add newline at end
  • Treat comment as an "indent with 2 spaces" item

Details

spork/fmt's approach is quick but it can adversely impact some situations involving contiguous whitespace.

If you have columnar alignment like:

(let [ant   1
      tiger 2]
  (+ ant tiger))

At the time of this writing, spork/fmt will turn this into:

(let [ant 1
      tiger 2]
  (+ ant tiger))

Another situation has to do with whitespace before comments, like:

{:a 1   # this nice comment
 :b 20  # another comment
 :c 3}

Similarly, this will become:

{:a 1 # this nice comment
 :b 20 # another comment
 :c 3}

jandent should leave such whitespace intact.

Internal Things

The following changes were made to aid comprehension and exploration:

  • Use longer names in pegs
  • Some code reformatting
  • No top-level private defs or defns
  • Has a bit more commentary

Credits

  • andrewchambers - jfmt
  • bakpakin - spork/fmt
  • llmII - discussion

License

Code from spork/fmt was modified and included, thus spork's license applies.

jandent's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.