How to trigger additional operations on code formatting (Ctrl+Alt+L)

Need to do additional code formatting operations (others than INDENT, WRAP and SPACING) when code formatting is triggered (like changing the case of the tokens). Unfortunately the FormattingDocumentModel is built also when Return is pressed, in which case I do not want the additional operations to be executed.

Is there a listener on the deliberate code formatting invocation (CtrlAltL)? Ideally it should provide the PsiElement which is being formatted.

4 comments
Comment actions Permalink

Hello Dan,

Need to do additional code formatting operations (others than INDENT,
WRAP and SPACING) when code formatting is triggered (e.g. changing the
case of the tokens). Unfortunately the FormattingDocumentModel is
built also when Return is pressed, in which case I do not want the
additional operations to be executed.

Is there a listener on the deliberate code formatting invocation
(started by CtrlAltL)? Ideally it should provide the PsiElement
which is being formatted.


No, there is no such listener.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,
Thanks for the feedback.
Is there another way to intercept an action invocation?
Dan

0
Comment actions Permalink

Dan Cioca wrote:

Hi Dimitry,
Thanks for the feedback.
Is there another way to intercept an action invocation?
Dan

Usually in this situation the best thing is to implement and replace
with your own action which delegates to the existing one, and does
whatever you need around it.

N.

0
Comment actions Permalink

Thanks Nathan,

i would prefer a more non-intrusive solution but it looks like there is none.
Regards,
Dan

0

Please sign in to leave a comment.