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.

Bug 23571 - Make abbreviations useful: support and include multiline abbrevs
Summary: Make abbreviations useful: support and include multiline abbrevs
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker with 3 votes (vote)
Assignee: issues@editor
URL:
Keywords:
: 8888 20674 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-05-15 23:11 UTC by Torbjorn Norbye
Modified: 2007-11-05 13:44 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
This should provide reformatting of the code when the abbreviation is expanded. (694 bytes, patch)
2002-11-06 02:35 UTC, Mauro Botelho
Details | Diff
Improved (?) patch (745 bytes, patch)
2002-11-25 20:13 UTC, aaime
Details | Diff
Provides variable expansion like eclipse. (13.92 KB, patch)
2002-11-28 01:02 UTC, Mauro Botelho
Details | Diff
Provide variable expansion like eclipse. (662 bytes, patch)
2002-11-28 01:03 UTC, Mauro Botelho
Details | Diff
Provides variable expansion like eclipse (1.46 KB, text/plain)
2002-11-28 01:04 UTC, Mauro Botelho
Details
zipped source files. (6.05 KB, application/octet-stream)
2002-11-30 01:00 UTC, Mauro Botelho
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Torbjorn Norbye 2002-05-15 23:11:13 UTC
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.
Comment 1 Marek Grummich 2002-07-22 10:02:13 UTC
Set target milestone to TBD
Comment 2 Marek Grummich 2002-07-22 10:08:13 UTC
Set target milestone to TBD
Comment 3 aaime 2002-10-17 10:55:14 UTC
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...
Comment 4 Mauro Botelho 2002-11-06 02:35:12 UTC
Created attachment 7860 [details]
This should provide reformatting of the code when the abbreviation is expanded.
Comment 5 aaime 2002-11-06 08:32:40 UTC
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...
Comment 6 Mauro Botelho 2002-11-07 00:33:05 UTC
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.
Comment 7 _ mihmax 2002-11-07 20:57:34 UTC
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
Comment 8 aaime 2002-11-09 17:17:16 UTC
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?) 
Comment 9 aaime 2002-11-09 17:22:53 UTC
*** Issue 20674 has been marked as a duplicate of this issue. ***
Comment 10 aaime 2002-11-09 17:31:00 UTC
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... 
Comment 11 aaime 2002-11-09 17:34:14 UTC
It seems that issue 8572 contains a useful template suggestion...  
psvmain -->   
public static void main (String[] args) { 
	| 
} 
Comment 12 aaime 2002-11-09 17:40:31 UTC
*** Issue 8888 has been marked as a duplicate of this issue. ***
Comment 13 _ mihmax 2002-11-09 18:26:45 UTC
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
Comment 14 aaime 2002-11-09 23:44:20 UTC
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... 
Comment 15 aaime 2002-11-25 20:12:36 UTC
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... 
Comment 16 aaime 2002-11-25 20:13:34 UTC
Created attachment 8048 [details]
Improved (?) patch
Comment 17 Mauro Botelho 2002-11-28 01:02:23 UTC
Created attachment 8076 [details]
Provides variable expansion like eclipse.
Comment 18 Mauro Botelho 2002-11-28 01:03:13 UTC
Created attachment 8077 [details]
Provide variable expansion like eclipse.
Comment 19 Mauro Botelho 2002-11-28 01:04:29 UTC
Created attachment 8078 [details]
Provides variable expansion like eclipse
Comment 20 Mauro Botelho 2002-11-28 01:06:29 UTC
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.
Comment 21 Torbjorn Norbye 2002-11-30 00:44:58 UTC
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
Comment 22 Mauro Botelho 2002-11-30 01:00:31 UTC
Created attachment 8121 [details]
zipped source files.
Comment 23 Torbjorn Norbye 2002-11-30 01:21:05 UTC
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.
Comment 24 Torbjorn Norbye 2002-11-30 01:26:31 UTC
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
Comment 25 Mauro Botelho 2002-11-30 01:32:22 UTC
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.
Comment 26 Torbjorn Norbye 2002-11-30 01:37:44 UTC
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.
Comment 27 Mauro Botelho 2002-11-30 01:39:54 UTC
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.
Comment 28 Jaroslav Tulach 2002-12-03 09:55:22 UTC
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.
Comment 29 aaime 2002-12-03 10:01:26 UTC
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.
Comment 30 _ mihmax 2002-12-03 10:25:09 UTC
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.
Comment 31 Miloslav Metelka 2002-12-03 18:44:03 UTC
We have tested the patch and it appears to work OK. We will continue
the integrations tomorrow.
Comment 32 _ mihmax 2002-12-03 20:12:28 UTC
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

Comment 33 _ mihmax 2002-12-03 20:14:28 UTC
Almost forgot:

Checking in editor/libsrc/org/netbeans/editor/Abbrev.java;
new revision: 1.22.132.1; previous revision: 1.22
done
Comment 34 Martin Roskanin 2002-12-04 09:53:51 UTC
fixed in [maintrunk] also
Comment 35 Martin Roskanin 2002-12-04 10:47:29 UTC
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