Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Auto-format on Save

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
FriendlyRabbit Posted - Feb 10 2025 : 02:41:40 AM
Can you please add an option to trigger "Format document" on save? That would spare me from using "Ctrl-K Ctrl-D" all the time.
5   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Feb 12 2025 : 07:45:05 AM
I never did ask which version of Visual Studio you were using, that's what I get for assuming it was VS2022. I am glad this helped though!
FriendlyRabbit Posted - Feb 12 2025 : 01:22:38 AM
Thank you for bringing this to my attention. I am currently stuck with VS 2017, which does not offer such a feature. But this plugin on the page you mention works for me.

https://marketplace.visualstudio.com/items?itemName=mynkow.FormatdocumentonSave
feline Posted - Feb 11 2025 : 08:00:29 AM
According to this page:

https://stackoverflow.com/questions/59839395/how-do-you-auto-format-code-in-visual-studio-on-save

turning On:

IDE tools menu -> Options -> Text Editor -> Code Cleanup -> Run Code Cleanup profile on Save

will do this. But from clicking on the "Configure Code Cleanup" link, it does depend on what you have the profile set to do, since it looks like you can remove the format step if you really want to. Or, perhaps more helpfully, you can remove all other steps, only leaving code formatting.

Not an option I knew about to be honest, but there are quite a few options to check over
FriendlyRabbit Posted - Feb 11 2025 : 01:35:58 AM
Yes, it happens while you type but it does not work reliably. It can only format the current line which is not enough when the semantics change. Here is an example:


// type
if (true) puts("Hi");
//then add
  else puts("Hello");
// In my case, a newline is added between else and puts() but the if line is not changed.

// Reformatting the document makes it 
if (true)
  puts("Hi");
else
  puts("Hello");


Stuff like this also happens if I wrap something in a namespace or block. Or when I have a typo causing the IDE to be confused about nesting or whether a name is a variable or a function, formatting can go wild.

Reformatting the whole document is the only way to guarantee stable formatting. Truth is I often have to trigger formatting manually.

I can understand you want to stay out of formatting, clang-format is already a great tool for that. My wish is just to trigger the IDE's formatting on save, basically hitting "Ctrl-K Ctrl-D" automatically on each save.
feline Posted - Feb 10 2025 : 09:48:09 AM
Isn't Visual Studio doing formatting as you edit?

Which version are you using? Mostly we try to stay out of formatting, since there are SO many different opinions on correct formatting, and the IDE has built in formatting options. It also supports ClangFormat. Normally all of this happens as you edit, at least this is my experience.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000