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:

ShortcutAction
Ctrl-J ISurround with if()
Ctrl-J TSurround with try-catch
Ctrl-J LAdd debug code
Ctrl-N PCreate property
Ctrl-J {Add a block
Ctrl-J HComment code
Ctrl-N FDefine identifier by previous class
Ctrl-N SDelete two words
Ctrl-J CTrim
Alt-U QToggle case of identifier
Ctrl-J [Format code
Ctrl-J DDebug variable
Ctrl-J FAdd 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? :-)
Comments:

Thank's a lot for your tip publication. There are somne problems in that macros, and the worse is the fact that your clipboard is lost qhen you use a macro. If somebody know how do that appropriately, please tell us. []'s

Posted by Michel Graciano on červen 15, 2005 at 03:17 odp. CEST #

I'll ask the editor developers if anything can be done about the clipboard. Michel, what are the other problems?

Posted by Roman Strobl on červen 15, 2005 at 04:36 odp. CEST #

Very cool indeed.

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 11:34 dop. CEST #

Well that would be very nice, but probably not easy to implement. The functionality you are writing about is available through editor hints (in alpha stage), I wrote about them earlier. Also the surround with try-catch action was added to editor context menu in recent daily builds (with a few bugs :-)

Posted by Roman Strobl on červen 19, 2005 at 11:38 dop. CEST #

how do i get the class name in the following macro : copy-to-clipboard caret-end-line insert-break "if(DEBUG" caret-end-line "System.out.println(\\"" paste-from-clipboard ";" for which I select the method name before calling it. The purpose is to produce the following: if(DEBUG)System.out.println("Method Name"); I want to add the class name as well ...

Posted by manoj on říjen 25, 2005 at 01:30 dop. CEST #

I don't think that this is be possible but I may be wrong - I've just never seen such usage. Feel free to file an RFE for this.

Posted by Roumen on říjen 26, 2005 at 07:11 dop. CEST #

Post a Comment:
Comments are closed for this entry.
About

Roman Strobl

Search

Archives
« duben 2014
PoÚtStČtSoNe
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today