This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
All the abbreviations for java are currently simple phrases, like a keyword or a couple of words (like System.out.println). "re" is an abbrevation for return. This is really painful, since a common phrase used in comments is "we're" which expands to "we'return". (Example: "// Here we're expecting a value of " This is common coding style. Can you consider making that "ret" instead? A larger issue however is that "re->return" isn't a particularly helpful abbreviation. A much more useful one would be: tryc -> try { | } catch (Exception e) { } or even addact -> addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { | } }); There are three issues here: (1) The default abbreviations that we ship with NetBeans aren't very useful (except for sout); please add a bunch of constructs like the above (2) Even if the user attempts to add these themselves (like I did) they are not handled correctly by the editor; the code is not correctly indented. If I'm in code like this: { // Now let's try to open the file tryc[space] I end up with { // Now let's try to open the file try { } catch (Exception e) { } (e.g. the second line and on are not indented correctly) There is also a problem in that when you look at the abbreviations list, multiline abbreviations have square boxes instead of \n's where the linebreaks occur. (3) Some of the abbreviations ("re" in particular) is in the way for normal usage.
Set target milestone to TBD
I strongly agree with tor, this would be a huge gain in productivity, and moreover other java editors do this well (see JBuilder). Voting for this issue...
Created attachment 7860 [details] This should provide reformatting of the code when the abbreviation is expanded.
Is this patch agains what version of Netbeans? CVS Head, 3.4? I would like to push it for the netbeans 3.4.1 release...
This patch can be applied to any version post 3.4 for sure, but maybe earlier versions. So including it on 3.4.1 would be great.
Hi, All, I've added this as a candidate for 3.4.1, but this is RFE, not a bug, so even though it's P2, it's not a MUST HAVE in 3.4.1 If any of you wants to see this in 3.4.1, please, make some work: 1. checkout netbeans sources (module standard_nowww with release34 tag) But be aware that you will need to do the checkout several times, because CVS server is almost dead, please vote for issue # 28380. 2. apply the attached diff to the proper file. 3. compile Netbeans (run nbbuild/build.xml), start the newly compiled, and test. Feedback here, I'm CC'd, so I'll surely waiting for the test results. Sincere, Maxym Mykhalchuk
I've tried the patch and it works for the examples suggested by Tor, and also for other I tested (like ife -> if() { } else {} on multiple lines, switch with one case and defalt, and so on). Really great, I cannot see any problem with this patch... now, is it worth doing some more formal testing? (like automated unit tests?)
*** Issue 20674 has been marked as a duplicate of this issue. ***
Ah, BTW, some people on nbusers complained that the standard abbreviations gets in the way... uhm, maybe netbeans should do what jbuilder does, that is, require you to press CTRL-J in order to expand an abbreviation... or maybe a configurable option, like as with code completion -> automatic as a default, triggered by a shortcut otherwise...
It seems that issue 8572 contains a useful template suggestion... psvmain --> public static void main (String[] args) { | }
*** Issue 8888 has been marked as a duplicate of this issue. ***
2 Editor people: ???: Where are the default abbraviation, SettingsDefaults.java contains only defaultAbbrevMap = new HashMap(); 2 Andrea: if you could write unit tests, that would be great, but if you don't - please, find more "fans" of multiline abbreviations, and ask them to test. Also please ask at nbusers about whether this RFE is useful enough to have it in 3.4.1, if feedback is positive, then it will go into 3.4.1 Thanks for volunteering to push it alive ;) 2 Mauro: please, vote for this issue if you are the fan ;) Thanks for the patch Sincere, Maxym Mykhalchuk, Merak Release Coordinator
Well, I know how to use the JUnit, but the problem is how do I interact with the netbeans code in order to verify the behaviour is the one expected (I've never looked at netbeans internals nor to the api required to write modules...) As for finding new fans, as you see I've tried to find duplicates, but ok, I will also write a public message on nbusers tomorrow to ask for voting, testing and listing useful abbreviations...
An issue has been raised that the current patch removes trailing spaces for single line abbreviations. The patch I'm going to attach is a very simple modification that keeps the trailing spaces for single line abbreviation while allowing for multiline reformatting on multi line abbreviations... works for me on Linux, not tested on other platforms...
Created attachment 8048 [details] Improved (?) patch
Created attachment 8076 [details] Provides variable expansion like eclipse.
Created attachment 8077 [details] Provide variable expansion like eclipse.
Created attachment 8078 [details] Provides variable expansion like eclipse
I don't know if it should be here, but I attached diffs for variable expansion like eclipse. I'll send a message to nbdev describing the feature better.
I'd like to try this feature. But I get failures applying the diffs, both on current development sources, and on 3.4 sources. Can you tell me which version this is relative too? Or better yet, instead of / in addition to posting diffs, can you post the complete modified source files (just as a single zip instead of multiple attachments) ? patch -p0 --dry-run < Abbrev.diff patching file `org/netbeans/editor/Abbrev.java' Hunk #1 FAILED at 14. Hunk #2 FAILED at 41. Hunk #3 FAILED at 80. Hunk #4 FAILED at 259. Hunk #5 FAILED at 421. Hunk #6 FAILED at 440. 6 out of 6 hunks FAILED -- saving rejects to org/netbeans/editor/Abbrev.java.rej
Created attachment 8121 [details] zipped source files.
Wow - that was fast service!! I noticed two problems; first, you should include build.xml in the patch; regexp needs to be added to the libsrc build (I got lots of class RE not found errors). After that, I got a compilation error complaining about cannot resolve symbol symbol : variable SHIFT_DOWN_MASK location: class java.awt.event.InputEvent editorUI.getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), (Object)PREVIOUS_VARIABLE_ACTION); This looks like a JDK1.4 dependency; when I switched to compiling with JDK1.4 it compiled just fine. Ooh, this is nice! I like it! I ran into a couple of problems. I wrote an abbreviation like this: (name = "tryc") try { | catch (Exception e) { ErrorManager.notify(e); } (yup, I should parameterize that like your iterator example - that's next!) Anyway, the first time I tried this, the cursor didn't end up intended on the try line - it was flushed left. Is this because of the "remove whitespace at the end of the line" discussion I saw mentioned? Please keep the above example in mind - I'm adding a line with ONLY whitespace. The second problem is that after trying out the iterator example you gave on nbdev (which worked beautifully), typing "tryc " no longer has an effect - but I verified the abbreviation is still there.
Small bug report; I was not doing any abbreviation substitutions; I had deleted the text I had inserted using an abbreviation. I had selected some text; out of XEmacs-habit I pressed the tab key. I got the following NPE: java.lang.NullPointerException at org.netbeans.editor.Abbrev.replaceAbbreviationVar(Abbrev.java:510) at org.netbeans.editor.Abbrev.moveToNextVar(Abbrev.java:465) at org.netbeans.editor.Abbrev.access$100(Abbrev.java:42) at org.netbeans.editor.Abbrev$AbbreviationCompletionAction.actionPerformed(Abbrev.java:545) at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1512) at javax.swing.JComponent.processKeyBinding(JComponent.java:2435) at javax.swing.JComponent.processKeyBindings(JComponent.java:247
Tor, the reason the cursor flushed left is that I reformat the code after I insert it, if the line is empty I think that the reformatter removes all white spaces. One way of solving this could be to reformat in two parts, before the cursor and after it. This could become tricky :) Regarding the tryc not expanding, could it be due to the completion not being finished? I block any other completions until you finish the one you started. Just to prevent nested completion.
I think this is a cornercase which just deserves special checking. When you have the cursor position on an empty line "|", compute the correct indentation level and put the cursor there (ignoring the number of spaces in the actual abbreviation). The intent I had was for the cursor to be where I wanted to start typing, and when it was flushed left it wasn't. Regarding the no-expansion: it's possible; I'll check again. I'd suggest that if you're "eating" abbreviation requests, you issue a beep or a status-message (already expanding abbreviation; cannot abbreviate yet. Press Escape to return to normal mode) or something like that.
I'm researching how to do it right now. I also think that the null pointer exception you got happened while you were in the abbreviation mode. I'm testing it.
Hi. This issue is marked as 3.4.1_CANDIDATE. It means that it should be integrated into release341 one branch. The plan at http://www.netbeans.org/devhome/docs/releases/34/index.html expected beta1 to be produced on Dec01. That did not happen due to a lot of outstanding not integrated candidates like this one. Would it be possible to spend few minutes by backporting this fix? Thank you in advance.
The "2002-11-25 12:13 PST: Abbrev.diff" attachment is against 3.4 and works for me, I can't speak for the latter diffs which also add variable expansion. I think the latter is a new feature, btw, so I'm not sure about integration in 3.4.1. I don't have cvs access so I can't integrate the patch... Maxym, I guess it's up to you to decide, but anyway someone with cvs access should decide whether integrate the patch or not... If you need more testing, information, whatever, just ask.
Hi, netbeans core developers, may you review the recently proposed patch http://www.netbeans.org/issues/showattachment.cgi?attach_id=8048&file=Abbrev.diff ? I think it's OK (reviewed, should make no harm). 2Mauro: Please file separate issue and attach your files there, because I plan to integrate & close this issue, and your proposal may be forgotten. Thanks.
We have tested the patch and it appears to work OK. We will continue the integrations tomorrow.
Patch commited to release341 branch. Great thanks to Mauro Botelho and Andrea Aime. Miloslav, Don't forget to commit to trunk, mean while I close this as fixed. Sincere, Max
Almost forgot: Checking in editor/libsrc/org/netbeans/editor/Abbrev.java; new revision: 1.22.132.1; previous revision: 1.22 done
fixed in [maintrunk] also
fixed in [prj40_prototype] /cvs/editor/libsrc/org/netbeans/editor/Abbrev.java,v <-- Abbrev.java new revision: 1.22.100.1; previous revision: 1.22 [maintrunk] diff: /cvs/editor/libsrc/org/netbeans/editor/Abbrev.java,v <-- Abbrev.java new revision: 1.23; previous revision: 1.22