How to restrict who may read my entries?
[editor] NetBeans editor support for tabs
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > Java Programming > [editor] NetBeans editor support for tabs 1 December 2000 16:23:21

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

[editor] NetBeans editor support for tabs

Bill Shannon 1 December 2000 16:23:21
 I've started using NetBeans recently and ran into a number of
problems, one of which was that the editor didn't work the way I
thought it should work.

The problem is that I *don't* want the editor to expand tabs.
However, I *do* want the editor to support indenting my code by
4 spaces. I do this in vi by setting shiftwidth to 4, setting
autoindent on, and using CTRL-T. (Using CTRL-T is a pain, so I
actually hacked vi to allow me to type TAB instead of CTRL-T.)
It's been awhile since I used it, but I believe the old Java
Workshop editor did pretty much what I want.

Using the NetBeans editor, if I turn off "expand tabs", then all
indenting is done in terms of the tab size, 8 spaces. Not what
I want at all.

The NetBeans editor has the following settings, that interact in
some undesirable ways:

expand tabs- whether to expand tabs to spaces
tab size- where the "tab stops" are, should always be 8
spaces per tab- how much to indent when you type tab, set to 4 by default
shift width- if expand tabs is true, then spaces per tab, else tab size

It's pretty clear how to set the first three from the various properties
windows, but I don't know if it's possible to set shift width independently
of the others. There also doesn't seem to be any consistency in the code
for when to use the shift width and when to use the other properties.

The problem I have with the current approach is that the "spaces per tab"
setting is ignored if "expand tabs" is not set. The behavior I'd like
is to turn off "expand tabs" and then...

- if I type TAB followed by some text at the beginning of the line,
the TAB is replaced by 4 spaces.
- if I type TAB, TAB, and then some text, the line starts with a real
TAB character followed by the text.
- if I shift a line right, and the indent ends with a TAB, 4 spaces
are inserted.
- if I shift a line right, and the indent ends with 4 spaces, the spaces
are replaced by a real TAB character.
- and so on...

I hope I've described this clearly. This is effectively what vi does
with the settings I listed above.

Please don't suggest setting the tab size to 4, that's not at all what
I want! Getting every other program I use and everyone else who looks
at my code to understand a non-standard tab size is hopeless. And don't
suggest that I just turn on "expand tabs", that makes it far too easy to
accidentally end up with a non-standard indent. This is probably just a
holdover from my C coding days where we always used full tab indents,
but for whatever reason this is the way I prefer for things to work.

So, to make this work, the link between "expand tabs" and "shift width"
needs to be broken.

I've prototyped some changes that seem to do what I want it to do.
I've tested the changes using the demo program that allows me to run
the editor kit standalone, pretty cool! I'd like to get these changes
into NetBeans somehow, but of course someone who really understands
the code needs to evaluate my changes. Plus, I'm not really CVS fluent
so I'm looking for someone who can integrate the changes for me.

In making my changes I haven't really worried about compatibility,
mostly because the current approach just seems wrong to me. However,
if complete compatibility with the current approach is important, these
changes will have to be done differently, and will likely become much
more complex.

Any comments and help are appreciated! Thanks!

Bill Shannon


-----

Following are the diffs from my prototype. They need to be cleaned
up a bit but they should give you an idea of the magnitude of the
changes. These are all classes in the org.netbeans.editor­ package.



In getShiftWidth, if the shift width has not been set explicitly,
it always defaults to "spaces per tab", ignoring "expand tabs".

*** BaseDocument.javaFr­i Nov 17 20:08:05 2000
--- ../BaseDocument.jav­aSat Nov 18 23:38:31 2000
***************
*** 848,854 ****

} else {
Formatter f = getFormatter();
! return f.expandTabs() ? f.getSpacesPerTab()­ : getTabSize();
}
}

--- 848,854 ----

} else {
Formatter f = getFormatter();
! return /*f.expandTabs()*/ true ? f.getSpacesPerTab()­ : getTabSize();
}
}



In InsertTabAction, use a new method I introduced that properly
inserts tabs in the middle of a line.

*** BaseKit.javaFri Nov 17 23:47:03 2000
--- ../BaseKit.javaFri Nov 17 23:48:37 2000
***************
*** 803,810 ****
--- 803,813 ----
}
doc.getFormatter().­changeRowIndent(doc,­ dotPos, indent);
} else { // already chars on the line
+ doc.getFormatter().­insertTabString(doc,­ dotPos);
+ /*
doc.insertString(do­tPos, Utilities.getTabIns­ertString(doc, dotPos),
null);
+ */
}
} catch (BadLocationExcepti­on e) {
// use the same pos



1. As with BaseDocument, ignore "expand tabs" for default shift width.
2. New insertTabString method to insert a tab in the middle of a line,
with possible non-whitespace text earlier in the line. Unlike the
method this replaces, this has to be smart enough to remove whitespace
preceding the current position and replace it with tabs.
3. In shiftLine, the indent should be based on the visual column. The
old code assumed that all whitespace had been converted to space
characters and it only counted character positions. Obviously this
doesn't work if there's a tab character in the line.

*** Formatter.javaFri Nov 17 20:08:05 2000
--- ../Formatter.javaSa­t Nov 18 23:42:54 2000
***************
*** 187,193 ****
}

return (shiftWidth != null) ? shiftWidth.intValue­()
! : (expandTabs() ? getSpacesPerTab() : getTabSize());
}

/** Set the width of one indentation level for non-BaseDocument documents.
--- 187,193 ----
}

return (shiftWidth != null) ? shiftWidth.intValue­()
! : (/*expandTabs()*/tr­ue ? getSpacesPerTab() : getTabSize());
}

/** Set the width of one indentation level for non-BaseDocument documents.
***************
*** 339,344 ****
--- 339,366 ----
}
}

+ /** Modify the line to move the text starting at dotPos one tab
+ * column to the right. Whitespace preceeding dotPos may be
+ * replaced by a TAB character.
+ * @param doc document to operate on
+ * @param dotPos insertion point
+ */
+ public void insertTabString(Bas­eDocument doc, int dotPos)
+ throws BadLocationExceptio­n {
+ doc.atomicLock();
+ try {
+ int startPos = Utilities.getFirstN­onWhiteBwd(doc, dotPos) + 1;
+ int startCol = Utilities.getVisual­Column(doc, startPos);
+ int endCol = Utilities.getNextTa­bColumn(doc, dotPos);
+ String tabStr = new String(Analyzer.cre­ateWhiteSpaceFillBuf­fer(
+ startCol, endCol, getTabSize()));
+ doc.remove(startPos­, dotPos - startPos);
+ doc.insertString(st­artPos, tabStr, null);
+ } finally {
+ doc.atomicUnlock();­
+ }
+ }
+
/** Shift line either left or right */
public void shiftLine(BaseDocum­ent doc, int dotPos, boolean right)
throws BadLocationExceptio­n {
***************
*** 348,354 ****
}

if (Utilities.isRowWhi­te(doc, dotPos)) {
! ind += dotPos - Utilities.getRowSta­rt(doc, dotPos);
} else {
ind += Utilities.getRowInd­ent(doc, dotPos);
}
--- 370,376 ----
}

if (Utilities.isRowWhi­te(doc, dotPos)) {
! ind += Utilities.getVisual­Column(doc, dotPos);
} else {
ind += Utilities.getRowInd­ent(doc, dotPos);
}



I turned off "expand tabs" for testing, although I believe with these
changes it could be turned off by default and you would see essentially
the same behavior in almost all cases, with the added bonus of using
real tab characters! Ok, I understand why you might not want to change
the default...

*** SettingsDefaults.ja­vaFri Nov 17 19:56:47 2000
--- ../SettingsDefaults­.javaFri Nov 17 22:30:39 2000
***************
*** 125,131 ****
= new Integer(defaultMark­Distance.intValue() * 7);
public static final Integer defaultLineBatchSiz­e = new Integer(2);

! public static final Boolean defaultExpandTabs = Boolean.TRUE;

public static final String defaultCaretTypeIns­ertMode = BaseCaret.LINE_CARE­T;
public static final String defaultCaretTypeOve­rwriteMode = BaseCaret.BLOCK_CAR­ET;
--- 125,131 ----
= new Integer(defaultMark­Distance.intValue() * 7);
public static final Integer defaultLineBatchSiz­e = new Integer(2);

! public static final Boolean defaultExpandTabs = Boolean.FALSE;

public static final String defaultCaretTypeIns­ertMode = BaseCaret.LINE_CARE­T;
public static final String defaultCaretTypeOve­rwriteMode = BaseCaret.BLOCK_CAR­ET;



1. Deprecate getTabInsertString because it doesn't do the right thing.
2. In getNextTabColumn, ignore "expand tabs". I don't understand why
this method doesn't just use the "shift width". Or maybe I don't
understand who should be calling this method instead of doing a
similar computation based on the shift width. This method only
seems to be called from InsertTabAction. I don't understand what's
supposed to happen in various cases if "shift width" and "spaces
per tab" are different.

*** Utilities.javaFri Nov 17 20:18:35 2000
--- ../Utilities.javaSa­t Nov 18 23:46:08 2000
***************
*** 652,666 ****
return doc.op.getLineCount­();
}

public static String getTabInsertString(­BaseDocument doc, int offset)
throws BadLocationExceptio­n {
int col = getVisualColumn(doc­, offset);
Formatter f = doc.getFormatter();­
! boolean expandTabs = f.expandTabs();
if (expandTabs) {
int spacesPerTab = f.getSpacesPerTab()­;
int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
return new String(Analyzer.get­SpacesBuffer(len), 0, len);
} else { // insert pure tab
return "\t"; // NOI18N
}
--- 652,668 ----
return doc.op.getLineCount­();
}

+ /** @deprecated see Formatter.insertTab­String */
public static String getTabInsertString(­BaseDocument doc, int offset)
throws BadLocationExceptio­n {
int col = getVisualColumn(doc­, offset);
Formatter f = doc.getFormatter();­
! boolean expandTabs = /*f.expandTabs()*/t­rue;
if (expandTabs) {
int spacesPerTab = f.getSpacesPerTab()­;
int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
return new String(Analyzer.get­SpacesBuffer(len), 0, len);
+ // XXX - doesn't do the right thing
} else { // insert pure tab
return "\t"; // NOI18N
}
***************
*** 670,676 ****
throws BadLocationExceptio­n {
int col = getVisualColumn(doc­, offset);
Formatter f = doc.getFormatter();­
! boolean expandTabs = f.expandTabs();
int tabSize = expandTabs ? f.getSpacesPerTab()­ : doc.getTabSize();
return (col + tabSize) / tabSize * tabSize;
}
--- 672,678 ----
throws BadLocationExceptio­n {
int col = getVisualColumn(doc­, offset);
Formatter f = doc.getFormatter();­
! boolean expandTabs = /*f.expandTabs()*/t­rue;
int tabSize = expandTabs ? f.getSpacesPerTab()­ : doc.getTabSize();
return (col + tabSize) / tabSize * tabSize;
}

Add comment
Ivan Soleimanipour 22 November 2000 02:05:23 permanent link ]
 Hear hear!

One way to sumarize all of this (:­-) is that having the TAB character expand
to <n> spaces is the wrong approach because while things will look
right under the editor, once they are printed or cated or mored
or emailed it will look different, especially if people mix using tabs
and spaces.

A TAB character should always imply 8 spaces!

Indentation mechanisms in the editor should use TABs as needed to
achieve indentation. For example if indent is set to 4 then use four
spaces for one level of indent, a tab for two levels of indent,
a tab and four spaces for three levels of indent etc.


Add comment
Trung Duc Tran 22 November 2000 20:59:00 permanent link ]
 On Tue, 21 Nov 2000 15:05:23 -0800 (PST) Ivan Soleimanipour> <Ivan.Soleimanipour­@Eng.Sun.COM> wrote:
Hear hear!>
One way to sumarize all of this (:­-) is that having the TAB character expand> to <n> spaces is the wrong approach because while things will look> right under the editor, once they are printed or cated or mored> or emailed it will look different, especially if people mix using tabs> and spaces.>
A TAB character should always imply 8 spaces!


right, but what should we do if someone else screws things up? There is
an unnamed widely used IDE on Windows where the tab width is set to 4
spaces by default. To view sources created in that IDE we need to set
our tab width to 4 spaces too. I would leave all options open to the
user but the defaults should be the right values.
Indentation mechanisms in the editor should use TABs as needed to> achieve indentation. For example if indent is set to 4 then use four> spaces for one level of indent, a tab for two levels of indent,> a tab and four spaces for three levels of indent etc.

Agreed

-- Trung

Add comment
Bill Shannon 22 November 2000 22:00:05 permanent link ]
 
From: Trung Duc Tran <trung.duc.tran@net­beans.com>> To: nbdev@netbeans.org>­ Date: 22 Nov 2000 18:59:00 +0100> Subject: Re: [nbdev] [editor] NetBeans editor support for tabs>
On Tue, 21 Nov 2000 15:05:23 -0800 (PST) Ivan Soleimanipour> > <Ivan.Soleimanipour­@Eng.Sun.COM> wrote:>
Hear hear!> >
One way to sumarize all of this (:­-) is that having the TAB character expand> > to <n> spaces is the wrong approach because while things will look> > right under the editor, once they are printed or cated or mored> > or emailed it will look different, especially if people mix using tabs> > and spaces.> >
A TAB character should always imply 8 spaces!>
right, but what should we do if someone else screws things up? There is> an unnamed widely used IDE on Windows where the tab width is set to 4> spaces by default. To view sources created in that IDE we need to set> our tab width to 4 spaces too. I would leave all options open to the> user but the defaults should be the right values.

I'm certainly not suggesting that the ability to do that should be removed.


Add comment
Bill Shannon 23 November 2000 04:50:51 permanent link ]
 I've seen no objections and some support for my proposal so I'd
like to wrap up the loose ends and close this.

Here's my open issues:

1. I'd like someone to explain to me the strategy for the use of "shift
width" in the code so that I can make sure the new code I'm adding
is consistent with that strategy. When should code use "shift
width" vs. "spaces per tab" vs. "tab size"? How does a user change
"shift width" independently of "spaces per tab" and "tab size", and
why would they want to do that? Which keyboard commands should
operate in terms of "shift width" vs. "spaces per tab" vs. "tab
size"?

2. Has anyone looked over my actual code changes and do you have
any comments?

3. Should I simply remove the Utilities.getTabIns­ertString, or
should I just deprecate it and leave it broken and unused?

4. I think my changes are complete, is there anything obvious I missed?

5. Is there any documentation I need to update?

6. Are there any particular tests I should perform to ensure that my
changes are correct?

I'll send updated diffs when I get answers to some of these questions.

Thanks for your help.

Bill

Add comment
Miloslav Metelka 23 November 2000 14:12:03 permanent link ]
 Hi Bill,
sorry for the delay with responding. I've already looked to your code and
currently I'm in the process of summarizing the changes that we need to do
in the editor code to implement the behavior that you request.
Anyway what is clear is that we need a customizer for the
INDENT_SHIFT_WIDTH setting. This setting is not visible under properties of
the indentation engine, because we don't have a proper customizer yet. I
didn't want it to be a simple integer property because in that case it
wouldn't change in case the TAB_SIZE or SPACES_PER_TAB settings get changed.
Instead I wanted to have a customizer where you could have an expression
where there could be some symbols instead of TAB_SIZE, SPACES_PER_TAB and
EXPAND_TABS because the INDENT_SHIFT_WIDTH is often related to these.
There is no default value for the INDENT_SHIFT_WIDTH currently (unless you
set it manually). If there is no value the Formatter computes the
INDENT_SHIFT_WIDTH in the following way:
INDENT_SHIFT_WIDTH = EXPAND_TABS ? SPACES_PER_TAB : TAB_SIZE
You can set the INDENT_SHIFT_WIDTH manually by executing the following code
by Internal execution:
Settings.setValue(J­avaKit.class, SettingsNames.INDEN­T_SHIFT_WIDTH, new
Integer(4));
However it will only work until restart. For the permanent solution please
look at
http://editor.netbe­ans.org/doc/Customiz­eEditor/CustomizeEdi­tor.html
Using this set of classes you can also replace the default InsertTabAction.
You just need to create the action named DefaultEditorKit.in­sertTabAction
(it's "insert-tab") and add it to CUSTOM_ACTION_LIST.­
We need to change the TAB behavior to be customizable too.
I will let you know as soon as I will have the final solution for this.
Mila

Add comment
Trung Duc Tran 23 November 2000 18:15:40 permanent link ]
 when we are talking about expanding tabs, something comes to my mind.
In makefiles one often has things like this

myprog : myprog.c
cc -o myprog myprog.c

The so-called command line "cc -o myprog myprog.c" must be prefixed by a
tab character whatever the current user setting for expanding tabs.
This is required by "make". I know emacs handles this correctly. Is
our builtin editor able to handle special cases like this one?

-- Trung

Add comment
Bill Shannon 24 November 2000 01:00:39 permanent link ]
 
From: Miloslav Metelka <miloslav.metelka@n­etbeans.com>> To: "'nbdev@netbeans.or­g'" <nbdev@netbeans.org­>> Subject: RE: [nbdev] [editor] NetBeans editor support for tabs>
Hi Bill,> sorry for the delay with responding. I've already looked to your code and> currently I'm in the process of summarizing the changes that we need to do> in the editor code to implement the behavior that you request.

Do you think there are changes that are necessary in addition to what
I changed?
Anyway what is clear is that we need a customizer for the> INDENT_SHIFT_WIDTH setting. This setting is not visible under properties of> the indentation engine, because we don't have a proper customizer yet. I> didn't want it to be a simple integer property because in that case it> wouldn't change in case the TAB_SIZE or SPACES_PER_TAB settings get changed.> Instead I wanted to have a customizer where you could have an expression> where there could be some symbols instead of TAB_SIZE, SPACES_PER_TAB and> EXPAND_TABS because the INDENT_SHIFT_WIDTH is often related to these.

Can you describe the intent of the separate INDENT_SHIFT_WIDTH setting?
(See my previous message for more questions about this.)

Do you believe that adding an INDENT_SHIFT_WIDTH customizer is necessary
before fixing the tab behavior, as I did with my changes? Seems like
these could be two separate changes. Fixing the tab behavior was relatively
simple, and I've already got the changes necessary for that. Adding a
customizer for INDENT_SHIFT_WIDTH looks like more work. I wouldn't like
to see that hold up my fixes.
There is no default value for the INDENT_SHIFT_WIDTH currently (unless you> set it manually). If there is no value the Formatter computes the> INDENT_SHIFT_WIDTH in the following way:> INDENT_SHIFT_WIDTH = EXPAND_TABS ? SPACES_PER_TAB : TAB_SIZE> You can set the INDENT_SHIFT_WIDTH manually by executing the following code> by Internal execution:> Settings.setValue(J­avaKit.class, SettingsNames.INDEN­T_SHIFT_WIDTH, new> Integer(4));> However it will only work until restart. For the permanent solution please> look at> http://editor.netbe­ans.org/doc/Customiz­eEditor/CustomizeEdi­tor.html> Using this set of classes you can also replace the default InsertTabAction.> You just need to create the action named DefaultEditorKit.in­sertTabAction> (it's "insert-tab") and add it to CUSTOM_ACTION_LIST.­

Are you suggesting that I should take this approach to changing the tab
behavior to do what I want, rather than fixing the base code to behave
appropriately? I don't believe this will work because of the other code
that ties together "expand tabs" and "shift width".
We need to change the TAB behavior to be customizable too.

In what new ways do you want to customize tab behavior?
I will let you know as soon as I will have the final solution for this.

Great, thanks!

Bill

Add comment
Miloslav Metelka 1 December 2000 02:47:06 permanent link ]
 Hi Bill,
I agree with you that making a customizer for INDENT_SHIFT_WIDTH would be
time consuming. The INDENT_SHIFT_WIDTH determines the width of one
indentation level of the code. In general it can differ from what is
inserted by Tab key by using SPACES_PER_TAB (e.g. somebody could want to
have SPACES_PER_TAB = 2 * INDENT_SHIFT_WIDTH)­. However the number of these
users will probably be low.
I have added your proposed changes to the editor code in main trunk. I have
modified it slightly but the resulting functionality should be the same.
Once you and our testers confirm that it works OK I will probably backport
it to 3.1 too. I think that the new behavior shouldn't affect users too
much. The only change is in case the user has 'Expand tabs to Spaces' set to
true. Then the Tab key will not insert '\t' character with the default
settings. However the user can restore the original behavior by setting the
'Number of Spaces Per Tab' to be the same as 'Tab Size'.
In addition to these changes I would like to add the possibility to make
the Ctrl+T/D to snap to the shiftwidth multiplies. Right now it only
adds/subtracts the INDENT_SHIFT_WIDTH to/from current indent (or visual
column for the caret position in case there is only whitespace on the line).

Mila
-----Original Message-----> From: Bill Shannon [mailto:Bill.Shannon@Eng.Sun.COM]> Sent: Thursday, November 23, 2000 11:01 PM> To: nbdev@netbeans.org>­ Subject: RE: [nbdev] [editor] NetBeans editor support for tabs>
From: Miloslav Metelka <miloslav.metelka@n­etbeans.com>> > To: "'nbdev@netbeans.or­g'" <nbdev@netbeans.org­>> > Subject: RE: [nbdev] [editor] NetBeans editor support for tabs> >
Hi Bill,> > sorry for the delay with responding. I've already looked > to your code and> > currently I'm in the process of summarizing the changes > that we need to do> > in the editor code to implement the behavior that you request.>
Do you think there are changes that are necessary in addition to what> I changed?>
Anyway what is clear is that we need a customizer for the> > INDENT_SHIFT_WIDTH setting. This setting is not visible > under properties of> > the indentation engine, because we don't have a proper > customizer yet. I> > didn't want it to be a simple integer property because in > that case it> > wouldn't change in case the TAB_SIZE or SPACES_PER_TAB > settings get changed.> > Instead I wanted to have a customizer where you could have > an expression> > where there could be some symbols instead of TAB_SIZE, > SPACES_PER_TAB and> > EXPAND_TABS because the INDENT_SHIFT_WIDTH is often > related to these.>
Can you describe the intent of the separate > INDENT_SHIFT_WIDTH setting?> (See my previous message for more questions about this.)>
Do you believe that adding an INDENT_SHIFT_WIDTH customizer > is necessary> before fixing the tab behavior, as I did with my changes? Seems like> these could be two separate changes. Fixing the tab behavior > was relatively> simple, and I've already got the changes necessary for that. Adding a> customizer for INDENT_SHIFT_WIDTH looks like more work. I > wouldn't like> to see that hold up my fixes.>
There is no default value for the INDENT_SHIFT_WIDTH > currently (unless you> > set it manually). If there is no value the Formatter computes the> > INDENT_SHIFT_WIDTH in the following way:> > INDENT_SHIFT_WIDTH = EXPAND_TABS ? SPACES_PER_TAB : TAB_SIZE> > You can set the INDENT_SHIFT_WIDTH manually by executing > the following code> > by Internal execution:> > Settings.setValue(J­avaKit.class, > SettingsNames.INDEN­T_SHIFT_WIDTH, new> > Integer(4));> > However it will only work until restart. For the > permanent solution please> > look at> >
http://editor.netbe­ans.org/doc/Customiz­eEditor/CustomizeEdi­tor.html> Using this set of classes you can also replace the default
InsertTabAction.> You just need to create the action named DefaultEditorKit.in­sertTabAction> (it's "insert-tab") and add it to CUSTOM_ACTION_LIST.­

Are you suggesting that I should take this approach to changing the tab
behavior to do what I want, rather than fixing the base code to behave
appropriately? I don't believe this will work because of the other code
that ties together "expand tabs" and "shift width".
We need to change the TAB behavior to be customizable too.

In what new ways do you want to customize tab behavior?
I will let you know as soon as I will have the final solution for this.

Great, thanks!

Bill
Add comment
Bill Shannon 1 December 2000 03:13:18 permanent link ]
 
From: Miloslav Metelka <miloslav.metelka@n­etbeans.com>> To: "'nbdev@netbeans.or­g'" <nbdev@netbeans.org­>> Subject: RE: [nbdev] [editor] NetBeans editor support for tabs>
Hi Bill,> I agree with you that making a customizer for INDENT_SHIFT_WIDTH would be> time consuming. The INDENT_SHIFT_WIDTH determines the width of one> indentation level of the code. In general it can differ from what is> inserted by Tab key by using SPACES_PER_TAB (e.g. somebody could want to> have SPACES_PER_TAB = 2 * INDENT_SHIFT_WIDTH)­. However the number of these> users will probably be low.

I agree. And what I'm still trying to understand is why there are three
parameters here when two would seem to be enough. Being able to set the
"hardware tab stops" is important to some people, but most of us will just
leave it set at 8. Setting the "indentation level" is the key parameter
for most people. Currently the "spaces per tab" parameter has that effect.
Is there really a need for a third setting, independent of those two? Just
thinking about how this all could be simplified, or at least rationalized...
I have added your proposed changes to the editor code in main trunk. I have> modified it slightly but the resulting functionality should be the same.> Once you and our testers confirm that it works OK I will probably backport> it to 3.1 too.

Wonderful, thanks!

I think that the new behavior shouldn't affect users too> much. The only change is in case the user has 'Expand tabs to Spaces' set to> true. Then the Tab key will not insert '\t' character with the default> settings. However the user can restore the original behavior by setting the> 'Number of Spaces Per Tab' to be the same as 'Tab Size'.

I think you mean "when 'Expand tabs to Spaces' is set to false". Yes, the
behavior is different in that case. Since that's not the default setting,
hopefully that won't cause a big problem, and as you say people can easily
change the settings to behave as before.
In addition to these changes I would like to add the possibility to make> the Ctrl+T/D to snap to the shiftwidth multiplies. Right now it only> adds/subtracts the INDENT_SHIFT_WIDTH to/from current indent (or visual> column for the caret position in case there is only whitespace on the line).

Yes, that might be useful.

Add comment
Miloslav Metelka 1 December 2000 16:23:21 permanent link ]
 
I think you mean "when 'Expand tabs to Spaces' is set to false". Yes, the> behavior is different in that case. Since that's not the default setting,> hopefully that won't cause a big problem, and as you say people can easily> change the settings to behave as before.

Yes, sorry, thanks for correction.
I agree with you that making a customizer for > INDENT_SHIFT_WIDTH would be> > time consuming. The INDENT_SHIFT_WIDTH determines the width of one> > indentation level of the code. In general it can differ > from what is> > inserted by Tab key by using SPACES_PER_TAB (e.g. somebody > could want to> > have SPACES_PER_TAB = 2 * INDENT_SHIFT_WIDTH)­. However the > number of these> > users will probably be low.>
I agree. And what I'm still trying to understand is why > there are three> parameters here when two would seem to be enough. Being able > to set the> "hardware tab stops" is important to some people, but most of > us will just> leave it set at 8. Setting the "indentation level" is the > key parameter> for most people. Currently the "spaces per tab" parameter > has that effect.> Is there really a need for a third setting, independent of > those two? Just> thinking about how this all could be simplified, or at least > rationalized...>

I have used the similar settings with VIM for writing mainly a C/C++ code
few years ago. I had (translated into nbeditor settings) the
INDENT_SHIFT_WITH=2­ and SPACES_PER_TAB=8. For initial indentation on the
line the autoindent was usually OK and if not I have pressed Ctrl+T/D to
adjust it (by shifting by 2). The benefit was when I was writing line
comments. I wanted to have them all to be indented usually at certain column
e.g. 60 (in fact I think it was 56 because it was a multiple of 8). Even
when I have written a short line I was able to reach the column 56 with only
several TAB presses. If I would have SPACES_PER_TAB=2 (equal to shiftwidth)
I would have to press the TAB 4 times more than with the SPACES_PER_TAB=8 to
reach the 56 column. Later in NetBeans I have changed the code style to use
INDENT_SHIFT_WIDTH=­4. With more and more java code I have also relaxed line
comment aligning. Now I usually only leave one space after the code and
start the line comment. I know that I'm only one user but I can imagine that
someone else wishing a nice looking code could want to use the similar
configuration too. BTW We could think about adding some code beautifying
logic to the java indent engine that would align line comments equally but
it's of course P5 enhancement.

Let me summarize the current settings after the changes done yesterday:
TAB_SIZE: "Tab Size" under Editor Settings-> <editor-type> - number of
spaces the editor display engine substitutes when it finds '\t' in the text.
I agree with you that the user should leave it to be the default i.e. 8. Not
doing so will make his documents incompatible with the rest of the world.
BTW We think that this property belongs to the document properties (not to
the pluggable Indentation Engine) so it's not present under Indentation
Engine properties (like the rest of the following options is).
EXPAND_TABS: "Expand Tabs" in Indentation Engine properties - when set to
true the editor will not use '\t' characters for inserts. Instead it will
use spaces in the insert and formatting operations. However if there are
existing '\t' characters (when the document is loaded they are not touched)
they will still be present (so the TAB_SIZE setting is still important). The
document can be reformatted to have all the '\t' replaced by spaces or vice
versa (BTW we should probably provide an action that would only replace the
tabs by spaces or vice versa without touching the indentation).
SPACES_PER_TAB: "Number of Spaces per Tab" in Indentation Engine properties
- number of spaces substituted when a TAB key is pressed. When EXPAND_TABS
is false the editor will logically replace the preceding spaces on the line
by '\t' character where possible. BTW I think that the current state is
probably better because it allows to preserve the old operation (inserting
the '\t' character) but allows the operation that you have requested too.
SHIFT_WIDTH - Currently not visually configurable, but it can be configured
by code - number of spaces substituted per one indentation level. If not set
explicitly it defaults to SPACES_PER_TAB. When EXPAND_TABS is false the
editor will logically replace the indentation spaces on the line by '\t'
character where possible.

There is always a question of what the users will understand. I believe
that the current state is understandable for the users i.e. everything
except the shiftwidth is visually configurable. On the other hand I believe
that if we make some additional comments the users looking into the editor
source code should be able to understand that there is the
INDENT_SHIFT_WIDTH setting that can be possibly configured.

Mila

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > Java Programming > [editor] NetBeans editor support for tabs 1 December 2000 16:23:21

see also:
[Security & JAAS/JBoss]…
[Messaging, JMS & JBossMQ] - JMS…
[Security & JAAS/JBoss] - Re: Creating…
пройди тесты:
see also:
How to strip DRM off iTunes M4P music…
How to transfer iTunes M4P music to…
How to import iTunes M4P music to…

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .