New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide variable for current selection #1
Comments
Interesting. Adding a command or argument to format each selected region, rather than buffer, should be pretty simple. The plugin could use the scopes at selection start, rather than buffer start, to determine which formatter to use (more precisely, from which "rule" to take the settings, which is basically the same). Would be interesting to hear about use cases. Can see this being useful for stuff like JS-in-HTML, but there's probably a lot more. Unsure how to handle indentation when formatting only selected regions. Examples would help. Folks in the ST Discord also mentioned async formatting. The general conclusion was that sometimes you want sync behavior ( |
That solution sounds good to me (having two separate configurations/commands). As for clang-format, I believe that when you are formatting just the selection (by providing the The most common use-case is probably to just format the current line rather than the whole document.
In the case of clang-format I think that no special handling would be necessary since the whole buffer would be returned regardless if formatting just the selection or the whole document.
To be fair, IMO the async formatting would always be preferred as even with very fast formatters, you'd likely see a tiny stutter on saving if you are sensitive to that. I know that that makes the
You could just cancel the formatting if the document was modified since triggering the formatting. This can be checked using |
In a general case we have N selection regions. Does When files are being watched, you don't want to save twice, as it would trigger a redundant rebuild/rerun. A good watcher will be able to cancel and restart (gow does), but a bad one will just build twice, wasting your CPU/battery and time (gulp/webpack). This makes sync Canceling format on change is an interesting idea, thanks. |
Yes. You can read about it more at https://clang.llvm.org/docs/ClangFormat.html |
It would be possible with variables if
The documentation seems to indicate that you need pairs:
If true, I'm slightly at a loss how to support the latter. |
We could have variables for "start of first selection" and "length of first selection". There could be incompatibilities between how ST and The user might want separate hotkeys and separate Fmt rules. For example, when formatting a selection, the user would want to activate a rule which contains |
I was checking your code to see if I could use it to replace my clang-format plugin [1] and found that my plugin also supports formatting just the selection. Or at least passing the current selection to clang-format [2].
Maybe you could provide variables that would expand to
selection_start
,selection_end
offsets, and alsoselection_length
?(Although, I've just realized while writing this, that we wouldn't want to pass
-offset
and-length
when the selection is empty so that could be another thing that would make supporting this tricky...)[1] https://github.com/rchl/SublimeClangFormat
[2] https://github.com/rchl/SublimeClangFormat/blob/9d4f804e82b471928fab0c347ccabefccaf9240c/ClangFormat.py#L128-L132
(Also, I would really want to run formatting on a separate thread so that the UI doesn't block when formatting MB-big files).
The text was updated successfully, but these errors were encountered: