Add Format Code function + Format on Save (Qt frontend only)#87
Open
aik2mlj wants to merge 3 commits into
Open
Add Format Code function + Format on Save (Qt frontend only)#87aik2mlj wants to merge 3 commits into
aik2mlj wants to merge 3 commits into
Conversation
Adds Edit -> Format Code (Ctrl+Shift+I, mapped to Cmd+Shift+I on macOS) that pipes the active document through an external formatter and replaces the buffer with the output. The formatter command is configurable via Preferences -> Editing and defaults to `chuckfmt`; any tool that accepts source on stdin and emits formatted source on stdout will work. - Full-buffer format only; single undoable action; cursor/scroll position preserved best-effort. - Errors (command not found, non-zero exit, timeout) leave the buffer untouched and surface on the status bar via a new formatError signal. - Qt frontend only
New checkbox in Preferences -> Editing (default off). When enabled, save() and saveAs() invoke formatCode() before writing.
When the formatter preference is left at the default `chuckfmt` and it's not found in PATH, point users to https://github.com/aik2mlj/chuckfmt instead of the generic "formatter not found" message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Ge, this PR is to integrate (and shamelessly promote) my chuckfmt util into miniAudicle.
This adds an Edit → Format Code menu item (
Ctrl+Shift+I, which Qt auto-maps toCmd+Shift+Ion macOS) that pipes the active document through an external formatter via stdin → stdout and replaces the buffer with the result. The formatter command is configurable under Preferences → Editing and defaults tochuckfmt; any tool that honors the stdin → stdout contract will work. There's also an opt-in Format on Save checkbox (off by default) that runs the formatter before each save and save-as. If the user doesn't havechuckfmt, they will not run into issues unless they manually trigger formatting or turn on format-on-save.The format itself is a single action that can be reverted by
Ctrl+Z. If the formatter isn't on PATH, exits non-zero, or exceeds a 10-second timeout, the buffer is left untouched and the reason is shown on the status bar. Format-on-save follows the same rule: if formatting fails, the save still proceeds with the unformatted content.This is the Qt frontend only, which covers the Linux and Windows builds plus
make mac-qtfor macOS. It does not cover the default Cocoa frontend for macOS yet. I'll implement it once I borrow a mac.Testing
Install chuckfmt according to its document.
.ck; oneCtrl+Zreverts the entire changeformatter not found: X, buffer unchangedformatter failed: …formatter timed outafter ~10s