Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Auto-format on Save
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

FriendlyRabbit
Junior Member

Germany
23 Posts

Posted - Feb 10 2025 :  02:41:40 AM  Show Profile  Reply with Quote
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.

feline
Whole Tomato Software

United Kingdom
19110 Posts

Posted - Feb 10 2025 :  09:48:09 AM  Show Profile  Reply with Quote
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.

zen is the art of being at one with the two'ness
Go to Top of Page

FriendlyRabbit
Junior Member

Germany
23 Posts

Posted - Feb 11 2025 :  01:35:58 AM  Show Profile  Reply with Quote
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.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19110 Posts

Posted - Feb 11 2025 :  08:00:29 AM  Show Profile  Reply with Quote
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

zen is the art of being at one with the two'ness
Go to Top of Page

FriendlyRabbit
Junior Member

Germany
23 Posts

Posted - Feb 12 2025 :  01:22:38 AM  Show Profile  Reply with Quote
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
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19110 Posts

Posted - Feb 12 2025 :  07:45:05 AM  Show Profile  Reply with Quote
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!

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000