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 30147 - Rebind the Tab key to perform automatic indentation
Summary: Rebind the Tab key to perform automatic indentation
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: All All
: P3 blocker with 5 votes (vote)
Assignee: _ ttran
: 14285 (view as bug list)
Depends on:
Reported: 2003-01-15 16:45 UTC by Torbjorn Norbye
Modified: 2007-11-05 13:42 UTC (History)
2 users (show)

See Also:
Exception Reporter:

Simple patch which implements the requested behavior (8.57 KB, patch)
2003-04-02 17:39 UTC, Torbjorn Norbye
Details | Diff
Patch migrated to NetBeans 5.0 (7.78 KB, patch)
2005-11-06 06:18 UTC, Torbjorn Norbye
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Torbjorn Norbye 2003-01-15 16:45:59 UTC
In JBuilder, the Tab key does not insert \t, it
recenters the current line (or when there is a
selection, it recenters all the lines in the

JBuilder also puts a message in the editor footer:
"Line automatically indented".

I think NetBeans should do the same.  Then it
needs a different key to insert a literal \t. I
think the editor footer message could tell the
user what it is:
  "Line automatically indented. Press Alt+t to
insert a Tab character."

See also the thread on nbusers, subject
"indentation setup", from January 2003. There are
a couple of objections to this. But instead of
continuing a discussion there, I'm filing an issue
such that the ui folks can evaluate this.
Comment 1 Torbjorn Norbye 2003-04-02 17:38:35 UTC
This ui problem (tab key doing the wrong thing) drives me nuts and
keeps sending me back to emacs. But this week I've decided to "fly our
own airplanes", so I wrote a patch to implement this issue. I'll
attach it.
Comment 2 Torbjorn Norbye 2003-04-02 17:39:49 UTC
Created attachment 9669 [details]
Simple patch which implements the requested behavior
Comment 3 Torbjorn Norbye 2003-04-02 17:42:12 UTC
Description of the patch: it creates a new ReindentLineAction, which
it registers and binds to the Tab key. (It also changes the old
insert-tab action to be bound to Control-Q [tab], as well as a
commented out version of Meta-i, which are emacs bindings for it. I'm
not sure what the non-emacs binding for tab should be - check JBuilder
I guess.)

The implementation is very straightforward - it just a copy of the
code in FormatAction, but modified in two ways:
- instead of using the selection begin and end points for formatting,
it uses the current line
- instead of moving the caret to the beginning of the line, it moves
the caret to the first non-whitespace character on the line
Comment 4 bondolo 2003-04-08 18:00:04 UTC
Eeek, how about having hitting tab insert a tab or replace the current
selection with a tab????

I really don't like weird behaviours bound to (unmodified) keys.

The behaviour of hitting tab while having a selection in the middle of
a line NOT replacing the selection is already annoying enough.
Comment 5 Torbjorn Norbye 2003-04-08 18:49:11 UTC
My point (which I made in the nbusers discussion, perhaps not in this
issue report) is that tying the Tab key to indentation is not weird. 
Not all non-modifier keys perform self-insert; the function keys for
example. JBuilder, long the market leading Java IDE, does exactly
this. As does Emacs. Besides, \t's in the source code leads to various
problems since the Java coding style calls for 4-space indentation,
and tabs often default to 8 chars (cvs diff, vi, etc.)

I'm not against allowing Tab to insert \t's, but it should be a
non-default option. I believe more users will benefit from IDE managed
indentation than doing on their own using Tabs.
Comment 6 _ jrichard 2003-07-17 04:43:22 UTC
Two points here:
 - indention is rather broken for multiline statements,
   binding tab to indention would be suprising and annoying
   for this reason

 - appreciation of this is one of those things which really
   depends on your background (emacs vs vi vs visual studio)
Comment 7 Roman Strobl 2005-04-20 16:01:41 UTC
*** Issue 14285 has been marked as a duplicate of this issue. ***
Comment 8 trembovetski 2005-06-09 18:05:54 UTC
Please fix this. I'd expect that most users want the line to be properly aligned
instead of adding a new tab. Certainly true in my case.

Comment 9 Torbjorn Norbye 2005-11-06 06:18:24 UTC
Created attachment 26656 [details]
Patch migrated to NetBeans 5.0
Comment 10 _ ttran 2005-11-11 22:21:45 UTC
Tor's patch refined and applied.  The new action is bound to tab only in Emacs
keymap.  C-q <tab> inserts \t.  Also works on selection.  I also found a bug
68575.  Will fix separately

IDE: [11/11/05 11:10 PM] Committing Files started
Checking in editor/libsrc/org/netbeans/editor/;
/cvs/editor/libsrc/org/netbeans/editor/,v  <--
new revision: 1.141; previous revision: 1.140
Checking in editor/libsrc/org/netbeans/editor/;
/cvs/editor/libsrc/org/netbeans/editor/,v  <--
new revision: 1.71; previous revision: 1.70
Checking in editor/libsrc/org/netbeans/editor/;
/cvs/editor/libsrc/org/netbeans/editor/,v  <--
new revision: 1.65; previous revision: 1.64
Checking in ide/defaults/src/org/netbeans/modules/defaults/Emacs-keybindings.xml;
/cvs/ide/defaults/src/org/netbeans/modules/defaults/Emacs-keybindings.xml,v  <--
new revision: 1.11; previous revision: 1.10
IDE: [11/11/05 11:10 PM] Committing Files finished
Comment 11 _ ttran 2005-11-11 22:22:51 UTC
marked as fixed