https://kotlinlang.org logo
#random
Title
# random
y

Youssef Shoaib [MOD]

11/22/2023, 11:40 PM
Is there an Idea plugin that folds functions with backticks
Copy code
`hello`
and makes them appear without the backticks? I saw some plugins that do that to prettify certain parts of languages (e.g. python's lambda being replaced by the greek letter lambda)
plus1 2
e

elect

11/23/2023, 1:20 PM
oh, that'd be very nice, let me subscribed to this thread
y

Youssef Shoaib [MOD]

11/23/2023, 9:28 PM
I've made it! Currently waiting on approval from Jetbrains Marketplace
🚀 1
🎉 2
Guess which are folded and which aren't! I turned off the color for folded text in the settings btw, which helps a lot
🧠 1
A few ideas and TODOs for the plugin: • Take in a custom mapping of function names/fqns to pretty names and use those as fallbacks (should be trivial to implement) • Add an option to hide the . in property access to pretty names (trivial) • Add an option to hide the parenthesis for prefix-like pretty functions (medium. Need to make it have similar semantics to existing prefix operators e.g.
!
) • Add the option to provide a custom format string for the function's arguments (medium. Varargs are difficult. Need to decide whether to exclude lambdas or not and when?) • Implement custom infix left/right operators with custom precedence (very hard. Note that this, like the rest, are in folding only, so it might be strange to type out). • Add option to fold single expression if-else to ternary operator
a

Adam S

11/24/2023, 12:20 AM
Great! Looking forward to it. Is it on GitHub?
e

elect

11/24/2023, 12:23 AM
Kudos! I'm curious on the whole predicates, could you expand the screenshot or past the whole code in here?
y

Youssef Shoaib [MOD]

11/24/2023, 12:51 AM
@Adam S It is on Github here. It will take a couple days for it to be approved on the Jetbrains marketplace, but once it is, it'll be just an install away @elect Here's a simplified example:
Copy code
infix fun Boolean.`?`(value: Any): Any = TODO()
infix fun Boolean.`&`(other: Boolean): Boolean = TODO()

@Pretty(":")
infix fun Any.orElse(other: Any): Any = TODO()

@Pretty("<<")
infix fun Any.shiftLeft(other: Any): Any = TODO()

@Pretty(">>")
infix fun Any.shiftRight(other: Any): Any = TODO()

@Pretty("if")
fun magicIf(condition: Any, block: () -> Unit): Any = TODO()
Now when I write:
Copy code
true `?` 1 orElse 2
true `&` false
1 shiftLeft 2 shiftRight 3
magicIf(true) {
  println("Hello")
}
It displays as the attached image (as long as you turn off the color for folded text in settings)
🆒 1
Looks like it works with emoji too 👀
🔥 2
e

elect

11/24/2023, 10:35 AM
does the completion work just fine? Do you have to type the backticks first?
y

Youssef Shoaib [MOD]

11/24/2023, 12:35 PM
That's the catch yes. You have to type the backticks. I'll look into if there's a way to add those to completion. However, I think using
@Pretty
to change how a function is displayed might be a lot nicer than changing its name to a backticked one.
2 Views