Scott Dorman

ephemeral segment

  Home  |   Contact  |   Syndication    |   Login
  566 Posts | 9 Stories | 573 Comments | 51 Trackbacks

News


Post Categories

Image Galleries



Creative Commons License


Microsoft MVP


MCP Profile


Locations of visitors to this page

Subscribers to this feed

TwitterCounter for @sdorman

View blog authority

Add to Technorati Favorites

Windows Live Alerts

AddThis Social Bookmark Button

LinkedIn profile

Community Credit profile

The Code Project

Follow me on Twitter

Get Free Shots from Snap.com

Community Credit Hall of Fame

Get Feedghost

Xobni outlook add-in for your inbox

Windows Live Translator


Support This Site

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

A few days ago in one of the CodeProject disucssion forums someone was looking for a way to easily remove the extra vertical whitespace in a file. This is really handy if you copy and paste code from the web or otherwise have a file that has multiple consecutive blank lines that you want to consolidate to a single blank line.

A solution was presented that used a Visual Studio macro, but that macro used pattern matching with find and replace, so it didn’t feel very stable. Taking the opportunity to dig into Visual Studio macros again, I created a more full-featured version of this macro.

This macro uses the selection object of the active document and iterates over each line. Once it finds a blank line, it then advances over the following lines, deleting them until it finds a non-blank line again. At the end, it runs the format document command.

The macro is available on my SkyDrive account. Download it to your <UserProfile>\Documents\Visual Studio 2008\Projects\VSMacros80\MyMacros folder, open the Visual Studio Macro IDE (Alt-F11) and add it as an existing item to the “MyMacros” project.

I make no guarantees or warranties on this macro. I have tested it on several solutions and projects and everything seems to work and not cause any problems, but, as always, use with caution. Since it is a macro, you have the full source code available to investigate and see what it’s actually doing. If you find any bugs or make any useful changes, please let me know and I’ll update the macro.

Technorati Tags: ,
Digg This
posted on Thursday, September 18, 2008 12:06 PM