Using Microsoft's Typescript plugin for sublime, I can format a file using ^T ^F
as mentioned in features.
Is they a way to run this command automatically when saving a file? I'm after something akin to Sublime-HTMLPrettify Beautify on Save feature.
Thanks.
TypeScript Plugin for Sublime Text The plugin uses an IO wrapper around the TypeScript language services to provide an enhanced Sublime Text experience when working with TypeScript code.
The Sublime Text API has been updated to Python 3.8, while keeping backwards compatibility with packages built for Sublime Text 3. The API has been significantly expanded, adding features that allow plugins like LSP to work better than ever. Read the revamped documentation here . Sublime Text 4 is fully compatible with version 3.
A huge thanks goes out to all the beta testers on discord and all the contributors to our packages. Sublime Text license keys are no longer tied to a single major version, instead they are now valid for all updates within 3 years of purchase.
Sublime Text license keys are no longer tied to a single major version, instead they are now valid for all updates within 3 years of purchase. After that, you will still have full access to every version of Sublime Text released within the 3 year window, but newer builds will required a license upgrade.
There is likely an existing plugin on PackgeControl that allows you to do something like this, although I'm not aware of any off the top of my head and the site is not responsive at the moment.
In the meantime, simplistically you can accomplish this via some simple plugin code:
import sublime
import sublime_plugin
class FormatTypescriptOnSave(sublime_plugin.EventListener):
def on_pre_save(self, view):
if "TypeScript" in view.settings().get("syntax"):
view.run_command("typescript_format_document")
To use this, select Tools > Developer > New Plugin...
from the menu, then replace the entire contents of the template document with this code, and save it (name doesn't matter, only the extension).
This catches a save that's about to happen and runs the appropriate command, so long as the current file is a TypeScript file, as determined by the currently set syntax.
I am using HTML-CSS-JS Prettify
plugin.
After installing the package, open HTMLPrettify.sublime-settings
under the menu Preferences > Package Settings > HTML/CSS/JS Prettify > Plugin Options - User
and paste this setting below:
{
"format_on_save": true,
"global_file_rules":
{
"js":
{
"allowed_file_extensions": ["js", "jsx", "ts"],
"allowed_file_syntaxes": ["javascript", "typescript", "ecma", "react", "babel"],
"disallowed_file_patterns": []
},
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With