views:

459

answers:

5

How can I copy diff output (diff old-version.cpp new-version.cpp) into an Outlook email so I can send it to other people with syntax highlighting?

I'd either like to pipe diff output to a program that will copy it to the clipboard with formatting (p4 diff file.cpp | rtfpatch) or have a plugin for Outlook that lets me select some text, click a button, and it gets colorized.

I use Windows (XP and Vista), Perforce, Visual Studio, Beyond Compare 3, Outlook 2007. Anything using a combination of those tools would work great (I'm not looking to change my main diff program, etc...).

A: 

Many editors have the ability to export syntax-highlighted files as HTML. From there, you can paste the HTML into Outlook. For example, to export a file to HTML in Vim, use :TOhtml.

This Visual Studio addon offers the "export to HTML" functionality as well. It's worth giving it a try.

Ayman Hourieh
There is another question[1] with similar answers, but I was hoping for something easier.Also, I tried using Vim like you described, but when I pasted it into Outlook (send format set to HTML), it pasted as html code. When I sent it to myself, it was still html code. [1]: http://stackoverflow.com/questions/225830/syntax-highlighting-when-pasting-into-emails
pydave
Did you try opening the HTML code in a browser, copying the diff and pasting it in Outlook?
Ayman Hourieh
A: 

I figured out a solution to make a batch file that diffs files from Perforce using the p4diff.exe program.

The problem with it is p4diff outputs the whole file, not only the changed sections (I'd also prefer unified diff). Also, this solution has to be used on the command line to do different revisions.

p4v custom tool definition:

<CustomToolDef>
  <Definition>
    <Name>RTF Diff</Name>
    <Command>c:\scripts\rtfdiff.bat</Command>
    <Arguments>%f</Arguments>
  </Definition>
  <AddToContext>true</AddToContext>
</CustomToolDef>

where rtfdiff.bat is

:: Use p4diff to get copy-pasteable diff output.

:: setlocal so we use the default after script terminates
setlocal
set P4DIFF=c:\Perforce\p4diff.exe
:: Diff all inputs to allow multiple revisions (must be in increasing order)
p4 diff %*
pydave
A: 

To paste the html into into outlook you should try an past it into th source of the msg. Right click the body of the HTML message and the select View source, then past your html into that.

The other way would be to script it in a batch file using and set the Message html body to equal your html text and send. There are quite a few examples of sending email via script on stackoverflow. There are a number of ways to do it depending what you have installed etc. one example is

http://stackoverflow.com/questions/152323/send-mail-from-a-windows-script

using CDO

76mel
+1  A: 

You can use Beyond Compare's "Text Compare Report" command in the Session menu to do this. Use the "Interleaved" layout style, the "HTML Report" output style and the "Copy to Clipboard" command and it will copy it to the clipboard as colored HTML. I don't have Outlook to test with, but it certainly works pasting it into Word.

Craig Peterson
That works really well! The interleaved output isn't the easiest to read. Especially if you don't have a wide screen (and have long code lines : ( But it works and there are other options. Too bad none of the patch report layouts have colour.
pydave
A: 

Another decent solution I've found is a vim plugin. cliphtml.vim gives you the :ClipHtml ex command that will copy the whole file or the selected region to the clipboard with vim's highlighting.

Requires python.

pydave