Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sogaiu/jandent
Alternate Indenter for Janet
https://github.com/sogaiu/jandent
indentation janet
Last synced: 6 days ago
JSON representation
Alternate Indenter for Janet
- Host: GitHub
- URL: https://github.com/sogaiu/jandent
- Owner: sogaiu
- License: mit
- Created: 2021-12-03T11:31:51.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-06T15:57:27.000Z (5 months ago)
- Last Synced: 2024-08-06T18:51:17.323Z (5 months ago)
- Topics: indentation, janet
- Language: Janet
- Homepage:
- Size: 95.7 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.spork
Awesome Lists containing this project
README
# jandent
Indenter for Janet
## Background
[spork/fmt](https://github.com/janet-lang/spork/blob/master/spork/fmt.janet)
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](https://github.com/andrewchambers/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.