plugin CudaFormatter + its formatters

Plugins for SynWrite and CudaText...
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

plugin CudaFormatter + its formatters

Post by Alexey »

Framework to use code formatters in CudaText. Formatters are Python functions
which change entire file text or only selected text.
Formatters are distributed as separate 2nd-level plugins, which are called
via this framework. This approach is like CudaLint and its linters.

Commands in the Plugins menu
----------------------------

- Formatter (menu):
Runs formatter for current editor file. If several formatters are found,
menu dialog will suggest to choose one of them.

- Formatter per-lexer A...D:
Runs formatter for current editor file, which has label (A, B, C, D) set.
These are per-lexer labels, ie you can have formatter for label 'B' in C++,
and another formatter for 'B' in XML, and another one for JSON.

- Formatter cross-lexer 1...4:
Runs formatter for current editor file, which has label (1, 2, 3, 4) set.
These are cross-lexer labels, ie they ignore the current lexer.

- Configure per-lexer labels:
Allows to assign labels (A, B, C, D) to formatters. Labels allow to use commands
"Formatter per-lexer A" ... "Formatter per-lexer D" (e.g. via hotkeys).
These are per-lexer labels, ie you can have formatter for label 'B' in C++,
and another formatter for 'B' in XML, and another one for JSON.

- Configure cross-lexer labels:
Similar to previous item, but for cross-lexer labels (1, 2, 3, 4). For example,
if formatter "XML Tidy" has the cross-lexer label "2", then calling
of formatter "2" will always run "XML Tidy", ignoring the current lexer.

- Configure on_save:
Chooses which formatters are active on file saving. The first formatter,
which is suitable for current lexer, and has the flag "on_save",
will be used to format text on file saving.

- Configure formatter:
For those formatters which support config file, command will suggest
to open global config file (in the folder "settings" of CudaText).

- Configure formatter (local):
For those formatters which suppots config file, command will suggest to open
"local" config (in the folder of current editor file). If local config
not exists, plugin will suggest to create it from global config.

Docs
----
No docs yet.
To see how to write formatters, install "Formatters for JavaScript"
which has most of features.


Author: Alexey Torgashin (CudaText)
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

- All formatter-like plugins were converted to new "formatter" form.
- Some config files of those formatters were renamed, to be like "cuda_fmt_nnnnnnn.json".
- Some formatters have updated engine libs, e.g. CSS Comb, CSS AutoPrefixer, CSS Prefixer.

- New formatter appeared: Python Black.
It requires Python 3.6+ so it cannot work on Windows build of CudaText (Py 3.5).
https://black.readthedocs.io/en/stable/
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

New formatter: Bash Beautify (based on Beautysh library).
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

New formatter: XML IndentX, based on Sublime Text plugin.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

New formatter: HTML Soup, based on library Beautiful Soup.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

New formatter: ColdFusion.
uvviewsoft
Posts: 392
Joined: 01.12.2020 13:46

Post by uvviewsoft »

2021.08.01
+ add: reworked config, now we have per-lexer labels (A B C D) + cross-lexer labels (1 2 3 4).

readme.txt:

- Formatter per-lexer A...D:
Runs formatter for current editor file, which has label (A, B, C, D) set.
These are per-lexer labels, ie you can have formatter for label 'B' in C++,
and another formatter for 'B' in XML, and another one for JSON.

- Formatter cross-lexer 1...4:
Runs formatter for current editor file, which has label (1, 2, 3, 4) set.
These are cross-lexer labels, ie they ignore the current lexer.

- Configure per-lexer labels:
Allows to assign labels (A, B, C, D) to formatters. Labels allow to use commands
"Formatter per-lexer A" ... "Formatter per-lexer D" (e.g. via hotkeys).
These are per-lexer labels, ie you can have formatter for label 'B' in C++,
and another formatter for 'B' in XML, and another one for JSON.

- Configure cross-lexer labels:
Similar to previous item, but for cross-lexer labels (1, 2, 3, 4). For example,
if formatter "XML Tidy" has the cross-lexer label "2", then calling
of formatter "2" will always run "XML Tidy", ignoring the current lexer.
ertank
Posts: 61
Joined: 06.06.2021 21:56

Post by ertank »

I do appreciate CudaFormatter modifications.

I could not figure how I can define a hotkey for a cross-lexer label.

Assuming I have a cross formatter "1" defined to pretty print XML. I also would like to use CTRL+SHIFT+X as a hotkey. Where can I define that hotkey? What would be exact command to pass to the hotkey?

Thanks.
uvviewsoft
Posts: 392
Joined: 01.12.2020 13:46

Post by uvviewsoft »

You can assign hotkeys via CommandPalette! F9 in the listbox.
All CudaFormatter commands are there.
Attachments
Screenshot from 2021-08-01 14-39-03.png
Last edited by uvviewsoft on 01.08.2021 11:43, edited 1 time in total.
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Post by main Alexey »

CudaFormatter updated.

2022.04.03
+ add: command "Minify to separate file". It needs the line "minifier=1" in the [fmtX] section of formatter's install.inf.

2 formatters updated to support new Minify command:
- JS/JSON
- CSS/SCSS/Sass/LESS
Post Reply