sum01 / fmt-micro Goto Github PK
View Code? Open in Web Editor NEWA multi-language formatting plugin for the Micro text-editor. Moved to Gitlab
Home Page: https://gitlab.com/sum01/fmt-micro
License: GNU General Public License v3.0
A multi-language formatting plugin for the Micro text-editor. Moved to Gitlab
Home Page: https://gitlab.com/sum01/fmt-micro
License: GNU General Public License v3.0
I'm adding support for files that Micro doesn't seem to support (when doing CurView().Buf:FileType()
). It already mostly works, but I want to add shebang support to detect shell/bash files without extensions. Turns out Micro can detect shebangs (but only on-load, not on-save), so I guess I don't need to do that.
This will allow for shfmt
andprettier
to work on some undetected filetypes, along with anything else that gets added later.
I guess it could optionally be used 100% of the time, and then the literal file extension could be used in insert()
when adding formatters, but I'm unsure if that's pointless or not.
Apply recommended luacheck stuff. Basically everything to local
, both functions and vars.
It seems that MakeCommand
requires a non-local function, so I can't use all recommendations
3.1.1
only used languages appear in the config
all languages appear/ most of them like "fortran-formatter": "",
which is quite disturbing
I hope this is either a user error or relatively inexpensive to fix.
Micro's JobSpawn is the only portable way to run OS commands, since the Go lib os/exec
isn't available from the plugin bindings.
JobStart can't shouldn't be used, since it is just a shortcut to run shell commands, which aren't compatible with systems that don't have sh
.
I've tried implementing JobSpawn in various ways, but it always outputs errors instead of running. Needs more work...
All I know is that it should look something like JobSpawn(target_fmt[2], {args, file}, "", "", "fmt.onExit")
but I've tried this with both Luafmt & Prettier, and both complain of invalid args.
Instead of keeping a list of formatters in a var at all times, I think it'd be better to get them when format()
runs instead. Then the fmt update
and saved_settings
things can be removed, as can the global var.
Note to self: Check DirectoryName(CurView().Buf.AbsPath)
for an uncrustify .cfg
before the WorkingDirectory()
, if they differ.
Change gofmt to goimports because
... goimports also formats your code in the same style as gofmt so it can be used as a replacement...
Most likely by using Uncrustify.
Alternative: Astyle (but it supports less languages)
Uncrustify might cause me some issues, as it seemingly requires a config file, along with both an input & output file.
While I can think of a rather easy way to get around supply the path twice to the command, I don't think I want to write up a file finder just for Uncrustify's config file.
But maybe I'm overlooking some command..
Unsure of a formatter. Maybe https://github.com/friendsofphp/PHP-CS-Fixer ?
Have a way for the user to override our default settings.
User wants different args to run on prettier, but only with Javascript.
User adds
"fmt|js": "prettier --write"
to settings.json
, which we check for before using our built-in defaults.
js
for Javascript), and if it's an Unknown
type, they must also know to put the file extension, such as p
for Pawn.Have a display name for both the default formatters, and known languages, so a more "common" name can be used.
So instead of tex-formatter
in settings, it would be latex-formatter
, or pawn-formatter
instead of p-formatter
. And for any formatters with weird cli commands, we "obfuscate" and allow for the display name to be used in settings.json
.
This also prevents problems with regressions if/when Micro suddenly "learns" about a new language. What I mean is that, if Micro suddenly recognized Pawn then it would break the p-formater
setting. By using display names, we avoid that.
The only issue is that means we'll have to keep a language list.
Just a big list of formatters, no guarentee all of these will make it in...
https://github.com/google/google-java-format
java -jar /path/to/google-java-format-1.5-all-deps.jar <options> [files...]
The formatter can act on whole files, on limited lines (--lines), on specific offsets (--offset), passing through to standard-out (default) or altered in-place (--replace).
As it is now, the code is kind of hastily written, and could probably benefit from OOP.
Each insert()
could be changed to something like
fmt_list[#fmt_list + 1] = formatter:new(lang = {"css", "html", "javascript"}, cli = "js-beautify", args = {"-r", "-f"})
which should cut down on all the looping it does.
At the same time, maybe a display_name
could be added, so that the user can use that instead of the cli
command as the name. This would help on some formatters that require odd cli calls, such as formatR with it's formatR::input()
or whatever. However, that'd require moving to major version 3
, as it changes the user interface.
Allow for duplicate file-types in fmt_table
by not assigning the key like fmt_table["filetype"] = "value"
but instead using table.insert(fmt_table, values)
. Reading the table will require nested loops, as doing this will mean we will have a potentially "table in a table in a table" as a worse-case scenario.
Reasoning: Some people might prefer one formatter over another, so this will allow conflicting formatters to exist in the same table, and also allow us to worry less over potential conflicts
There should be a way to update/edit the configs/uncrustify/defaults.cfg
with settings from get_settings()
so that the user doesn't need to actually replace the file to get the desired results.
To be honest, I'm clueless as to how to do edits to a file with Lua. I'm sure I'd be able to figure it out, but it might take a while. Also, considering how big the Uncrustify .cfg
file is, it might take a lot of code to get working to the users settings.
It should look for any languages that have more than 1 supported formatter, and create an option like
AddOption(lang .. "-pref", "none")
Then this can be checked before choosing the formatter. If it's "none"
it will use the first found formatter, but if it's set to something like "css-pref": "csscomb"
(in the settings.json
) then it will use csscomb
instead of prettier
(or whatever).
This will allow for clashing formatters to be both enabled at the same time, but the user to preffer one formatter for a specific filetype.
Probably by using https://github.com/google/yapf
Grab the users settings (tabs/space, indent size, etc.), and apply it via formatter args (if they support it).
This should not interfere with the editorconfig plugin.
rustfmt
reads from a rustfmt.toml
config file, can't directly pass options.prettier
can read from a config, but also supports args. Unsure if there'll be a clash.luafmt
only supports tab-size, nothing else.gofmt
only accepts tabsrubocop
seems to lack any relevant args.fish_indent
seems to lack any relevant args.crystal
seems to lack any relevant args.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.