Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parinfer Take 3 #1429

Open
wants to merge 96 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
273f79f
WIP infer parens and preserve formatting fwd
PEZ Nov 8, 2021
f2e23d0
Try make backspace play with the new modes
PEZ Nov 8, 2021
8fef5ed
Format forward on enter
PEZ Nov 8, 2021
4daa30b
Fix bug with NaN selection after format forward
PEZ Nov 8, 2021
c6517c7
Update docs
PEZ Nov 8, 2021
732f020
Consider strictness in forward delete
PEZ Nov 8, 2021
f79f305
Auto-close brackets in strict mode
PEZ Nov 9, 2021
406fb93
Update Calva description
PEZ Nov 9, 2021
b2d107c
Fix bug with adding closing parens
PEZ Nov 9, 2021
5df063c
Use non-strict backspace in parinfer mode
PEZ Nov 9, 2021
3792315
Udate docs [skip ci]
PEZ Nov 9, 2021
f34b978
Update docs, remove some keybindings
PEZ Nov 9, 2021
a5837a7
Hack the cursor position returned from parinfer
PEZ Nov 9, 2021
2356668
Make Calva Highlight a separate page
PEZ Nov 10, 2021
e5dde87
Document auto-closing setting
PEZ Nov 10, 2021
804a9f3
Don't forget the image =) [skip ci]
PEZ Nov 10, 2021
9f5b38f
Dynamic parinfer config
PEZ Nov 10, 2021
a297205
Disable paredit autoclose brackets by default
PEZ Nov 10, 2021
aed920f
Do auto-closing in doc-mirror processChanges
PEZ Nov 10, 2021
4de1678
Use onType true for docmirror model edits
PEZ Nov 12, 2021
b70c242
Only auto-close when bracket is the single change
PEZ Nov 12, 2021
186aad5
Fix extra paren
PEZ Nov 12, 2021
675005f
Fix funny function name
PEZ Nov 13, 2021
c9ea47b
Add `experimental` to settings names
PEZ Nov 13, 2021
946876c
Add `experimental` to settings names, for real
PEZ Nov 13, 2021
59c091b
Add check parinfer integrity status bar item
PEZ Nov 14, 2021
4b37ca8
Add commands for fixing indentation
PEZ Nov 15, 2021
25455b9
Paredit -> parinfer
PEZ Nov 15, 2021
399c964
Don't nag on readonly documents
PEZ Nov 15, 2021
7b74e47
Wait with health check to after inference
PEZ Nov 15, 2021
dff921f
Fix formatForward config bug
PEZ Nov 15, 2021
f67287d
Alays update status bar item on editor change
PEZ Nov 15, 2021
69fdba1
Only perform parinfer on current active doc
PEZ Nov 15, 2021
839f3d6
Update mirrordoc indent integrity on enable
PEZ Nov 15, 2021
3048bcf
Update docs/site/parinfer.md
PEZ Nov 16, 2021
5353e3d
Create token cursors inside changes loop
PEZ Nov 16, 2021
a09f6e5
Make formatForward part of formatAsYouType
PEZ Nov 16, 2021
72235ee
Let VS Code handle strict autoclose
PEZ Nov 16, 2021
a1259b8
Merge extraCOnfig for good measure
PEZ Nov 17, 2021
1183461
Resize huge gif
PEZ Nov 17, 2021
abc915a
Add CRLF test file
PEZ Nov 17, 2021
e8386d3
Send CRLF line endings to formatter if CRLF doc
PEZ Nov 17, 2021
b47aee2
Update docs
PEZ Nov 17, 2021
a3029c3
Stop infiinte loop when CRLF text is formatted
PEZ Nov 18, 2021
66dfcbd
Update statusbar
PEZ Nov 18, 2021
75985a3
Batch edits in processChanges
PEZ Nov 18, 2021
e80a383
Don't alert in for result doc
PEZ Nov 19, 2021
bed42e4
New as-you-type health check strategy
PEZ Nov 19, 2021
a16925c
Fix infer parens aftet format forward
PEZ Nov 19, 2021
82058c0
Remove performFormatForward from model
PEZ Nov 20, 2021
2240d1a
Clean ns
PEZ Nov 20, 2021
f6b5ab4
Clean up some more format forward stuff
PEZ Nov 20, 2021
abe6f51
Disregard mysterious zero-length changes
PEZ Nov 20, 2021
72cc125
Factor out fomratRangeInfo
PEZ Nov 20, 2021
f01153e
Factor out format from formatInfo
PEZ Nov 20, 2021
5bbd320
Factor out indexForFormatForward
PEZ Nov 20, 2021
e9848a0
Apply padding indents on all lines
PEZ Nov 21, 2021
cec880b
Format pasted text as-you-type
PEZ Nov 21, 2021
60ba1ef
Check structure health befor range-format
PEZ Nov 21, 2021
ca4df54
Don't infer parens after paredit ops
PEZ Nov 21, 2021
80127f9
Add cljfmt testdata config
PEZ Nov 21, 2021
543bae3
Separate toolbar items for toggle and check
PEZ Nov 21, 2021
5e96938
Sync active/non-active parinfer for both items
PEZ Nov 22, 2021
7a2d537
Tidy up performChanges and formatRange
PEZ Nov 22, 2021
15f9b3c
Don't range format inside strings (see #720)
PEZ Nov 22, 2021
b1d2b42
Only check parinfer readiness on clojure docs
PEZ Nov 22, 2021
f8975f1
Add debug logging
PEZ Nov 22, 2021
fc498b3
Experimental guardprocessing processed changes
PEZ Nov 23, 2021
2ae102a
Control processing via edit options
PEZ Nov 23, 2021
773e177
Use a promise chain
PEZ Nov 23, 2021
ae2dd92
Move all after process into last then
PEZ Nov 23, 2021
f121281
Use theme for toolbar item color
PEZ Nov 24, 2021
d9e5e72
WIP: Use brancing instead of promise chain
PEZ Nov 24, 2021
1aaa047
Only invoke extra processChanges when Parinfer ON
PEZ Nov 24, 2021
81e08a6
Update documentatioon
PEZ Nov 24, 2021
7deddaf
Show info message when Parinfer is toggled
PEZ Nov 24, 2021
7039484
Add some missing undstop when deleting text
PEZ Nov 25, 2021
5e4da41
Update health checking strategy
PEZ Nov 25, 2021
653f807
Use closed in batchDone variable to control reset
PEZ Nov 26, 2021
104a813
Reintroduce formatForwardAsYouType setting
PEZ Nov 27, 2021
3f8f4b3
Stop updating status bar on open doc events
PEZ Nov 27, 2021
062909a
Revert normalize-indents
PEZ Nov 28, 2021
08ea756
Add currentEnclosing form get-text function
PEZ Nov 28, 2021
9db804c
Don't indent on type when parinfer on
PEZ Nov 28, 2021
9a8e0bf
Reinstall indenter also for parinfer mode
PEZ Dec 1, 2021
69c9aa6
Add function for indenting on an editable doc
PEZ Dec 1, 2021
427c40d
Format current form 2 levels on multiline edits
PEZ Dec 1, 2021
e586c5b
Don't infer parens after most all paredits
PEZ Dec 1, 2021
54cd8bc
Infer after delete, of course
PEZ Dec 1, 2021
69fe6e4
Don't format on paste when formatForward on
PEZ Dec 1, 2021
47adbee
Clean up som settings and update changelog
PEZ Dec 1, 2021
0dc548c
Update docs about statusbar indicator [skip ci]
PEZ Dec 1, 2021
2379e28
Update changelog
PEZ Dec 8, 2021
e4f3d07
Check formatOnType in clojure scope too
PEZ Dec 8, 2021
fc4ffac
Add crlf another sandbox file
PEZ Dec 12, 2021
5638d86
Merge branch 'dev' into pez/253-parinfer-take-3
PEZ Dec 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"docmirror",
"Docstring",
"eckstein",
"eduarddyckman",
"eldoc",
"enablement",
"enablements",
Expand Down Expand Up @@ -131,6 +132,7 @@
"Sexp",
"Sexpr",
"Sexps",
"shaunlebron",
"sivertsen",
"stacktraces",
"stian",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Changes to Calva.

## [Unreleased]
- Re-enable, Experimental: [Add Parinfer Mode](https://github.com/BetterThanTomorrow/calva/issues/253)
- Re-enable, Experimental: [Add option to keep text more fully formatted as you type](https://github.com/BetterThanTomorrow/calva/issues/1406)
- Re-enable, [Remove `calva.fmt.formatAsYouType` option](https://github.com/BetterThanTomorrow/calva/issues/1407)

## [2.0.231] - 2021-12-14
- Fix: [Calva randomly edits file while in Live Share](https://github.com/BetterThanTomorrow/calva/issues/1434)
Expand Down
34 changes: 4 additions & 30 deletions docs/site/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ Calva sets some VS Code settings for all Clojure files. Some of these are needed
"[clojure]": {
"editor.wordSeparators": "\t ()\"':,;~@#$%^&{}[]`",
"editor.autoClosingBrackets": "always",
"editor.autoClosingOvertype": "always",
"editor.autoClosingQuotes": "always",
"editor.formatOnType": true,
"editor.autoIndent": "full",
"editor.formatOnPaste": true,
"files.trimTrailingWhitespace": false,
"editor.matchBrackets": "never",
"editor.renderIndentGuides": false,
"editor.guides.indentation": false,
"editor.parameterHints.enabled": false
}
```

!!! Note
!!! Note "`editor.wordSeparators`"
The above `editor.wordSeparators` setting establish Clojure word boundaries. E.g `-` is considered to be part of words. This affects what happens when double-clicking symbols and other things. If you want to include `-` or something else as a word boundary, just add it to the setting.

## Pretty Printing
Expand All @@ -45,34 +46,7 @@ Calva's pretty printing mode can be configured a bit. See [Pretty Printing](ppri

## Calva Highlight

Calva takes care of syntax highlighting, and also provides some features not available through VS Code's highlighting mechanism. These extras include rainbow parens, sane bracket matching, and comment form dimming/highlighting.

You are in charge of how brackets and comments are highlighted via the `calva.highlight.<setting>` settings:

| Setting | Meaning | Example |
| --- | ------- | ------- |
| `enableBracketColors` | Enable rainbow colors | `true` |
| `rainbowIndentGuides` | Enable rainbow indent guides | `true` |
| `highlightActiveIndent` | Highlight the active indent guide | `true` |
| `bracketColors` | Which colors to use | `["#000", "#999"]` |
| `cycleBracketColors` | Whether same colors should be <br> reused for deeply nested brackets | `true` |
| `misplacedBracketStyle` | Style of misplaced bracket | `{ "border": "2px solid #c33" }` |
| `matchedBracketStyle` | Style of bracket pair highlight | `{"backgroundColor": "#E0E0E0"}` |
| `ignoredFormStyle` | Style of `#_...` form | `{"textDecoration": "none; opacity: 0.5"}` |
| `commentFormStyle` | Style of `(comment ...)` form | `{"fontStyle": "italic"}` |

!!! Note "Calva disables the VS Code built-in indent guides"
The VS Code built-in settings `editor.renderIndentGuides` and `editor.highlightActiveIndent` do not have any effect, since the former is switched off by the **Clojure Defaults**, mentioned above. Use Calva Highlight's `rainbowIndentGuides` and `highlightActiveIndent` instead. They are different from the built in ones in that they are independent, meaning you can choose to have active indent highlighted while the guides generally are not rendered (this is the default, even).

!!! Note "VS Code bracket coloring vs Calva's"
Calva's bracket coloring is more Clojure aware than VS Code's built-in coloring. And also will chime better with Calva's indent guides. If you like to have bracket coloring outside Clojure code, by all means enable it. Calva's bracket coloring will ”over paint” in Clojure files, when enabled. These settings work nicely:

```clojure
"calva.highlight.highlightActiveIndent": true,
"editor.bracketPairColorization.enabled": true,
```

The `calva.highlight.bracketColors` setting can be used to harmonize the coloring between VS Code and Calva.
See [Clojure Syntax Highlighting](highlight.md) for customization options.

## Automatic Parameter Hints Poppup

Expand Down
16 changes: 13 additions & 3 deletions docs/site/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ With the default settings, Calva's formatting behaves like so:
* formats the current form, _aligning map keys and values_, when you press `ctrl+alt+l`
* formats `(comment ..)` forms special, see [rich comments](#rich-comments)

!!! Tips
Calva has a command that will ”heal” the bracket structure if it is correctly indented. Yes, it is Parinfer behind the scenes. This command is default bound to `shift+tab` to form a nicely balanced pair with the `tab` formatting.

Also: If you have **Format on Save** enabled in VS Code, it will be Calva doing the formatting for Clojure files.

Calva's formatting is mostly about indenting, but it also (again, defaults):
Expand All @@ -35,6 +32,19 @@ Not a fan of some default setting? The formatter is quite configurable.

## Configuration

There are settings for the general behaviour of Calva formatting as well as for configuring `cljfmt`, which is the formatting engine used.

| Setting | Description | Default
| ------- | ----------- | -------
| `calva.fmt.newIndentEngine` | Fast indentation. When disabled, a full formatting will be done on the current enclosing form. | **true**
| `calva.fmt.experimental.fullFormatOnType` | Experimental: Formats forms starting on the same line, forwards from the cursor as you enter or delete text. Also enabled as part of [Parinfer](parinfer.md) mode (`inferParensAsYouType`) | **false**
| `calva.fmt.experimental.inferParensAsYouType` | Experimental: [Parinfer](parinfer.md) mode | **false**
| `calva.fmt.keepCommentTrailParenOnOwnLine` | See [Rich Comments](rich-comments.md) | **true**

Calva's auto-formatter will reformat forms that are directly affected by your edits, and it will automatically indent new lines to match your `cljfmt` indentation settings. See below.

### cljfmt

You configure Calva's formatting using [cljfmt's configuration EDN](https://github.com/weavejester/cljfmt#configuration). This means that you can adjust the above mentioned defaults, including the indenting.

!!! Note
Expand Down
47 changes: 47 additions & 0 deletions docs/site/highlight.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Syntax Highlighting
description: Calva takes care of your Clojure syntax highlighting, and then some.
---

# Calva Highlight

Calva takes care of syntax highlighting, and also provides some features not available through VS Code's highlighting mechanism. These extras include Clojure aware rainbow parens and vertical guides, sane bracket matching, and comment form dimming/highlighting.

1. Dimming of ignored forms (or whatever style you customize it to)
2. Italics for `(comment ...)` forms (or your preferred highlight style)
3. Colorize the tags/dispatches of tagged lists the same as the bracket color.
4. Highlight matched brackets at the tag for a tagged list
5. Option to display colorized indent guide for the active indent only

<figure markdown>
![Calva Highlight](images/calva-highlight.png)
<figcaption>The cursor is that light-blue bar before the `#:g` namespace tag. The corresponding brackets highlight and the cursor is marked as being inside the blue `#:b` map (by the blue vertical guide).</figcaption>
</figure>

You are in charge of how brackets and comments are highlighted via the `calva.highlight.<setting>` settings:

| Setting | Meaning | Example |
| --- | ------- | ------- |
| `enableBracketColors` | Enable rainbow colors | `true` |
| `rainbowIndentGuides` | Enable rainbow indent guides | `true` |
| `highlightActiveIndent` | Highlight the active indent guide | `true` |
| `bracketColors` | Which colors to use | `["#000", "#999"]` |
| `cycleBracketColors` | Whether same colors should be <br> reused for deeply nested brackets | `true` |
| `misplacedBracketStyle` | Style of misplaced bracket | `{ "border": "2px solid #c33" }` |
| `matchedBracketStyle` | Style of bracket pair highlight | `{"backgroundColor": "#E0E0E0"}` |
| `ignoredFormStyle` | Style of `#_...` form | `{"textDecoration": "none; opacity: 0.5"}` |
| `commentFormStyle` | Style of `(comment ...)` form | `{"fontStyle": "italic"}` |

!!! Note "Calva disables the VS Code built-in indent guides"
The VS Code built-in settings `editor.renderIndentGuides` and `editor.highlightActiveIndent` do not have any effect, since the former is switched off by the **Clojure Defaults**, mentioned above. Use Calva Highlight's `rainbowIndentGuides` and `highlightActiveIndent` instead. They are different from the built in ones in that they are independent, meaning you can choose to have active indent highlighted while the guides generally are not rendered (this is the default, even).

!!! Note "VS Code bracket coloring vs Calva's"
Calva's bracket coloring is more Clojure aware than VS Code's built-in coloring. And also will chime better with Calva's indent guides. If you like to have bracket coloring outside Clojure code, by all means enable it. Calva's bracket coloring will ”over paint” in Clojure files, when enabled. These settings work nicely:

```clojure
"calva.highlight.highlightActiveIndent": true,
"editor.bracketPairColorization.enabled": true,
```

The `calva.highlight.bracketColors` setting can be used to harmonize the coloring between VS Code and Calva.

Binary file added docs/site/images/calva-highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Learn how to use Calva, an IDE bringing full Clojure and ClojureScr

![Calva Logo](https://raw.githubusercontent.com/BetterThanTomorrow/calva/dev/assets/calva-64h.png)

[Calva](https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva) is an integrated REPL powered environment for enjoyable and productive [Clojure](https://clojure.org) and [ClojureScript](https://clojurescript.org) development in [Visual Studio Code](https://code.visualstudio.com). It includes inline code evaluation, Paredit, code formatting, a test runner, syntax highlighting, [linting](linting.md), and more. [Calva is open source](https://github.com/BetterThanTomorrow/calva) and free to use.
[Calva](https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva) is an integrated REPL powered environment for enjoyable and productive [Clojure](https://clojure.org) and [ClojureScript](https://clojurescript.org) development in [Visual Studio Code](https://code.visualstudio.com). It includes inline code evaluation, [Paredit](paredit.md), [Parinfer](parinfer.md), [code formatting](formatting.md), a [test runner](test-runner.md), syntax highlighting, [linting](linting.md), and more. [Calva is open source](https://github.com/BetterThanTomorrow/calva) and free to use.

## Getting Started

Expand Down
15 changes: 11 additions & 4 deletions docs/site/paredit.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ search:

# Paredit – a Visual Guide

Structural editing and navigation for Clojure.
Structural editing and navigation for Clojure. Works great together with [Parinfer](parinfer.md).

## What is Paredit?

Expand All @@ -34,11 +34,12 @@ Indicator | Paredit Mode
`(λ)` | Cave Man (strict mode off)
`λ` | No default key bindings

Toggle between Strict and Cave Man using: `ctrl+alt+p ctrl+alt+m`
Strict mode also inserts matching brackets when you type an open bracket.

### Prevent Unbalanced Closing Brackets
Toggle between Strict and Cave Man using: `ctrl+alt+p ctrl+alt+m`

There is also a setting, `calva.paredit.strictPreventUnmatchedClosingBracket`, that will help you to not enter unbalanced closing brackets into the code.
!!! Note "Parinfer is strict mode"
When you are using Calva's [Parinfer](parinfer.md) mode, then this strictness is handled by Parinfer. It is recommended that you leave this setting on regardless.

## Commands

Expand Down Expand Up @@ -145,5 +146,11 @@ There are some context keys you can utilize to configure keyboard shortcuts with

In some instances built-in command defaults are the same as Paredit's defaults, and Paredit's functionality in a particular case is less than what the default is. This is true of *Expand Selection* and *Shrink Selection* for Windows/Linux when multiple lines are selected. In this particular case adding `!editorHasMultipleSelections` to the `when` clause of the binding makes for a better workflow. The point is that when the bindings overlap and default functionality is desired peaceful integration can be achieved with the right `when` clause. This is left out of Paredit's defaults to respect user preference, and ease of maintenance.

## See also

* [Parinfer](parinfer.md)
* [Formatting](formatting.md)

## Cheering-ons

Happy Editing! ❤️
114 changes: 105 additions & 9 deletions docs/site/parinfer.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,114 @@
---
title: Parinfer
description: Yes, you can use Calva with with the Parinfer extension
description: Learn how to leverage Calva Parinfer Mode for structural editing
---

# Using Calva with Parinfer
# Calva Parinfer Mode

Yes, you can use Calva with with the Parinfer extension. The only conflict here is that Calva's auto-formatting (that which happens as you type) is going to risk clash with Parinfer's.
[Parinfer](https://shaunlebron.github.io/parinfer/) is a system for editing the structure of LISP text without explicit commands. The structure can be regarded as already being expressed through indentation. With Parinfer you can use your intuition about the structure _inferred_ from the indentation to perform surprisingly many structural edits.

However, Calva's [Paredit](paredit.md) is carefully crafted. If you don't already have an established preference for parinfer, we suggest you give it a try. Even parinfer veterans may find they prefer the explicit nature of paredit. It takes only some few minutes to learn two or three basic Paredit commands:
!!! Note "Experimental"
This feature is currently disabled by default and should be considered experimental. There are known [quirks](#quirks). Especially beginners should take note. Parinfer is not as beginner friendly as it might seem, and with the quirks it might be extra ”dangerous”.

* **Select form**
* **Slurp**
* **Barf**
## Infer Parens

Also, if you find yourself having deleted or added a bracket out of structure, despite Calva Paredit's **Strict mode** (which you are using, right?) there is a command that might help you heal the structure: **Infer Parens from Indentation**. That command is actually implemented using the Parinfer library, so it will let you recover from quite many situations. This command is bound to `shift+tab` by default, making it a good companion to `tab` which indents based on bracket structure.
When you enable Calva's Parinfer it is all about infering brackets from indentation. There are no modes further Parinfer modes. Calva's auto-formatter will take care of keeping the code correctly indented.

All that said, what was said first is true: if you want to use the Parinfer extension, you can. You'll probably want to disable Calva's auto-formatting. The setting for controlling this is named `calva.fmt.formatAsYouType`.
Enable it with from this setting: `calva.fmt.experimental.inferParensAsYouType` or from the status bar item.

### Parinfer Status bar items

To the right on the status bar, right before the [Paredit](paredit.md) status bar item, you will have two items, Parinfer toggle ON/OFF and a health indicator.

1. Parinfer **ON**/**OFF** indicator/button. <kbd>•()</kbd> (The dot/circle indicates **ON**/**OFF**)
2. Structure and indentation health indicator. <kbd>✔️</kbd>/<kbd>⚠</kbd>/<kbd>⊘</kbd>

When Parinfer is **ON**, the health indicator will have three states:

1. <kbd>✔️</kbd> Healthy - meaning both structure and indentation is OK
2. <kbd>⊘</kbd> Structure broken - you need to fix the the structure of the code
3. <kbd>⚠</kbd> Bad indentation - meaning that to Parinfer the structure and indentation do not match, _the item is now also a button with which you can fix the indentation.

Parinfer will be disabled in both the unhealthy states.

When Parinfer is OFF, only the first two states above are used.

## Some VS Code Settings automatically changed

In order for some automatic VS Code behaviour not to interfere with Parinfer the following settings are automatically configured when you toggle Parinfer ON:

```json
"[clojure]": {
"editor.autoClosingBrackets": "never",
"editor.autoClosingOvertype": "never",
"editor.formatOnPaste": false
},
```

And when you toggle Parinfer OFF:

```json
"[clojure]": {
"editor.autoClosingBrackets": "always",
"editor.autoClosingOvertype": "always",
"editor.formatOnPaste": true
},
```

It is recommended that you let Calva handle these settings to avoid weird behaviour.

## No Tab indenting

As the `tab` key is used for formatting the current form in Calva, it is ”taken”. The closest equivalents you have are `space` and `backspace`. At least for now. We'll see if we can find out a good way for supporting `tab` and `shift+tab` for indent and dedent.

`tab` for formatting is of course just a default key binding and you can assign it to something else to get it to do indenting. However, it will not be a very smart indent anyway, there is no Clojure awareness about it. You are hereby adviced to instead use some more spaces.

## Paredit is still there

In Calva, Parinfer and [Paredit](paredit.md) are designed to coexist and both be there to let you edit the structure easily and efficiently. Since Paredit commands are always formatted, they leave the code in a state where Parinfer has what it needs to infer bracket placement as you either edit the indentation, or remove/add brackets.

## Disable the Parinfer Extension

If you want to have Parinfer you are probably best served by Calva's built-in version. It is designed, and will continue to be improved to function well together with Calva's other structural editing and formatting features. _It will also probably conflict with the Parinfer Extension._

## Quirks

There are some known quirks, of varying severity, with this feature. Some of them will need to be fixed before we move this feature out of **Experimental** status.

For the most times you can always *Undo* to get back to where the document was fine. You just need to pay some attention and be aware when undo is needed.

### No multi-cursor support

The bracket inference will remove all cursors but the first one. So for instance if you edit with multiple cursors and it causes brackets to move, you'll end up with just one cursor and the subsequent edits will not be what you intended. This is particularly important to note when you have cursors that are not in the viewport. In such cases it might be better to turn Parinfer off while you do the edits, fix formatting and such manually and then switch Parinfer on again.

### Wrong inferences

For yet unknown reasons an edit such as the following does the wrong thing (the cursor indicated by the vertical bar):

```clojure
(foo| (bar)
(baz))
```

<kbd>backspace</kbd> =>

```clojure
(fo| (bar
(baz)))
```

That is `(baz)` is slurped. When what should happen is:

```clojure
(fo| (bar)
(baz))
```

### Lag causing errors when fast typing

the way that Calva Parinfer works is that at eny edit of the document it first re-formats the code around the cursor, then infer brackets. Currently these two steps are not atomic to VS Code, so if you type fast bracket inference might happen on the yet unformatted code, and thus not be correct. You might also see the cursor end up at the wrong position at times.

## See also

* [Paredit](paredit.md)
* [Formatting](formatting.md)
Loading