Eclipse copy code with syntax highlighting
Asked Answered
S

5

20

I'm writing a document of programming guidelines for my developers team. I use MS Word. We work with Eclipse CDT (C++). I need to copy-paste C++ code with syntax highlighting from Eclipse to Word. I've tried Notepad++ and it can export text with syntax highlighting, but it's highlighting is limited to basic syntax (it doesn't know about defined class, enum etc...). Eclipse syntax highlighting is very powerful and I wish to export directly from Eclipse to Word using it's syntax highlighting.

Is there any Eclipse plugin that achieve this purpose? Or some trick to do it (without taking a screen snapshot)?

Stolzer answered 5/12, 2011 at 13:49 Comment(0)
T
22

When you copy the code to word document, you can choose the option "keep source formatting" and the highlighting will be the same as the one in eclipse.

EDIT:

As mentioned in the comments below, this won't work on folded code, so you can right click on the line numbers and select Folding > Expand All

EDIT 2: Also mentioned in the comments, as of eclipse oxygen, the code is automatically copied with syntax highlighting

Tonneson answered 5/12, 2011 at 13:53 Comment(6)
It was so simple! Eclipse supports rtf copy from version 3.2!Stolzer
@AlessandroPezzato Yup, everything is always more simple than it looks :)Tonneson
Make sure you have 'toggle mark occurrences' off, otherwise that marking will be copied too.Snaffle
Watch out for folded code. See: cmanios.wordpress.com/2012/03/08/…Aigneis
@espertus +1 That was what I needed to know. If there is anything folded it just reverts to a text copy and doesn't tell you why. You can right click on the line numbers and select Folding>Expand All to fix.Mend
As of Eclipse Oxygen (2018-01-04) there is no option "keep source formatting" that I can see... code is copied with formatting if the selected code contains NO FOLDED CODE ... otherwise it is copied in horrid black and white.Warnerwarning
A
3

When I copy from Eclipse straight to PowerPoint some of the formatting is messed up. Bold and color seems to "keep going". But if I copy from Eclipse to Word -- and then from Word to PowerPoint (with the keep source formatting CNTRL-K) -- the formatting is correct. I recently upgraded Eclipse to Mars and Office to 2013. I still have to go through Word first.

Arnitaarno answered 31/7, 2015 at 9:59 Comment(1)
Also works with LibreOffice Writer: copy to Writer, then recopy elsewhere (Google Docs in my case).Tjader
N
0

I was trying it too and for some reason not every compile unit would keep the formating.

After a while I've seen that you also won't get the formating kept if there are parts of the code hidden, so for the ones that cannot make it work with the answers above, just make sure that there are no "+" signs on the left of your code (mine were where the imports at the beggining).

Nicknickel answered 3/9, 2016 at 16:13 Comment(0)
S
0

Copying of formatting is supported since version 3.2

Note that everything is copied: highlighting of spelling errors, marked variables/types/etc and underscoring of warnings/errors.

To avoid that, turn off spell checking, "Mark Occurrences" and "Report problems as you type" respectively.

Sorcim answered 19/1, 2018 at 9:14 Comment(0)
L
0

Make sure the the selected contains no folded code.

Lightning answered 13/10, 2023 at 0:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.