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 168495 - Tab key, insert 2 spaces in yaml
Summary: Tab key, insert 2 spaces in yaml
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: YAML (show other bugs)
Version: 7.0.1
Hardware: All All
: P3 blocker with 6 votes (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
: 160489 193373 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-07-13 16:40 UTC by humphrey
Modified: 2012-05-12 09:55 UTC (History)
7 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description humphrey 2009-07-13 16:40:04 UTC
tabs should insert 2 spaces, or at least have the option to, when in yaml files
Comment 1 hansbrix 2009-07-17 21:11:41 UTC
the yaml format disallows tabs, so i think this is an important fix!
Comment 2 CheeseSucker 2011-10-20 04:10:04 UTC
Bumping up the priority of this one, as adding tabs break your YAML files. Netbeans should force spaces.
Comment 3 CheeseSucker 2011-10-20 04:13:40 UTC
*** Bug 193373 has been marked as a duplicate of this bug. ***
Comment 4 CheeseSucker 2011-10-20 04:13:46 UTC
*** Bug 160489 has been marked as a duplicate of this bug. ***
Comment 5 Petr Jiricka 2011-11-23 10:28:48 UTC
I tried this, and the behavior I observed is the following:

1. By default, when I type Tab in a YAML file, it is converted to two spaces, so this is correct
2. In IDE options, under Editor -> Formatting, I can uncheck Expand Tabs to Spaces
3. After this, when I type Tab, it is not converted to spaces, which is a bug

The workaround is to 
#1 - use the default and do not uncheck Expand Tabs to Spaces - this is recommended anyway for most languages
#2 - if you uncheck Expand Tabs to Spaces, do not use Tab key in YAML files, and instead just type 2 spaces

So this is a valid bug, but P3 is a more appropriate priority.
Comment 6 Ondrej Brejla 2012-05-04 13:32:17 UTC
Not sure if it's a P3 bug...because you CAN use tabs in yaml, but you can't use it for indenting. You can use it in value parts, in strings, etc. The only place, where you can't use em is for indenting.
Comment 7 Amnzero 2012-05-04 13:35:22 UTC
(In reply to comment #6)
> Not sure if it's a P3 bug...because you CAN use tabs in yaml, but you can't use
> it for indenting. You can use it in value parts, in strings, etc. The only
> place, where you can't use em is for indenting.

you can use it for indenting as long as you're consistent. mixing space indentations with tabs won't work, only using tabs or spaces does.
Comment 8 Ondrej Brejla 2012-05-04 13:50:59 UTC
Ok, I didn't know that. Ok, so we can force the Editor to ignore that "Expand tabs" option and we can
expand it everytime. Maybe it could be a solution. Current yaml support isn't good enough to catch these little differences (where we are, what kind of indentation we use, etc.)...so one coding style will be the best solution I think. Spaces everywhere.
Comment 9 Amnzero 2012-05-04 13:53:31 UTC
(In reply to comment #8)
> Ok, I didn't know that. Ok, so we can force the Editor to ignore that "Expand
> tabs" option and we can
> expand it everytime. Maybe it could be a solution. Current yaml support isn't
> good enough to catch these little differences (where we are, what kind of
> indentation we use, etc.)...so one coding style will be the best solution I
> think. Spaces everywhere.

I'd prefer tabs really ;) so I suggest we stick to whatever is set in the preferences. Convert tabs to spaces checked? then spaces. Else, tabs. Everyone is happy.

Except maybe the ones that need to adjust netbeans.
Comment 10 Guile 2012-05-04 14:01:14 UTC
http://www.yaml.org/spec/1.2/spec.html#id2777534
Official specs say "To maintain portability, tab characters must not be used in indentation"
Comment 11 Amnzero 2012-05-04 14:08:22 UTC
(In reply to comment #10)
> http://www.yaml.org/spec/1.2/spec.html#id2777534
> Official specs say "To maintain portability, tab characters must not be used in
> indentation"

You are correct.

I disagree with the specs on it though. If I'm not mistaken, a tab character is simply a "\t" char. I can't see how different systems treat it differently.

What I can see happening though, is different systems using a different tabsize, i.e. one system uses the whitespace of 4 spaces to indicate one tab, whilst another system might use 8. However as also stated in the yaml specs, it's the amount of indention that matters, not the size of the indention.


I could be wrong on this, would appreciate extra insight.
Comment 12 Ondrej Brejla 2012-05-04 14:09:57 UTC
Now the behavior is set exactly as Amnzero said...everything depends on your
"Expand tabs" option. I also think that it's correct behavior :) And I thought
exactly what Guile wrote...that tabs can't be used for indentation.

So here are 2 possibilities now.

1) let everything be as is...everyone can say what will a behavior of his tabs
(it's my personal choice)
2) I can enable "everytime expanding", so no tab char will be possible in text

No other possibilities can't be applied now, in this Yaml support
implementation.

Yes, there is just one possibility, to enable only tabs and disable expanding,
but it has no sense...

So, what? Let it be?
Comment 13 Amnzero 2012-05-04 14:14:08 UTC
Ah. I just realized something.

It's about netbeans v7, and v7 already converts to tabs. v6 actually forced spaces, which was probably one of the duplicate bugs I was subscribed to.

Just checked v7, I got tabs when I pressed tab, so honestly I'm happy the way it is right now.



According to specs, it should insert spaces, yes. But please don't. :D
Comment 14 Ondrej Brejla 2012-05-04 14:15:57 UTC
Maybe the second possibility would be better...because, how often do you use
tab for indenting yaml structure, and how often do you use it for "tab char"
elsewhere...
Comment 15 Ondrej Brejla 2012-05-04 14:19:06 UTC
Hehe...so inconsistent users...hard to make a correct decision. I think that I will close this issue as incomplete... We can then wait for other user responses...or we can wait for brand new yaml support...

Any other solution of this issue will be wrong for someone.
Comment 16 Amnzero 2012-05-04 14:24:18 UTC
OK wait there's something else.

Say you're using tabs for indention, and you're on a tab-indented line and press enter, the auto indention on the new line actually consists of spaces. That is an issue, as it breaks the parsing of the yaml file because of the tab/space mix.

With that in mind forcing spaces for indentation would fix this issue and would be according to official yaml specs as well.
Comment 17 Ondrej Brejla 2012-05-04 14:35:30 UTC
Yes...seems that IT's that problem. I have "Expanding tabs" set to off...so I'm indenting using tabs (which is allowed by parsers). And if I press enter at the end of line, new line indentation is constructed by spaces...and that's the problem. Ok, thanks.

The second solution could solve this problem.
Comment 18 Ondrej Brejla 2012-05-04 15:01:06 UTC
Ok, I'll fix it by just another possibility :)

The indentation type (tabs or spaces) after enter at the end of line will correspond to setting of "Expand tabs" in Tools -> Options -> Editor -> Formatting.

1) If you have this option UNchecked - you want to use tabs (e.g. for indenting, everywhere, ...)

Then if you enter at the end of line, only TABS will be places into indenting part.

2) If you have "Expand tabs" CHECKED (you want to use just spaces, e.g. for indentation, etc)

Then if you enter at the end of line, only SPACES will be present in indenting part.

I think, that it's the most correct behavior, am I right?
Comment 19 Amnzero 2012-05-04 15:03:32 UTC
I would very much like that solution :)
Comment 20 Guile 2012-05-04 15:16:38 UTC
I personally am against this.
The specs are clear : don't use tab for indent.
If parsers accept tabs as indent char, it is (for me) a way to ease work for authors BUT it is the same reason that Internet Explorer eased the HTML authoring by parsing crappy things. (<p><div>test</p></div>)

The specs are clear : tabs must be avoided. And editors should respect specs, not ease the work and produce 'unvalid' YAML files that may be unreadable in the future (because parsers may respect specs)

To me, Netbeans (and every other editors) must indent with spaces in YAML files, whatever was the option about tabs.
Comment 21 Amnzero 2012-05-04 15:24:42 UTC
I can see your point, there is however a difference between supporting crap and supporting alternatives.

It has no extra value for a parser to leave out something that could be valid syntax, even though not according to specs. I'm not knowledgeable enough to be truly certain about tabs not breaking the yaml format in different systems, but I can see yaml specs changing in the future. I'm not sure what bright mind determines the yaml spec, so maybe he's wrong, then again maybe I am :)


Is there an option to set it to spaces by default, maybe even in the yaml-language preferences, so that you'd have to override it there to use spaces? then for most people it would be safe, and tabs would not be used unless explicitly set for yaml.


then again, if this 'enter'-bug is fixed, and my yaml files are consistent no matter what setting I have, and it's not mixing up the indention types, then I'm pretty much fine with it all.
Comment 22 enebo 2012-05-04 15:31:17 UTC
I have yet to see any intentional'in the wild' examples of YAML using tabs for
indentation. Which I think means that before YAML 1.2 it was not very common
(not sure if 1.2 was first version to outlaw the use of tabs for ident or not).

If you do search for 'yaml tabs' in google you will see YAML guides by various
sites telling people to not use tabs as indentation.  In a cursory look through
some forums the #1 offender of tabs as indent is not people but editors/IDEs
automatically using tab.  Hard to know how common this is since it really only
needs to be an issue a few times before it becomes an FAQ entry.  It is pretty
clear though tabs are not a desirable feature for indentation. 

My real plea against using tabs is the intent in 1.2 spec.  They decided this
was a practice they wanted to remove so we should encourage that with the YAML
editor by not allowing it.
Comment 23 Amnzero 2012-05-04 15:33:07 UTC
I'm your example in the wild. ;)

But I'm fine with spaces. 

obrejla@netbeans.org, what say you?
Comment 24 enebo 2012-05-04 15:41:39 UTC
Oh sorry...I did you see you say you used them.

I am just adding a little more info...tabs were not valid in 1.0 of YAML for indentation.  Is this a case of some parsers doing Character.isWhitespace() and just accepting tabs even though YAML does not accept them?  Maybe tabs have never been allowed from a spec perspeactive?
Comment 25 Guile 2012-05-04 16:04:53 UTC
I previously gave YAML 1.2 specs ...
Here is YAML 1.1 specs
http://yaml.org/spec/1.1/#indentation%20space/
"Note that indentation must not contain any tab characters."
http://yaml.org/spec/1.1/#id871856
"To maintain portability, tab characters must not be used in these cases, since different systems treat tabs differently. Note that most modern editors may be configured so that pressing the tab key results in the insertion of an appropriate number of spaces. "
YAML 1.0 specs
http://yaml.org/spec/1.0/#id2560933
"Tab characters are not allowed in indentation since different systems treat tabs differently. To maintain portability, YAML's tab policy is conservative; they shall not be used. Note that most modern editors may be configured so that pressing the tab key results in the insertion of an appropriate number of spaces. "


Always clear : TAB key insert spaces
Comment 26 Amnzero 2012-05-04 16:40:47 UTC
so the question is, do yaml specs outrank user preference?
Comment 27 scifi_fan 2012-05-04 19:35:29 UTC
Yes, Amnzero, specs outrank user preference. I am 100% with Guile: this component is a software product that has to interpret and even manipulate standardized data. Letting it accept and even produce non-standard data could make it end up in a convoluted set of unexpected and possibly even undocumented features and behaviors (like with said Internet Explorer). In this case, it would be obrejla who would have maintain these features.

Netbeans should support exactly the indentation method for YAML files that the YAML specification recommends/requires.
Comment 28 Amnzero 2012-05-04 20:57:14 UTC
I disagree, user preference outranks specs.

The internet explorer thing is not really comparable. 

But where will you draw the line between what the editor fixes for you, and what you may determine yourself?

Will you require the HTML editor to not be able to let you write a bug? or use an obsolete element?
Will you require the PHP editor to not be able to let you write a bug?
Will you no longer allow someone to write in PHP4 as it's EOL?
Will you no longer allow CSS hacks? or browser specific css hacks? 

I think there are numerous examples of where specs can be and are overruled by the user.

What will be auto fixed and what not? Where will you draw the line? And why not make the editor flexible, so I can decide for myself where I draw the line and what matters to me and what not?



So to come back on topic, I'd say make it an absolute default that yaml uses spaces for indenting, something that's not overruled by default editor settings, but that can be overruled at language specific settings. 

so basically:
language specific settings > default settings
and default setting for the YAML language would be indent with spaces.
Comment 29 scifi_fan 2012-05-05 11:43:52 UTC
I see what you mean. I think it will be the decision of the dev team whether they want to maintain a configurable non-standard mode or not. You should keep in mind, that accepting tabs as indentation actually also implies that the syntax checker is able to consider them "acceptable" or "incorrect" based on a configuration setting. But I think we can agree on the fact that the standard-mode is essential and must be the default.
Comment 30 Ondrej Brejla 2012-05-11 10:09:15 UTC
I'm just working on this prototype:

- every indentation (ENTER at the end of the line and pressing TAB somewhere in a line, when all forgoing characters are whitespaces) produces just SPACES
- pressing TAB anywhere else (when NOT indenting) in a file produces TABS if "Expand tabs" option is unchecked
- pressing TAB anywhere else (when NOT indenting) in a file produces SPACES if "Expand tabs" option is checked

I think that it's the only correct behavior corresponding with a Yaml spec. It's ok, isn't it?

Hope that it will work ;)
Comment 31 Guile 2012-05-11 11:42:34 UTC
+1
Comment 32 Ondrej Brejla 2012-05-11 11:56:04 UTC
And it's there...and it behaves as I described in my last comment.

Fixed in web-main #1129ca616c09
Comment 33 Quality Engineering 2012-05-12 09:55:56 UTC
Integrated into 'main-golden', will be available in build *201205120400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/1129ca616c09
User: Ondrej Brejla <obrejla@netbeans.org>
Log: #168495 - Tab key, insert 2 spaces in yaml