Eclipse Word-Wrap Plug-In

Summary

The Word-Wrap Eclipse plug-in enables the built-in soft text wrap feature in every text-based editor within Eclipse. In general all text widgets based on the Standard Widget Toolkit (SWT) support word wrap. The word wrap plug-in I created is activated on all editors that implement the org.eclipse.ui.IEditorPart interface. This means that you can enhance almost every code editor of Eclipse with the soft wrapping feature (e.g. TextEditor, the JavaEditor of JDT, the C/C++ Editor of CDT or the TeXlipse LaTeX editor)!

In addition to that I wrote a fix for the line number ruler to display the correct line number in combination with the word wrap feature. I also present a solution to make this work with the TeXlipse plug-in.

Introduction

When I found TeXlipse I really liked it and I was glad to find a great replacement for texmaker. Unfortunately it was not very comfortable when it comes to writing long paragraphs because the line wrapping feature (be it soft or hard wrapping) simply did not work. I've looked for a solution and found the Eclipse Word-Wrap plug-in by Ahti Kitsik. Finally I was able to write paragraphs with soft wrapping activated. Two things got in the way: This plug-in was written two years ago and did not survive an update to the current Eclipse version. It simply did not work anymore because it based on an Eclipse extension point that was deprecated. The other thing was the line numbering that never worked together with the soft wrapping feature. This must be the reason why it never showed up as an official Eclipse feature.

There is also a very old reported Eclipse bug that refers to the missing word wrap feature. It seems that there are several people out there who want this feature to be implemented. :-) For more links see the Further Information section.

The first thing I did was to rewrite the word wrap plug-in from scratch to make it work with the latest Eclipse Juno release. The second thing I set as a goal was to get the line numbering to work together with the word wrapping.

The line ruler is created within the Eclipse Platform Text feature and was located in the org.eclipse.jface.text plug-in where I finally found the LineNumberRulerColumn.java class. I played around with the class to see how it worked and was able to implement a correct rendering of the line ruler with word wrap activated. Take a look at the project website to see what I did there in detail.

Screenshots

The word wrap plug-in, the fix of the line ruler and the TeXlipse fix were already tested on Windows 7 and OS X 10.8.2 Mountain Lion with Eclipse Juno (4.2).

Word wrap turned off and on (click to enlarge):

Eclipse editor with word wrap turned off Eclipse editor with word wrap turned on

Folding feature works without problems:

Eclipse editor with word wrap while showing the folding feature

Error marker is displayed where the line number is rendered (in this case an error in line 5 is highlighted):

Eclipse editor with word wrap demonstrating the error marker

The window can still be resized without problems (Screenshot).

In the Eclipse preferences the automatic word wrapping can be enabled and configured for specific file extensions:

Word Wrap preferences in Eclipse

Install (Update Site)

Please select the appropriate update site for your Eclipse version to download the word wrap plug-in and the line numbering ruler fix (In Eclipse: Help > Install New Software...):

For further information about the fixed line numbering ruler in the org.eclipse.jface.text plug-in: See the project website

To remove the plug-ins and use your standard org.eclipse.jface.text plug-in open the "About Eclipse..." > "Installation Dialog" window, select the installed feature and click on "Uninstall...".

Important

In most cases it is necessary to run Eclipse with the -clean parameter after installing the plugins. In OSX use the Terminal and run this command within the Eclipse folder: ./Eclipse.app/Contents/MacOS/eclipse -clean In Windows use the command line or change the shortcut path to eclipse.exe -clean.

Install (Offline)

For the offline installation of the word-wrap plug-in and the line numbering fix you need to download the following files and copy them to your Eclipse /plugin/ folder:

This should override your current org.eclipse.jface.text plug-in because it is newer. If it does not work please use the Eclipse -clean parameter as mentioned in the section above.

For further information about the fixed line numbering ruler in the org.eclipse.jface.text plug-in: See the project website

To remove the plug-ins and use your standard org.eclipse.jface.text plug-in just delete the new files and restart Eclipse.

TeXlipse Fix

If you are using TeXlipse you can install the following fix for the word wrapping to work.

An update for TeXlipse used in Eclipse Juno forced the word-wrap to be always turned off. You can deactivate this behaviour if you follow the instructions below. Consider that this is only a workaround and can be overwritten by a TeXlipse update anytime (tested with version 1.5.0).

How to install the word-wrap plug-in, fix the line numbering and fix the TeXlipse plug-in within Eclipse Juno (4.2):

Usage

Please note that in every text editor the wrapping is turned off by default. You have to activate this by using one of the following three ways to toggle the soft word wrap:

If there should be problems concerning your workspace please temporarily remove the file .metadata\.plugins\org.eclipse.e4.workbench\workspace.xmi and see if that solves the problem. Usually the file serves as a cache for the shortcuts and could prevent the new shortcut from being executed.

In combination with the Subversive SVN Plug-In the shortcut for toggling word-wrap could already be registered by Subclipse. In Eclipse preferences (category General > Keys) the shortcut can be disabled. Now word-wrap keyboard shortcut should work just fine.

Future Development

It would be awesome if this plug-in would make it into the official Eclipse release. Therefore I really appreciate any feedback from you to keep the plug-in free of bugs and problems. Probably you know people who might benefit from this work, so please tell them about it! :-)

Below is a ToDo list for further development and known issues of the word wrap plug-in.

I think the most issues cannot be fixed by a plug-in and it may be necessary to change code within the SWT classes that are responsible for actually wrapping the text (or other classes).

Further Information

Contact

Feel free to contact me and tell me about suggestions, bug reports and comments in general. I really appreciate any feedback and it would be great to hear from you if my work has helped you. You can write in English or German.

E-Mail: flo () cdhq () de (Please add the necessary symbols)