Clean source code for email snippet
Posted: 12 Dec 2011 20:40
I use Visual Studio for many of my work-related projects. In VS, I prefer to work with a "dark" UI theme, as I think it's easier on the eyes. So, my editor window has a dark background and the code text is variations of lighter colors. This works great until I have the need to cut/paste a code snippet into an email to send to a colleague. When pasting into Outlook, the theme colors are pasted also, and the result is very hard to read on the white background of the email body.
I have been getting around this problem like this:
- Copy code from VS into clipboard
- In RJTE, create a new, temporary text document
- Paste the copied VS code into the new document (this removes all colorization)
- Copy the newly cleaned code back into the clipboard
- Close the temporary RJTE document.
- Paste the cleaned code into an Outlook email.
While this works well, it's quite quite repetitive in nature. With that in mind, I created the following simple script to automate the task.
Jeff
I have been getting around this problem like this:
- Copy code from VS into clipboard
- In RJTE, create a new, temporary text document
- Paste the copied VS code into the new document (this removes all colorization)
- Copy the newly cleaned code back into the clipboard
- Close the temporary RJTE document.
- Paste the cleaned code into an Outlook email.
While this works well, it's quite quite repetitive in nature. With that in mind, I created the following simple script to automate the task.
Jeff
Code: Select all
#language C++Script
// Remove the VSS theme colorization from clipboard data and put the cleaned code
// back into the clipboard. This makes it possible to email code snippets without
// them containing the VSS theme colors.
{
// Create a new TXT document
MainApp.NewDocument(".txt");
// Paste the clipboard contents into the new doc
Document.PasteFromClipboard;
// Select the entire document
Document.SelectAll();
// Copy the selection to the clipboard
Document.CopyToClipboard();
// Undo the paste to prevent a "Save?" question on doc close
Document.Undo();
// Close the document (cleaned code is in the clipboard)
Document.Close();
// Add message to the status area.
MainApp.SetStatusText("Cleaned text is in the clipboard.");
}