Quick tip: Ignoring the Darcs directory in Eclipse

I’m using Darcs on a new project and one annoyance was that when I did, say, a text search, Eclipse would happily descend into the “_darcs” directory and pull up the Darcs internal files in the editor. When I Googled this I found people asking about it but nobody with the answer, which turns out to not be too hard. You can also use this to hide metadata from Monotone or any other system that produces directories you don’t want Eclipse to mess with.

The first thing to deal with is searches. That is very easy: bring up the Properties dialog for the _darcs directory (e.g. via its context menu) and check the “Derived” checkbox. By default, Eclipse will not search derived resources.
But that directory still shows up in various views like Package Explorer. That view in particular has a very easy way to solve the problem, so I’ll describe it first. From the Package Explorer view, click on the little triangular popup menu icon (usually in the upper right). Select “Filters…”. Check the box at the top of the Java Element Filters dialog if it’s not already checked, and add “_darcs” to the list of patterns.

Presto, the _darcs directory will disappear from the Package Explorer view, so you won’t open it accidentally.

Unfortunately, it will still appear in the Navigator view. Fixing that is less straightforward; for some reason Eclipse doesn’t let you add your own patterns to the filters in the Navigator the way it does in the Package Explorer. So you will need to create a working set instead. (This approach will also work with the Package Explorer.)

Once again, click on the popup menu button. This time choose “Select Working Set…”.  Then click “New…” in the dialog. Select “Resource” as the working set type and click Next. Enter a name for your new working set (mine is “Exclude Darcs”). Click “Select All” then, for each project that has a Darcs directory you want to exclude, open it up and deselect that directory. You can also deselect the “.settings” directory and any others you want to hide. Click Finish and select the new working set from the dialog.

That’s all there is to it! You can now work on your project without worrying about stumbling across Darcs’ private copies of your files.

One other approach bears mentioning, though it may not be an option for existing projects: Put a top-level directory in your Darcs tree and use that directory, not the root of your Darcs workspace, as the Eclipse project directory. Then Eclipse will never even know that there is a Darcs directory. But that only works if you own the project and can adjust the directory layout to your liking.

Leave a Reply