yasi


Nameyasi JSON
Version 2.1.2 PyPI version JSON
download
home_pagehttps://github.com/nkmathew/yasi-sexp-indenter
SummaryA dialect aware s-expression indenter
upload_time2020-05-22 18:03:04
maintainer
docs_urlNone
authorMathew Ng'etich
requires_python
license
keywords scheme formatter newlisp beautifier clojure lisp indenter
VCS
bugtrack_url
requirements argparse backports.functools-lru-cache colorama docutils autopep8 flake8 pycodestyle pylint tox virtualenv
Travis-CI
coveralls test coverage No coveralls.
            [![Build Status][2]][3]
[![Latest tag][4]][5]
[![pypi downloads][6]][7]
[![Supported versions][8]][5]
[![Supported implementations][9]][5]

## yasi - yet another s-expression indenter

- [Introduction](#introduction)
- [Installation](#installation)
- [Features](#features)
- [Command Line Arguments](#command-line-arguments)
- [Hanging Indentation](#hanging-indentation)
- [Customization](#customization)
- [About the default indent](#about-the-default-indent)
- [What yasi does not handle](#what-yasi-does-not-handle)
- [Modifications to lispindent](#modifications-to-lispindent)
- [Editor Integration](#editor-integration)
- [Lispindent2 Issues](#lispindent2-issues)
- [lispindent2 Command Line Options](#lispindent2-command-line-options)

### Introduction

yasi is a dialect-aware s-expression indenter that tries to improve on [Dorai's
indenter][0] and *Vim's* built in indenter. It can handle *Common Lisp*, *Clojure*,
*Scheme* and *newLISP* code and their unique syntaxes.

It's mainly a batch mode indenter inspired by Dorai's [lispindent.lisp][1]
that was written first in *Python* and later translated to *newLISP*.  

Its style of indentation is very close to that of *lispindent.lisp* and tries to
follow [these style guidelines][0] where reasonable.

It should find most use with programmers who use any other editor other than Emacs
which provides excellent indentation for lisp-like forms and s-expressions out of
the box.

I made this because there weren't any good enough tools out there that could indent
the code I would copy/paste and run from tutorials when I was starting out with Lisp.

### Installation

From pypi:

    pip install --upgrade yasi

Locally(latest changes):

    git clone https://github.com/nkmathew/yasi-sexp-indenter.git
    cd yasi-sexp-indenter
    make install

### Features

*yasi's* indentation relies heavily on regular expressions that give it an edge
over its counterpart *lispindent.lisp*. Its features include:

+ Support for the different mainstream Lisps out there giving you the correct
  indentation of a form according to the dialect's syntax/semantic. e.g.
  The `do` keyword which is a looping construct in *Common Lisp* and sequential
  execution in *Clojure*. The keyword should look like this in the two dialects:

```lisp
;; In Common Lisp
(do ((j 0 (+ j 1)))
    (nil)                       ;Do forever.
  (format t "~%Input ~D:" j)
  (let ((item (read)))
    (if (null item) (return)   ;Process items until NIL seen.
      (format t "~&Output ~D: ~S" j item))))
```

```Clojure
;; In Clojure
(do
 (println "LOG: Computing...")
 (+ 1 1))
```

+ Ability to trim extraneous whitespace and compact code

+ Issues warnings for possible errors in code like unmatched brackets and unclosed
  strings

+ Correct indentation of user defined macros

+ Supports additional keywords through a config file in the current or home
  directory

+ Correct indentation of `flets` and `labels`, something that doesn't come out of
  the box even in Emacs

+ Indentation from standard input

+ The python version can output a unified diff between the initial and indented code

### Command Line Arguments

    usage: yasi [-h] [-nc] [-nb] [-nm] [--diff] [-nw] [-nr] [--no-output] [-c]
                [-ne] [-o OUTPUT_FILE] [--tab TAB_SIZE] [--dialect DIALECT] [-v]
                [-suffix BACKUP_SUFFIX] [-bd BACKUP_DIR] [-is INDENT_SIZE]
                [-di DEFAULT_INDENT] [-ic] [-uni] [-parallel]
                [files [files ...]]

    Dialect-aware s-expression indenter

    positional arguments:
      files                 List of files to be indented. Will indent from
                            standard input if no files are specified

    optional arguments:
      -h, --help            show this help message and exit
      -nc, --no-compact, --nc
                            Do not compact the code, just indent
      -nb, --no-backup, --nb
                            Do not create a backup file even if --backup-dir is
                            specified
      -nm, --no-modify, --nm
                            Do not modify the file
      --diff, -diff         Prints unified diff of the initial and final result
      -nw, --no-warning, --nw
                            Do not display warnings
      -nr, --no-rc, --nr    Ignore any rc files in the current or home folder
      --no-output, -no-output
                            Suppress output of the indented code
      -c, --color, -color   Display diff text in color
      -ne, --no-exit, --ne  Instructs the program not to exit when a warning is
                            raised.
      -o OUTPUT_FILE        Path/name of output file
      --tab TAB_SIZE, -tab TAB_SIZE
                            Indent with tabs using the specified tabwidth. A tab
                            is assumed equal to 4 spaces by default when expanding
                            the tabs in the input file
      --dialect DIALECT, -dialect DIALECT
                            Use Scheme keywords
      -v, --version         Prints script version
      -suffix BACKUP_SUFFIX, --suffix BACKUP_SUFFIX
                            Backup file suffix
      -bd BACKUP_DIR, --backup-dir BACKUP_DIR, --bd BACKUP_DIR, -backup-dir BACKUP_DIR
                            The directory where the backup file is to be written
      -is INDENT_SIZE, --indent-size INDENT_SIZE, --is INDENT_SIZE
                            The number of spaces per indent
      -di DEFAULT_INDENT, --default-indent DEFAULT_INDENT, --di DEFAULT_INDENT
                            The indent level to be used in case a function's
                            argument is in the next line. Vim uses 2, the most
                            common being 1.
      -ic, --indent-comments, --ic
                            If true, comment lines will be indented possibly
                            messing with any deliberate comment layout
      -uni, --uniform, -uniform, --uni
                            Dictates whether the if-clause and else-clause of an
                            if-likeblock should have the same indent level.
      -parallel, --parallel
                            Process the given files in parallel


### Hanging Indentation
This is where the indented code block is not flush with the left margin. Lispindent
does this by default although differently to the way it's implemented in yasi.
The effect is obtained by passing **--no-compact** to the script.
Here's how hanging indentation in *lispindent* and yasi differs:

Initial code:

```lisp
;; Comment
                    (if (not (empty? macro-name))
                    (push (list macro-name KEYWORD1) keyword-lst)
                    nil)

        (if (not (empty? macro-name))
        (push (list macro-name KEYWORD1) keyword-lst)
        nil)

                (exit)
```

Calling yasi on the file with **--no-compact**:

```lisp
;; Comment
                    (if (not (empty? macro-name))
                        (push (list macro-name KEYWORD1) keyword-lst)
                      nil)

        (if (not (empty? macro-name))
            (push (list macro-name KEYWORD1) keyword-lst)
          nil)

                (exit)
```

How *lispindent* does it(the number of spaces at the start of first block defines
where the rest of the blocks in the file will start):

```lisp
;; Comment
                    (if (not (empty? macro-name))
                        (push (list macro-name KEYWORD1) keyword-lst)
                      nil)
                    
                    (if (not (empty? macro-name))
                        (push (list macro-name KEYWORD1) keyword-lst)
                      nil)
                    
                    (exit)

```

### Customization

Customization is done similarly to the way it's done in *lispindent* - keywords are
associated with numbers that determine the next line's indentation level.

The additional keywords are defined in a **.yasirc.json** file placed in the current
working directory of in the home folder. Should there be configuration files in both
directories the one in the current working directory will be preferred.

A typical config file looks like this:

```javascript
{
  "scheme": {
    "do": 2,
    "if": 2
  },
  "lisp": {
    "do": 2,
    "if": 2
  },
  "clojure": {
    "do": 2,
    "if": 2
  },
  "newlisp": {
    "do": 2,
    "if": 2
  }
}
```


The numbers are described below(assuming standard indentation size of 2 spaces):

  + **0** - Associating a keyword with zero turns it into a normal function i.e
    removes keywordness

```lisp
(do-the-boogie (= 12 44)
               (print "if clause")
               (print "else clause"))
```

  + **1** - Causes the subforms of the function to be indented uniformly by a unit
    indentation size(which can be changed)

```lisp
(do-the-boogie (= 12 44)
  (print "if clause")
  (print "else clause"))
```

  + **2** - Distinguishes the first subform by giving it a greater indentation than
    the rest of the subforms the same way the standard if expression is indented.
    The first subform has twice the indentation size as the rest.

```lisp
(do-the-boogie (= 12 44)
    (print "if clause")
  (print "else clause"))
```

  + **3** - Subforms will be indented uniformly by twice the indentation size

```lisp
(do-the-boogie (= 12 44)
    (print "if clause")
    (print "else clause"))
```

  + **4** - Indents by a unit like a 1-keyword but also its local functions

```lisp
(letfn [(six-times [y]
          (* (twice y) 3))
        (twice [x]
          (* x 2))]
  (println "Twice 15 =" (twice 15))
  (println "Six times 15 =" (six-times 15)))
```

  The standard indentation(assuming `letfn` is just another function) would be:

```lisp
(letfn [(six-times [y]
                   (* (twice y) 3))
        (twice [x]
               (* x 2))]
  (println "Twice 15 =" (twice 15))
  (println "Six times 15 =" (six-times 15)))
```


#### About the default indent

The *--default-indent* comes in in expressions whose subforms usually start in the
subsequent lines. Like in a `cond` expression:

```lisp
(cond
 ((> this that) 'Yes)
 ((= those these) 'No))
```

This above result would be the standard/expected indentation. However one might
prefer to have the subforms to start two spaces past the head of the expression like
this.

```lisp
(cond
  ((> newLISP CL) 'Yes)
  ((= Clojure Lisp) 'No))
```

This is *Vim's* default style of indentation.
That option enables you to specify the amount you want, for example to achieve the
style above, you pass the parameter like so:

```shell
    yasi.py test.lisp --lisp --default-indent 2
```

----------

### What yasi does not handle

There are some syntaxes used in some dialects of Scheme that didn't seem worth the
effort implementing. An example is *MzScheme* and *Gauche's* use of `#//` or `#[]`
for regular expressions.

#### Modifications to lispindent

I made a couple of modifications to *lispindent.lisp* and renamed it to
*lispindent2.lisp*. The changes include:

+ Added comments for some sections of the program that took me time to understand

+ It can now indent files from the command line without the need to redirect file
  contents to the program. The original one was purely intended to be used as a
  filter script indenting only from standard input.

+ *lispindent2.lisp* indents *Clojure's* *vectors* and *sets* better, i.e with an
 indentation level of 1, without affecting *Lisp's* or *Scheme's indentation*. It
  uses the file's extension to determine if it's looking at *Clojure* code.
  e.g.

```Clojure
;; lispindent2.lisp's indentation
(print {define "The keyword does not affect indentation"
    })
```

```Clojure
;; lispindent.lisp's indentation
(print {define "The keyword does not affect indentation"
   })
```

+ *lispindent2.lisp* ignores any code in a multiline comment and won't  be affected
  by any unclosed brackets inside the comment like the original version.
  Unfortunately, its method of detecting multiline comments is rather  naive and
  introduces a bug in the code. Refer to its issues below.

+ *lispindent2.lisp* writes files using *LF* line endings be default. It's less
  irritating than *CRLF* endings which usually light up in an annoying way in *Vim*.

#### Editor Integration

yasi's ability to format code from standard input makes it a suitable candidate for
the `equalprg` setting in *Vim*. Add this in your **.vimrc** and you're good to go.

```vim
au filetype clojure,lisp,scheme,newlisp setlocal equalprg=yasi.py\ --indent-comments
```

You can then indent a function/block by providing the motion after the `=` sign
e.g `=%`

You can also checkout these other projects for proper integration without invoking
it externally as a filter script for example:

  + *Vim* plugin: https://github.com/nkmathew/vim-newlisp-yasi
  + Sublime Text 2/3 plugin: https://github.com/nkmathew/sublime-yasi

#### lispindent2 Issues

I inadvertently added a bug in an attempt to prevent it from evaluating brackets
inside multiline comments in Common Lisp and symbols with whitespace in Scheme.

It uses the pipe character(|) to track whether the comment it's still in a multiline
comment meaning an odd number of pipes in a multiline comment will yield a wrong
indentation e.g.:

```lisp
#|*******************************************************************|
 |   This is a multiline comment that will trip the indenter         |
 |   because the odd number of pipes will cause `multiline-commentp` |
 |   to be true after this comment. It means the rest of the code    |
 |   won't be indented because it thinks it's still in a comment.    |
          Total pipes=11(odd)
 |#
 (print (cons
    'Hello ;; This line and the one below won't change
    'World
        ))
```

I don't find this to be a major issue because multiline comments are rarely used,
the common use case being to comment out regions of code when debugging.

*lispindent2.lisp* uses the *Lisp* reader function `read-from-string` to get lisp
forms and atoms from the read string.

The downside of this is that `read-from-string` will fail when the code in the
string is 'malformed'. For example, if it finds that the dot operator used for
consing in *Common Lisp* comes after the opening bracket, it will raise a fatal
error. This means that any *Clojure* code that tries to use the dot operator to
access a class method will not be indented because of the error. An example is this
code:

```Clojure
(defmacro chain
  ([x form] `(. ~x ~form))
  ([x form & more] `(chain (. ~x ~form) ~@more)))
```

*lispindent2.lisp* uses the `ignore-errors` macro as a workaround. Doing that means
that it can't run in *GNU Common Lisp* because it doesn't have the macro.

#### lispindent2 Command Line Options

    +---------------------------------------------------------------------------+
    |   Usage:  lispindent2.lisp [[<file>] [--no-modify] [--no-output]]         |
    |           --no-output ;; Don't output the indented code, false by default |
    |           --no-modify ;; Don't modify the file, false by default          |
    +---------------------------------------------------------------------------+

[0]: https://github.com/ds26gte/scmindent
[1]: https://github.com/ds26gte/scmindent/blob/master/lispindent.lisp
[2]: https://travis-ci.org/nkmathew/yasi-sexp-indenter.svg?branch=master
[3]: https://travis-ci.org/nkmathew/yasi-sexp-indenter
[4]: https://img.shields.io/github/tag/nkmathew/yasi-sexp-indenter.svg
[5]: https://github.com/nkmathew/yasi-sexp-indenter/releases
[6]: https://img.shields.io/pypi/dm/yasi.svg
[7]: https://pypi.python.org/pypi/yasi
[8]: https://img.shields.io/pypi/pyversions/yasi
[9]: https://img.shields.io/pypi/implementation/yasi
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nkmathew/yasi-sexp-indenter",
    "name": "yasi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "scheme,formatter,newlisp,beautifier,clojure,lisp,indenter",
    "author": "Mathew Ng'etich",
    "author_email": "kipkoechmathew@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3a/58/e369cc04c658f6fbf53de6f05163fc6adbb16694ff7ae56886875fe30c07/yasi-2.1.2.tar.gz",
    "platform": "",
    "description": "[![Build Status][2]][3]\n[![Latest tag][4]][5]\n[![pypi downloads][6]][7]\n[![Supported versions][8]][5]\n[![Supported implementations][9]][5]\n\n## yasi - yet another s-expression indenter\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Features](#features)\n- [Command Line Arguments](#command-line-arguments)\n- [Hanging Indentation](#hanging-indentation)\n- [Customization](#customization)\n- [About the default indent](#about-the-default-indent)\n- [What yasi does not handle](#what-yasi-does-not-handle)\n- [Modifications to lispindent](#modifications-to-lispindent)\n- [Editor Integration](#editor-integration)\n- [Lispindent2 Issues](#lispindent2-issues)\n- [lispindent2 Command Line Options](#lispindent2-command-line-options)\n\n### Introduction\n\nyasi is a dialect-aware s-expression indenter that tries to improve on [Dorai's\nindenter][0] and *Vim's* built in indenter. It can handle *Common Lisp*, *Clojure*,\n*Scheme* and *newLISP* code and their unique syntaxes.\n\nIt's mainly a batch mode indenter inspired by Dorai's [lispindent.lisp][1]\nthat was written first in *Python* and later translated to *newLISP*.  \n\nIts style of indentation is very close to that of *lispindent.lisp* and tries to\nfollow [these style guidelines][0] where reasonable.\n\nIt should find most use with programmers who use any other editor other than Emacs\nwhich provides excellent indentation for lisp-like forms and s-expressions out of\nthe box.\n\nI made this because there weren't any good enough tools out there that could indent\nthe code I would copy/paste and run from tutorials when I was starting out with Lisp.\n\n### Installation\n\nFrom pypi:\n\n    pip install --upgrade yasi\n\nLocally(latest changes):\n\n    git clone https://github.com/nkmathew/yasi-sexp-indenter.git\n    cd yasi-sexp-indenter\n    make install\n\n### Features\n\n*yasi's* indentation relies heavily on regular expressions that give it an edge\nover its counterpart *lispindent.lisp*. Its features include:\n\n+ Support for the different mainstream Lisps out there giving you the correct\n  indentation of a form according to the dialect's syntax/semantic. e.g.\n  The `do` keyword which is a looping construct in *Common Lisp* and sequential\n  execution in *Clojure*. The keyword should look like this in the two dialects:\n\n```lisp\n;; In Common Lisp\n(do ((j 0 (+ j 1)))\n    (nil)                       ;Do forever.\n  (format t \"~%Input ~D:\" j)\n  (let ((item (read)))\n    (if (null item) (return)   ;Process items until NIL seen.\n      (format t \"~&Output ~D: ~S\" j item))))\n```\n\n```Clojure\n;; In Clojure\n(do\n (println \"LOG: Computing...\")\n (+ 1 1))\n```\n\n+ Ability to trim extraneous whitespace and compact code\n\n+ Issues warnings for possible errors in code like unmatched brackets and unclosed\n  strings\n\n+ Correct indentation of user defined macros\n\n+ Supports additional keywords through a config file in the current or home\n  directory\n\n+ Correct indentation of `flets` and `labels`, something that doesn't come out of\n  the box even in Emacs\n\n+ Indentation from standard input\n\n+ The python version can output a unified diff between the initial and indented code\n\n### Command Line Arguments\n\n    usage: yasi [-h] [-nc] [-nb] [-nm] [--diff] [-nw] [-nr] [--no-output] [-c]\n                [-ne] [-o OUTPUT_FILE] [--tab TAB_SIZE] [--dialect DIALECT] [-v]\n                [-suffix BACKUP_SUFFIX] [-bd BACKUP_DIR] [-is INDENT_SIZE]\n                [-di DEFAULT_INDENT] [-ic] [-uni] [-parallel]\n                [files [files ...]]\n\n    Dialect-aware s-expression indenter\n\n    positional arguments:\n      files                 List of files to be indented. Will indent from\n                            standard input if no files are specified\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -nc, --no-compact, --nc\n                            Do not compact the code, just indent\n      -nb, --no-backup, --nb\n                            Do not create a backup file even if --backup-dir is\n                            specified\n      -nm, --no-modify, --nm\n                            Do not modify the file\n      --diff, -diff         Prints unified diff of the initial and final result\n      -nw, --no-warning, --nw\n                            Do not display warnings\n      -nr, --no-rc, --nr    Ignore any rc files in the current or home folder\n      --no-output, -no-output\n                            Suppress output of the indented code\n      -c, --color, -color   Display diff text in color\n      -ne, --no-exit, --ne  Instructs the program not to exit when a warning is\n                            raised.\n      -o OUTPUT_FILE        Path/name of output file\n      --tab TAB_SIZE, -tab TAB_SIZE\n                            Indent with tabs using the specified tabwidth. A tab\n                            is assumed equal to 4 spaces by default when expanding\n                            the tabs in the input file\n      --dialect DIALECT, -dialect DIALECT\n                            Use Scheme keywords\n      -v, --version         Prints script version\n      -suffix BACKUP_SUFFIX, --suffix BACKUP_SUFFIX\n                            Backup file suffix\n      -bd BACKUP_DIR, --backup-dir BACKUP_DIR, --bd BACKUP_DIR, -backup-dir BACKUP_DIR\n                            The directory where the backup file is to be written\n      -is INDENT_SIZE, --indent-size INDENT_SIZE, --is INDENT_SIZE\n                            The number of spaces per indent\n      -di DEFAULT_INDENT, --default-indent DEFAULT_INDENT, --di DEFAULT_INDENT\n                            The indent level to be used in case a function's\n                            argument is in the next line. Vim uses 2, the most\n                            common being 1.\n      -ic, --indent-comments, --ic\n                            If true, comment lines will be indented possibly\n                            messing with any deliberate comment layout\n      -uni, --uniform, -uniform, --uni\n                            Dictates whether the if-clause and else-clause of an\n                            if-likeblock should have the same indent level.\n      -parallel, --parallel\n                            Process the given files in parallel\n\n\n### Hanging Indentation\nThis is where the indented code block is not flush with the left margin. Lispindent\ndoes this by default although differently to the way it's implemented in yasi.\nThe effect is obtained by passing **--no-compact** to the script.\nHere's how hanging indentation in *lispindent* and yasi differs:\n\nInitial code:\n\n```lisp\n;; Comment\n                    (if (not (empty? macro-name))\n                    (push (list macro-name KEYWORD1) keyword-lst)\n                    nil)\n\n        (if (not (empty? macro-name))\n        (push (list macro-name KEYWORD1) keyword-lst)\n        nil)\n\n                (exit)\n```\n\nCalling yasi on the file with **--no-compact**:\n\n```lisp\n;; Comment\n                    (if (not (empty? macro-name))\n                        (push (list macro-name KEYWORD1) keyword-lst)\n                      nil)\n\n        (if (not (empty? macro-name))\n            (push (list macro-name KEYWORD1) keyword-lst)\n          nil)\n\n                (exit)\n```\n\nHow *lispindent* does it(the number of spaces at the start of first block defines\nwhere the rest of the blocks in the file will start):\n\n```lisp\n;; Comment\n                    (if (not (empty? macro-name))\n                        (push (list macro-name KEYWORD1) keyword-lst)\n                      nil)\n                    \n                    (if (not (empty? macro-name))\n                        (push (list macro-name KEYWORD1) keyword-lst)\n                      nil)\n                    \n                    (exit)\n\n```\n\n### Customization\n\nCustomization is done similarly to the way it's done in *lispindent* - keywords are\nassociated with numbers that determine the next line's indentation level.\n\nThe additional keywords are defined in a **.yasirc.json** file placed in the current\nworking directory of in the home folder. Should there be configuration files in both\ndirectories the one in the current working directory will be preferred.\n\nA typical config file looks like this:\n\n```javascript\n{\n  \"scheme\": {\n    \"do\": 2,\n    \"if\": 2\n  },\n  \"lisp\": {\n    \"do\": 2,\n    \"if\": 2\n  },\n  \"clojure\": {\n    \"do\": 2,\n    \"if\": 2\n  },\n  \"newlisp\": {\n    \"do\": 2,\n    \"if\": 2\n  }\n}\n```\n\n\nThe numbers are described below(assuming standard indentation size of 2 spaces):\n\n  + **0** - Associating a keyword with zero turns it into a normal function i.e\n    removes keywordness\n\n```lisp\n(do-the-boogie (= 12 44)\n               (print \"if clause\")\n               (print \"else clause\"))\n```\n\n  + **1** - Causes the subforms of the function to be indented uniformly by a unit\n    indentation size(which can be changed)\n\n```lisp\n(do-the-boogie (= 12 44)\n  (print \"if clause\")\n  (print \"else clause\"))\n```\n\n  + **2** - Distinguishes the first subform by giving it a greater indentation than\n    the rest of the subforms the same way the standard if expression is indented.\n    The first subform has twice the indentation size as the rest.\n\n```lisp\n(do-the-boogie (= 12 44)\n    (print \"if clause\")\n  (print \"else clause\"))\n```\n\n  + **3** - Subforms will be indented uniformly by twice the indentation size\n\n```lisp\n(do-the-boogie (= 12 44)\n    (print \"if clause\")\n    (print \"else clause\"))\n```\n\n  + **4** - Indents by a unit like a 1-keyword but also its local functions\n\n```lisp\n(letfn [(six-times [y]\n          (* (twice y) 3))\n        (twice [x]\n          (* x 2))]\n  (println \"Twice 15 =\" (twice 15))\n  (println \"Six times 15 =\" (six-times 15)))\n```\n\n  The standard indentation(assuming `letfn` is just another function) would be:\n\n```lisp\n(letfn [(six-times [y]\n                   (* (twice y) 3))\n        (twice [x]\n               (* x 2))]\n  (println \"Twice 15 =\" (twice 15))\n  (println \"Six times 15 =\" (six-times 15)))\n```\n\n\n#### About the default indent\n\nThe *--default-indent* comes in in expressions whose subforms usually start in the\nsubsequent lines. Like in a `cond` expression:\n\n```lisp\n(cond\n ((> this that) 'Yes)\n ((= those these) 'No))\n```\n\nThis above result would be the standard/expected indentation. However one might\nprefer to have the subforms to start two spaces past the head of the expression like\nthis.\n\n```lisp\n(cond\n  ((> newLISP CL) 'Yes)\n  ((= Clojure Lisp) 'No))\n```\n\nThis is *Vim's* default style of indentation.\nThat option enables you to specify the amount you want, for example to achieve the\nstyle above, you pass the parameter like so:\n\n```shell\n    yasi.py test.lisp --lisp --default-indent 2\n```\n\n----------\n\n### What yasi does not handle\n\nThere are some syntaxes used in some dialects of Scheme that didn't seem worth the\neffort implementing. An example is *MzScheme* and *Gauche's* use of `#//` or `#[]`\nfor regular expressions.\n\n#### Modifications to lispindent\n\nI made a couple of modifications to *lispindent.lisp* and renamed it to\n*lispindent2.lisp*. The changes include:\n\n+ Added comments for some sections of the program that took me time to understand\n\n+ It can now indent files from the command line without the need to redirect file\n  contents to the program. The original one was purely intended to be used as a\n  filter script indenting only from standard input.\n\n+ *lispindent2.lisp* indents *Clojure's* *vectors* and *sets* better, i.e with an\n indentation level of 1, without affecting *Lisp's* or *Scheme's indentation*. It\n  uses the file's extension to determine if it's looking at *Clojure* code.\n  e.g.\n\n```Clojure\n;; lispindent2.lisp's indentation\n(print {define \"The keyword does not affect indentation\"\n    })\n```\n\n```Clojure\n;; lispindent.lisp's indentation\n(print {define \"The keyword does not affect indentation\"\n   })\n```\n\n+ *lispindent2.lisp* ignores any code in a multiline comment and won't  be affected\n  by any unclosed brackets inside the comment like the original version.\n  Unfortunately, its method of detecting multiline comments is rather  naive and\n  introduces a bug in the code. Refer to its issues below.\n\n+ *lispindent2.lisp* writes files using *LF* line endings be default. It's less\n  irritating than *CRLF* endings which usually light up in an annoying way in *Vim*.\n\n#### Editor Integration\n\nyasi's ability to format code from standard input makes it a suitable candidate for\nthe `equalprg` setting in *Vim*. Add this in your **.vimrc** and you're good to go.\n\n```vim\nau filetype clojure,lisp,scheme,newlisp setlocal equalprg=yasi.py\\ --indent-comments\n```\n\nYou can then indent a function/block by providing the motion after the `=` sign\ne.g `=%`\n\nYou can also checkout these other projects for proper integration without invoking\nit externally as a filter script for example:\n\n  + *Vim* plugin: https://github.com/nkmathew/vim-newlisp-yasi\n  + Sublime Text 2/3 plugin: https://github.com/nkmathew/sublime-yasi\n\n#### lispindent2 Issues\n\nI inadvertently added a bug in an attempt to prevent it from evaluating brackets\ninside multiline comments in Common Lisp and symbols with whitespace in Scheme.\n\nIt uses the pipe character(|) to track whether the comment it's still in a multiline\ncomment meaning an odd number of pipes in a multiline comment will yield a wrong\nindentation e.g.:\n\n```lisp\n#|*******************************************************************|\n |   This is a multiline comment that will trip the indenter         |\n |   because the odd number of pipes will cause `multiline-commentp` |\n |   to be true after this comment. It means the rest of the code    |\n |   won't be indented because it thinks it's still in a comment.    |\n          Total pipes=11(odd)\n |#\n (print (cons\n    'Hello ;; This line and the one below won't change\n    'World\n        ))\n```\n\nI don't find this to be a major issue because multiline comments are rarely used,\nthe common use case being to comment out regions of code when debugging.\n\n*lispindent2.lisp* uses the *Lisp* reader function `read-from-string` to get lisp\nforms and atoms from the read string.\n\nThe downside of this is that `read-from-string` will fail when the code in the\nstring is 'malformed'. For example, if it finds that the dot operator used for\nconsing in *Common Lisp* comes after the opening bracket, it will raise a fatal\nerror. This means that any *Clojure* code that tries to use the dot operator to\naccess a class method will not be indented because of the error. An example is this\ncode:\n\n```Clojure\n(defmacro chain\n  ([x form] `(. ~x ~form))\n  ([x form & more] `(chain (. ~x ~form) ~@more)))\n```\n\n*lispindent2.lisp* uses the `ignore-errors` macro as a workaround. Doing that means\nthat it can't run in *GNU Common Lisp* because it doesn't have the macro.\n\n#### lispindent2 Command Line Options\n\n    +---------------------------------------------------------------------------+\n    |   Usage:  lispindent2.lisp [[<file>] [--no-modify] [--no-output]]         |\n    |           --no-output ;; Don't output the indented code, false by default |\n    |           --no-modify ;; Don't modify the file, false by default          |\n    +---------------------------------------------------------------------------+\n\n[0]: https://github.com/ds26gte/scmindent\n[1]: https://github.com/ds26gte/scmindent/blob/master/lispindent.lisp\n[2]: https://travis-ci.org/nkmathew/yasi-sexp-indenter.svg?branch=master\n[3]: https://travis-ci.org/nkmathew/yasi-sexp-indenter\n[4]: https://img.shields.io/github/tag/nkmathew/yasi-sexp-indenter.svg\n[5]: https://github.com/nkmathew/yasi-sexp-indenter/releases\n[6]: https://img.shields.io/pypi/dm/yasi.svg\n[7]: https://pypi.python.org/pypi/yasi\n[8]: https://img.shields.io/pypi/pyversions/yasi\n[9]: https://img.shields.io/pypi/implementation/yasi",
    "bugtrack_url": null,
    "license": "",
    "summary": "A dialect aware s-expression indenter",
    "version": "2.1.2",
    "project_urls": {
        "Download": "https://github.com/nkmathew/yasi-sexp-indenter/zipball/master",
        "Homepage": "https://github.com/nkmathew/yasi-sexp-indenter"
    },
    "split_keywords": [
        "scheme",
        "formatter",
        "newlisp",
        "beautifier",
        "clojure",
        "lisp",
        "indenter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a58e369cc04c658f6fbf53de6f05163fc6adbb16694ff7ae56886875fe30c07",
                "md5": "5b9558dbdd07a715c272f7b9ea859233",
                "sha256": "de0f8a1391f55549713592c6464dde7e46f29f40e8ff7c9ff19b938cb5963df4"
            },
            "downloads": -1,
            "filename": "yasi-2.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "5b9558dbdd07a715c272f7b9ea859233",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 32730,
            "upload_time": "2020-05-22T18:03:04",
            "upload_time_iso_8601": "2020-05-22T18:03:04.987132Z",
            "url": "https://files.pythonhosted.org/packages/3a/58/e369cc04c658f6fbf53de6f05163fc6adbb16694ff7ae56886875fe30c07/yasi-2.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-05-22 18:03:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nkmathew",
    "github_project": "yasi-sexp-indenter",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "argparse",
            "specs": [
                [
                    "==",
                    "1.4.0"
                ]
            ]
        },
        {
            "name": "backports.functools-lru-cache",
            "specs": [
                [
                    "==",
                    "1.6.1"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    "==",
                    "0.4.3"
                ]
            ]
        },
        {
            "name": "docutils",
            "specs": [
                [
                    "==",
                    "0.16"
                ]
            ]
        },
        {
            "name": "autopep8",
            "specs": []
        },
        {
            "name": "flake8",
            "specs": []
        },
        {
            "name": "pycodestyle",
            "specs": []
        },
        {
            "name": "pylint",
            "specs": []
        },
        {
            "name": "tox",
            "specs": []
        },
        {
            "name": "virtualenv",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "yasi"
}
        
Elapsed time: 0.06539s