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)
plugin CudaFormatter + its formatters
- 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/
- 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/
-
- Posts: 392
- Joined: 01.12.2020 13:46
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.
+ 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.
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.
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.
-
- Posts: 392
- Joined: 01.12.2020 13:46
You can assign hotkeys via CommandPalette! F9 in the listbox.
All CudaFormatter commands are there.
All CudaFormatter commands are there.
Last edited by uvviewsoft on 01.08.2021 11:43, edited 1 time in total.
-
- Posts: 2323
- Joined: 25.08.2021 18:15