The background: I'm a dyed-in-the-wool Emacs user who dabbles in a lot of languages. Recently a Famous Engineer upbraided me for continuing to use Emacs in this day and age, and I wish to put this Famous Engineer's chiding to the test. (This Famous Engineer happens to be partial to NetBeans, but we'll let that slide for the moment. ;-) ) So I'm getting myself acquainted with Eclipse, and I want to find out just how programmable it is.
How would you go about designing a command for Eclipse that does the following to a selection of code?
I'm not looking for code snippets per se, but pointers to what I should be doing. Do I need to write a full-out plugin for this? Should I be looking at macro facilities? What APIs will help me out, and where are they documented (if anywhere)? Are there any examples already out there of doing this kind of ad-hoc but programmatic text manipulation in Eclipse?
For this problem, I'm looking for a solution that's as lightweight (read: easy to hack up) as possible...
Thinking about a vanilla Eclipse installation, I think the closest you could get would be creating a formatter template for SO. There may be 3rd party plugins which give a more advanced interface though.
As far as plug-ins go however, I think this one would be pretty simple. I'd guess you could look at how the line-comment (Ctrl-/) command works to see both how to create a command and how to "extend the selection so that complete lines are selected." I would imagine "untabifying" would be some very simple string manipulation, as would inserting a 4-space block. Finally, copying to the clipboard is a pretty common Java task (see this link, or look at Toolkit.getSystemClipboard();
). As you might guess, the real work just comes in putting together the pieces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With