In Visual Studio 2010, under Tools -> Options -> Text Editor -> HTML -> Formatting -> Tag Specific Options, there are options for configuring how the editor auto formats differe
Well, there's Edit -> Advanced -> Format Document, which I guess messes your code up as well. I searched loads of documentation trying to find something more, but as far as I can say, there isn't anything.
Edit:
The Problem isn't in the HTML Formatting options but with the <% %> "tag". For example: <h2><span></span></h2>
works quite well. As I said, I don't think this can be done.
For the moment I recommend using:
<h2>
<%="Hello World" %>
</h2>
or
<h2>
<%
if(true)
Response.Write("Hello World");
%>
</h2>
You were looking in the right area:
Tools -> Options -> Text Editor -> HTML -> Formatting -> Tag Specific Options.
However, you need to set the option in "Client tag supports contents", under Default Settings, for Line breaks to "None". Visual Studio is looking at this setting rather than the setting for the <h1 />
tag.
I don't believe this will give you the spacing inside the <% %>
tag that you want, but it will fix those pernicious extra line breaks.
[EDIT] I had initially said to set the option for "Server tag supports contents", but I think it's actually "Client tag supports contents" (I changed this above). You can also set the "Line breaks" setting to "Before and after" instead of to "None" if that better gives you what you are looking for. You may also need to set Line breaks for "Client tag does not support contents" to "None".
Indeed there is no any significant difference between the two folders (Client and ASP.NET) from the VS's point of view. They exist just for convenience. The fact is that the tag is recognized only by its name and (luckily) VS ignores it's not a true tag. Therefore you can put subject settings in either of the folders. Even more one can create (what personally I did) another folder (called, for example, Expressions) and store settings there.
Concerning changing "Default Settings". If one wants to change settings only for a few tags then IMHO it should be better to create/change the rules for these tags themselves rather than changing the defaults (appears that h1-h6 rules are missing withing the default set of rules).
Thanks to @schellack for the knudging me in the right direction. Here are the settings I needed to get the behavior I wanted (all within the tag specific options dialog box):
The trick is that the editor seems to recognize <% %> blocks as a client tag named '%' that has no closing tag. Same deal for <%: %> and <%= %>.
With these settings (combined with the rest of the defaults in Visual Studio) I get formatted markup that looks like the following (which is the compact form I was looking for):
<h1><%: Model.Name %></h1>
<ul>
<% foreach (var item in Model.Items) { %>
<li><%: item %></li>
<% } %>
</ul>
As yet, it doesn't appear that the second part of my question is possible.