Quick Tip #7 - Macros in Editor
As promised, today's tip is about macros. What are they? These are actions which are recorded according to what you do in the editor. Depending how good you are, you can create even such action such as surround with try-catch, comment a piece of code, etc.
You can record the macros by pressing the red button in editor toolbar, perform the actions and then end recording by pressing the grey square next to the button. Then you name the macro and assign a shorcut to it. To execute the macro, you just need to press the shortcut you've assigned.
Michel Graciano from Brazil has prepared some great macros and you can download them
here. Similarly to
abbreviations the content of the zip should be placed into the directory ~/.netbeans/4.1/config/Editors/text/x-java. Make sure to backup all XML files this may replace. The abbreviations in abbreviations.xml are necessary to execute the macros (they contain few more than last time), the keybindings.xml file sets the shortcuts. Macros.xml file contains macros recorded by Michel.
Here are the available macros:
| Shortcut | Action |
| Ctrl-J I | Surround with if() |
| Ctrl-J T | Surround with try-catch |
| Ctrl-J L | Add debug code |
| Ctrl-N P | Create property |
| Ctrl-J { | Add a block |
| Ctrl-J H | Comment code |
| Ctrl-N F | Define identifier by previous class |
| Ctrl-N S | Delete two words |
| Ctrl-J C | Trim |
| Alt-U Q | Toggle case of identifier |
| Ctrl-J [ | Format code |
| Ctrl-J D | Debug variable |
| Ctrl-J F | Add editor fold |
Most of these macros require to have selected a piece of code in the clipboard. You may not use all of these, but they're a good source of inspiration for creating your own macros. Actually this way you can add simple features to your IDE. How cool is that? :-)
Posted by Michel Graciano on červen 15, 2005 at 10:17 odp. CEST #
Posted by Roman Strobl on červen 15, 2005 at 11:36 odp. CEST #
A good enhancement would be for the IDE to autodetect a situation in the editor that requires the macro to be offered to be run. For example, say, the code is at a point where a try-catch block or Exception declaration is needed, the IDE then offers a popup with choices of "Surrounding with a Try-Catch Block" or "Declare Exception in the method". When one of these is chosen by user, the appropriate macro is run. This would be very cool to have and more interactive.
Perhaps even better would be a framework that allows for custom macros to be defined to be offered to be played at certain custom defined situations for users to create. Hope to see this sometime in the future.
Posted by Shreedhar on červen 19, 2005 at 06:34 odp. CEST #
Posted by Roman Strobl on červen 19, 2005 at 06:38 odp. CEST #
Posted by manoj on říjen 25, 2005 at 08:30 dop. CEST #
Posted by Roumen on říjen 26, 2005 at 02:11 odp. CEST #