https://kotlinlang.org logo
#intellij
Title
# intellij
e

Ellen Spertus

08/17/2022, 7:34 PM
It makes me sad that there is no way to globally set Actions on Save to Reformat Code for all new projects. I'm a professor and will have to tell my students to do that every time they create a project. I hope someone can let me know a workaround or upvote the issue. https://intellij-support.jetbrains.com/hc/en-us/community/posts/7178879949842-Is-there-a-way-to-set-Actions-on-Save-for-all-new-projects-
K 1
👍 1
s

sreich

08/18/2022, 6:22 PM
OMG YES. THIS. Thank you i was thinking my environment was messed up. This has bothered me b ecause i come to import a new maven project and each time see this is off. I thought it was random because i switch b/w a lot of projects before
actions on save
there is a plugin that is actually more elaborate than this, i think it's called
save actions
. i have thought about switching back to that. it can also do other fun things
🙏 1
e

Ellen Spertus

08/18/2022, 6:31 PM
@sreich Thanks for the commiseration and letting me know about the plugin. Do you know if it works for all projects or needs to be set individually?
s

sreich

08/18/2022, 6:32 PM
i'm pretty sure it's global
e

Ellen Spertus

08/18/2022, 6:33 PM
Hallelujah!
s

sreich

08/18/2022, 6:34 PM
install it and give it a shot
e

Ellen Spertus

08/18/2022, 6:35 PM
I'm on it!
The settings do not work for new projects. 😭
s

sreich

08/18/2022, 7:06 PM
nooooo
e

Ellen Spertus

08/18/2022, 7:09 PM
I'm going to need to apply for a job at JetBrains unless someone who works there already takes pity on us. https://twitter.com/swaglord__420/status/1377051721655066629
@antonarhipov I see you're a Developer Advocate and one of my closest JetBrains connections on LinkedIn. Can you please help with this? 🙏
a

antonarhipov

08/19/2022, 8:13 AM
@Ellen Spertus “Actions on Save to Reformat Code” — I sense some Eclipse habits 🙂
I think it would be much easier for you just to remap the formatting key to Cmd+S/Ctrl+S as you don’t push them in IntelliJ anyway because of autosaving feature
I don’t have a better workaround 🤷 But perhaps the plugin helps
e

Ellen Spertus

08/19/2022, 4:24 PM
Remapping Cmd+S/Ctrl+S is a great idea, although I don't know if young ones are as compulsive about pressing it as I am.
The inability to set it across projects undermines DRY.
a

antonarhipov

08/19/2022, 4:28 PM
Another option is to check the correct formatting inspection before commit and then make sure there are no warnings before commit
s

sreich

08/19/2022, 4:42 PM
what do you mean, eclipse habits? what would your approach be for code formatting?
a

antonarhipov

08/19/2022, 4:51 PM
When you type with shortcuts in Intellij, in most cases your code will end up correctly formatted. Save on actions is the feature in eclipse and most users develop a habit pressing Ctrl+s for saving the file and consequently executing the additional actions. In Intellij, there is just a different shortcut for formatting as saving of files is automatic, so if Ctrl+s shortcut is already so deep in the muscle memory, you can just assign Ctrl+s to reformatting action However, formatting a full file isn't a very good approach anyway. Especially when working on large code bases, in branches, in teams. You can change a line of code and unintentionally reformat a large file, making the change too big for the code review
e

Ellen Spertus

08/19/2022, 6:41 PM
Students will sometimes be pasting in code (from the instructor, not just from Stack Overflow). Having the code automatically properly formatted would save the students and graders lots of grief.
s

sreich

08/19/2022, 6:42 PM
@antonarhipov that is why save on actions has the ability to reformat only changed lines. idk about them, i don't use ctrl-s. i auto save and i expect my IDE to reformat my code as i go
9 Views