Plugin: Space Indenter [v0.2.1] [2022-09-17]

Space Indenter

I find spaces to be a bit easier to manage on the mobile (compared to tabs, which I hold in respect), so I looked for a solution.

This plugin exposes CodeMirror's relevant settings to Joplin users, which enable switching between tab indentation and space indentation. In addition, it can automatically reformat your notes (if enabled in the settings) and convert any existing tabs to spaces (or vice versa, if you decide you're a tab-person after all). A dedicated toolbar button calls the same action manually.

AFAIK replacing tabs with 4 spaces is OK as far as CommonMark is concerned, and in practice most things work as expected even with 2 spaces. If there are caveats to this approach, please discuss below.

Thanks to Rich Markdown (@CalebJohn), that heavily influenced this implementation.

4 Likes

@shikuz, I prefer to set editors to use 4 spaces rather than tabs, so this is a welcome addition.

On testing, it doesn't seem consistent, sometimes it will insert a tab character, and sometimes four spaces. I can't figure out a particular pattern to it.

Setup in use here:
Joplin 2.8.8 (prod, linux)
Client ID: 615c7880d02145c5a89371d6264bdcb9
Sync Version: 3
Profile Version: 41
Keychain Supported: No
Revision: c2a6a13

CodeMirror's logic in this case is indeed a bit obscure, but I believe the following rules apply:

key / event result
Indent less/more command (Edit menu) SPACE
TAB while text is selected SPACE
TAB on an empty bullet/checkbox line SPACE
TAB on any other event (e.g., cursor in mid-line) TAB
2 Likes

v0.2.0

  • tab key behavior fix:
    • in any context, the tab key is always converted to spaces (based on the parameters in the plugin's settings)
    • when pressed anywhere on a list item, the tab key indents the line using spaces
  • new toolbar button: reformat tabs, which converts all tabs in the current note to spaces (or changes spaces back to tabs, when the plugin is set to indent with tabs)
  • new setting (off by default) to apply the above reformatting to any note when it's being loaded
1 Like