943,694 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Mar 28th, 2008
0

Tab width within Code tags

Expand Post »
What is the tab width (number of spaces indented for a tab) within code tags? Is it 8? Is it possible to change it to 4? Since the code is wrapped for lines with length less than 80 characters, I think that it is a waste of space.
Similar Threads
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Mar 28th, 2008
0

Re: Tab width within Code tags

This	contains a tab
This    contains 4 spaces
But this        contains 8 spaces
Just testing. I used Notepad to create the above text

My suggestion is to change the option in your text editor to convert tabs to spaces because some people might use 8 spaces while others 4 or some other number. I've even seen just 2 spaces.
Last edited by Ancient Dragon; Mar 28th, 2008 at 11:31 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005
Mar 28th, 2008
0

Re: Tab width within Code tags

Perhaps have an option to set the tab stop explicitly in the code tags:
[code=c, tab=2]
#include <stdio.h>

int main ( void )
{
puts ( "Hello, world!" );
return 0;
}
[/code]
Last edited by Narue; Mar 28th, 2008 at 11:34 am.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 28th, 2008
0

Re: Tab width within Code tags

CSS 2 doesn't appear to have a tab-width property. The following are the properties that can be applied to text elements: http://www.w3schools.com/css/css_reference.asp#text
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Mar 29th, 2008
0

Re: Tab width within Code tags

I know that if I use the option to replace tabs with 4 spaces (which I already do in Visual Studio), this problem would be over for my code. But we do not have control of the other user's editors. When they post codes with the tab character used for indenting, even code with a level 4 nesting can wrap unnecessarily. Sometimes I copy and paste the code to my own editor and replace tabs with 4 spaces to make the code readable, and was wondering if there was a quick fix. But if as Dani says that nothing can be done about it, well I guess we should grin and bear.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Mar 29th, 2008
0

Re: Tab width within Code tags

I believe it is a platform-specific setting ... i.e. Your OS/browser determines how many spaces per tab.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Mar 30th, 2008
0

Re: Tab width within Code tags

Gah, I hate when this happens! I was googling to see if there is a solution or workaround to this problem, only to find something that was specifically what I was looking for. I click on it and it ended up being this very thread.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Mar 30th, 2008
1

Re: Tab width within Code tags

I'm not going to try to pretend that I'm any sort of web programming expert, but couldn't you modify your parser to change tab characters into spaces? That way you could specify a manual tab width within the code tags, like Narue suggested.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Mar 30th, 2008
0

Re: Tab width within Code tags

That's a very brute force method that would undermine the purpose of tabs, screwing up more things than it fixes. For example, if tabs were to be converted into two spaces, the following:

php Syntax (Toggle Plain Text)
  1. echo "Hello World!"; // This is line one
  2. echo "DaniWeb"; // This is line two
  3. echo "Blah blah blah blah!"; // This is line three
Would be translated, without the poster's intent, into:
php Syntax (Toggle Plain Text)
  1. echo "Hello World!"; // This is line one
  2. echo "DaniWeb"; // This is line two
  3. echo "Blah blah blah blah!"; // This is line three
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Mar 30th, 2008
1

Re: Tab width within Code tags

C'mon Dani, you can't fool me; I know you can do it. How hard would it be to make your parser calculate the number of spaces to insert to make it line up to the next tab stop?
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in DaniWeb Community Feedback Forum Timeline: JavaScript Fix
Next Thread in DaniWeb Community Feedback Forum Timeline: Posting C code is a frustration experience





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC