Intellij Java / Scala: remove to delimiter? (e.g. Emacs Paredit)
One of the amazing features of Emacs "paredit" mode, which works with Lisp-like as well as other languages ββsuch as Java / Scala, is the ability to simply press Ctrl-k (kill), and it will intelligently delete the text before the appropriate delimiter. which can be a closing quote or a closing parenthesis / pair / square bracket. This will essentially remove things while keeping your syntactically valid code, i.e. Removes exactly the correct number of closing parsers / curly braces, etc.
Is there such action or keyboard shortcut in Intellij IDEA? Or how can I define a macro for this?
source to share
I have a solution that almost works: Record a sequence of macros (Mac key bindings):
- Expand Selection (Alt Up)
- Expand Selection (Alt Up)
- Correctly with selection (Shift RightArrow)
- Cut selection (Cmd X)
Then I bind this macro to Ctrl-K. It works great for example. (the vertical bar is the position of the caret when it is called):
List( "first", "second", "third |string", "fourth") => List( "first", "second", "third ", "fourth")
{100, 200, {300|, 400, 500}, 20} => {100, 200, {300}, 20}
A case that doesn't quite work exactly the way I want is when I use parentheses:
(1, 2, (3, |4, 5), 6, 7, 8) => (1, 2, (3, , 6, 7, 8)
Note that it removes the closing right parenthesis, which is because Expand-Selection includes parentheses. If the enclosing expression is a string or has curly braces, then Expand-Selection does not include right quotes or braces.
If I knew how to do Expand-Selection without including parentheses, that would be fine, but I can live with what I have.
source to share