1

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...).

idbrii
  • 10,975
  • 5
  • 66
  • 107

5 Answers5

2

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.

Zoë Peterson
  • 13,094
  • 2
  • 44
  • 64
  • 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. – idbrii Jun 27 '09 at 01:39
1

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.

idbrii
  • 10,975
  • 5
  • 66
  • 107
0

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
  • 132,184
  • 23
  • 144
  • 116
  • 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 – idbrii May 09 '09 at 00:24
  • Did you try opening the HTML code in a browser, copying the diff and pasting it in Outlook? – Ayman Hourieh May 09 '09 at 00:26
  • With some work, this could be the best solution. You could make a script to copy a diff to clipboard: output diff, load it in vim, use `:TOhtml` to convert it to html, pass it to something that will put it on the clipboard as rich text (instead of html code). `xclip -t text/html` would do the last part on Linux, so maybe it can work under cygwin. – idbrii May 09 '15 at 14:42
0

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, diffing specific revisions requires calling rtfdiff from command line (the custom tool just diffs against HEAD).

p4v custom tool definition (write this to tool.xml and then import it in p4v's Manage Custom Tools menu):

<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 %*

That will let you right click on a file and select "RTF Diff" or call rtfdiff.bat via command line (rtfdiff.bat file.txt#1 file.txt#2).

idbrii
  • 10,975
  • 5
  • 66
  • 107
  • Can you explain in detail how you achieved the above. I have a perforce changelist which I would like to get it reviewed and having a colored output with additions and deletions would be very helpful. – codingbbq May 05 '15 at 11:02
  • I'm not sure if perforce still provides p4diff.exe, but I've made the above steps more explicit. I've since learned that the default diff can take a `-u` for unified diff (possibly need to `set P4DIFF=` to use default), but I don't know if `p4 diff -u` would give syntax colouring. – idbrii May 09 '15 at 14:12
0

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
Send mail from a Windows script
using CDO

Community
  • 1
  • 1
76mel
  • 3,993
  • 2
  • 22
  • 21