Hello,
I am working a lot with source code written using Emacs on Linux. The prevailing convention is that tabs are presented as 8 spaces, but indents are only 4 spaces. Indenting will insert spaces, and Emacs seems to swap groups of 8 spaces for a tab.
If I use a tab size of 8 in Textmate, the source files display correctly. Sadly, there is no way to tell Textmate to use an indent size of 4.
It would be very useful is it was possible to tell TextMate to: 1. Draw tabs as 8 spaces 2. Use spaces when indenting 3. Intend with 4 spaces, not the 8 spaces from a tab
Is there any way to do this with TextMate at the moment?
I'm using TextMate 1.5.3 (1215)
-- Kind regards, James Milne
James Milne wrote:
I am working a lot with source code written using Emacs on Linux. The prevailing convention is that tabs are presented as 8 spaces, but indents are only 4 spaces. Indenting will insert spaces, and Emacs seems to swap groups of 8 spaces for a tab.
If I use a tab size of 8 in Textmate, the source files display correctly. Sadly, there is no way to tell Textmate to use an indent size of 4.
It would be very useful is it was possible to tell TextMate to:
- Draw tabs as 8 spaces
- Use spaces when indenting
- Intend with 4 spaces, not the 8 spaces from a tab
Is there any way to do this with TextMate at the moment?
No there isn't. And this is a truly wacky convention from emacs? Is that really the default in emacs?? I suggest that instead you just make some simple commands for converting sane indentation <-> wacky emacs indentation, and then just run them when you open/save documents. Sorry, but there really is no better way to do this at the moment.
Incidentally, is there any possible explanation for this behavior in emacs? Why use tab characters at all if the intention is to have 4-space indents? Just to save a few bytes of disk space??
-Jacob
On 28 Oct 2006, at 07:45, Jacob Rus wrote:
James Milne wrote:
I am working a lot with source code written using Emacs on Linux. The prevailing convention is that tabs are presented as 8 spaces, but indents are only 4 spaces. Indenting will insert spaces, and Emacs seems to swap groups of 8 spaces for a tab. If I use a tab size of 8 in Textmate, the source files display correctly. Sadly, there is no way to tell Textmate to use an indent size of 4. It would be very useful is it was possible to tell TextMate to:
- Draw tabs as 8 spaces
- Use spaces when indenting
- Intend with 4 spaces, not the 8 spaces from a tab
Is there any way to do this with TextMate at the moment?
No there isn't. And this is a truly wacky convention from emacs? Is that really the default in emacs?? I suggest that instead you just make some simple commands for converting sane indentation <-> wacky emacs indentation, and then just run them when you open/save documents. Sorry, but there really is no better way to do this at the moment.
Incidentally, is there any possible explanation for this behavior in emacs? Why use tab characters at all if the intention is to have 4-space indents? Just to save a few bytes of disk space??
Yes, it is a fairly standard behaviour. It probably goes back into the mists of time when people cared about saving a few bytes when working over a 1200 baud modem.
I'm not trying to justify it. It's not the way I would set up my source editing environment, but there you go.
Xcode is capable of differentiating between tabs and indents. If you go into the Indentation panel in Xcode Preferences, it specifies the width for a tab and the width for an indent, and allows you to specify whether the Tab key inserts a tab character or a set of spaces.
This is actually very common, and it is frustrating when TextMate is so good at pretty much everything else, but can't handle this relatively simple situation.
-- Kind regards, James Milne
Jacob Rus <jrus@...> writes:
No there isn't. And this is a truly wacky convention from emacs?
It's not just emacs; this is very common in vi as well.
There are two major issues with changing the tab size from 8 columns:
1. There's no standard for carrying the tab size around with the file. Given any file, there's no way to tell if it uses 8 or 4 column tabs without manually inspecting it.
2. Changing tab sizes to change indent doesn't work because often tabs are used at the end of a line to line things up:
SOME_THING = 'un' # one OTHER_THING = 'deux' # two YET_ANOTHER_THING = 'trois' # three
(That probably won't line up if you're reading this in a proportional typeface, but you get the idea.)
In this situation, if you're not using the original coders tab size, you end up with the stuff at the right-hand not lining up.
The ability to have separate indent widths and tab columns is a standard feature of every programmer's editor I've ever seen, with the exception of TextMate. I don't understand why you guys don't just add the darn thing and be done with it.
cjs
Curt Sampson wrote:
Jacob Rus <jrus@...> writes:
No there isn't. And this is a truly wacky convention from emacs?
It's not just emacs; this is very common in vi as well.
Really? people use 4 spaces for the first tab stop, but a single tab for the second? I had never heard of that before...
There are two major issues with changing the tab size from 8 columns:
- There's no standard for carrying the tab size around with the file. Given any
file, there's no way to tell if it uses 8 or 4 column tabs without manually inspecting it.
- Changing tab sizes to change indent doesn't work because often tabs are
used at the end of a line to line things up:
SOME_THING = 'un' # one OTHER_THING = 'deux' # two YET_ANOTHER_THING = 'trois' # three
In this situation, if you're not using the original coders [sic] tab size, you end up with the stuff at the right-hand not lining up.
Ok, fine. Changing tab size could be bad, if someone still is using some random editor no one has ever heard of, which can't handle any tab size other than 8. So what's the benefit to coding like this instead of just using spaces? Is it just saving a few bytes?
-Jacob
Let me clarify...
Jacob Rus wrote:
Curt Sampson wrote:
It's not just emacs; this is very common in vi as well. [...]
- There's no standard for carrying the tab size around with the file.
Given any file, there's no way to tell if it uses 8 or 4 column tabs without manually inspecting it. [...]
This is an argument against using tabs at all
In this situation, if you're not using the original coders [sic] tab size, you end up with the stuff at the right-hand not lining up.
This is also an argument against using tabs
Ok, fine. Changing tab size could be bad, if someone still is using some random editor no one has ever heard of, which can't handle any tab size other than 8. So what's the benefit to coding like this instead of just using spaces? Is it just saving a few bytes?
To clarify my statement, so there are no ruffled feathers: Every editor worth its salt can interpret tabs to be any desired size. This includes bbedit, emacs, vim, and textmate. But emacs (and apparently vim) want to do this odd dance where you use 4-space tabs, but replace pairs of them with literal tab characters to save 7 bytes. This just seems absurd to me. Can you give any rational explanation why anyone would want to do this?
-Jacob
On Nov 8, 2006, at 10:41 PM, Jacob Rus wrote:
Let me clarify...
Jacob Rus wrote:
Curt Sampson wrote:
It's not just emacs; this is very common in vi as well. [...]
- There's no standard for carrying the tab size around with the
file. Given any file, there's no way to tell if it uses 8 or 4 column tabs without manually inspecting it. [...]
This is an argument against using tabs at all
In this situation, if you're not using the original coders [sic] tab size, you end up with the stuff at the right-hand not lining up.
This is also an argument against using tabs
Ok, fine. Changing tab size could be bad, if someone still is using some random editor no one has ever heard of, which can't handle any tab size other than 8. So what's the benefit to coding like this instead of just using spaces? Is it just saving a few bytes?
To clarify my statement, so there are no ruffled feathers: Every editor worth its salt can interpret tabs to be any desired size. This includes bbedit, emacs, vim, and textmate. But emacs (and apparently vim) want to do this odd dance where you use 4-space tabs, but replace pairs of them with literal tab characters to save 7 bytes. This just seems absurd to me. Can you give any rational explanation why anyone would want to do this?
Back in the old days, saving 7 bytes was even more significant than those two bytes you saved by not storing the year on dates (pre-Y2K).
God I feel old sometimes...
S
On 9. Nov 2006, at 04:47, Lists In@IDC wrote:
Back in the old days, saving 7 bytes was even more significant than those two bytes you saved by not storing the year on dates (pre-Y2K).
But actually, it doesn’t save bytes, if the alternative is to use tabs:
I just tried merging a lot of my sources and did a test:
Using tabs: 1.16 MB Using spaces: 1.32 MB Using the hybrid: 1.18 MB
So while the hybrid comes close to using only tabs, it still takes up more space on disk.
On 10/27/06, James Milne james.milne@mac.com wrote:
Hello,
I am working a lot with source code written using Emacs on Linux. The prevailing convention is that tabs are presented as 8 spaces, but indents are only 4 spaces. Indenting will insert spaces, and Emacs seems to swap groups of 8 spaces for a tab. Is there any way to do this with TextMate at the moment?
Not mentioned so far is that you're probably best off setting tabsize to 8, converting all tabs to spaces, and then switching back to 4-space soft-tabs.
I have seen that type of tab encoding before as well, but any emacs hacker worth her salt [1] uses "(setq indent-tabs-mode nil)".
/Nick
On 9 Nov 2006, at 14:37, Nick Sieger wrote:
On 10/27/06, James Milne james.milne@mac.com wrote: Hello,
I am working a lot with source code written using Emacs on Linux. The prevailing convention is that tabs are presented as 8 spaces, but indents are only 4 spaces. Indenting will insert spaces, and Emacs seems to swap groups of 8 spaces for a tab. Is there any way to do this with TextMate at the moment?
Not mentioned so far is that you're probably best off setting tabsize to 8, converting all tabs to spaces, and then switching back to 4-space soft-tabs.
I have seen that type of tab encoding before as well, but any emacs hacker worth her salt [1] uses "(setq indent-tabs-mode nil)".
Sadly I'm going to get short shrift informing my emacs hackers that they have to change their coding style just to suit my choice of editor :-)
Also, I don't want to change the whitespace in these files, as it means I'm touching every line in the source file. This makes my diff more complicated when I check back into CVS. When someone else has to resolve conflicts with their merges they would find I had changed every single line in the file, most of which is just replacing tabs with spaces. Again, not going to be very popular :-)
It's the only usability niggle I have with TextMate. I keep learning more funky keyboard shortcuts every day which make it a great environment otherwise!
-- Kind regards, James Milne
On 11/9/06, James Milne james.milne@mac.com wrote:
Sadly I'm going to get short shrift informing my emacs hackers that they have to change their coding style just to suit my choice of editor :-)
Also, I don't want to change the whitespace in these files, as it means I'm touching every line in the source file. This makes my diff more complicated when I check back into CVS. When someone else has to resolve conflicts with their merges they would find I had changed every single line in the file, most of which is just replacing tabs with spaces. Again, not going to be very popular :-)
Sorry, didn't realize you still have to interop with those emacs users. Perhaps you can clue them in to indent-tabs-mode ;-).
Cheers, /Nick
On Nov 9, 2006, at 10:06 AM, James Milne wrote:
On 9 Nov 2006, at 14:37, Nick Sieger wrote:
On 10/27/06, James Milne james.milne@mac.com wrote: Hello,
I am working a lot with source code written using Emacs on Linux. The prevailing convention is that tabs are presented as 8 spaces, but indents are only 4 spaces. Indenting will insert spaces, and Emacs seems to swap groups of 8 spaces for a tab. Is there any way to do this with TextMate at the moment?
Not mentioned so far is that you're probably best off setting tabsize to 8, converting all tabs to spaces, and then switching back to 4-space soft-tabs.
I have seen that type of tab encoding before as well, but any emacs hacker worth her salt [1] uses "(setq indent-tabs-mode nil)".
Sadly I'm going to get short shrift informing my emacs hackers that they have to change their coding style just to suit my choice of editor :-)
Also, I don't want to change the whitespace in these files, as it means I'm touching every line in the source file. This makes my diff more complicated when I check back into CVS. When someone else has to resolve conflicts with their merges they would find I had changed every single line in the file, most of which is just replacing tabs with spaces. Again, not going to be very popular :-)
It's the only usability niggle I have with TextMate. I keep learning more funky keyboard shortcuts every day which make it a great environment otherwise!
Is it hard to write a command that simply goes through all the files in the current project and toggles between the two tabbing styles? Unless I'm mistaken, Allan might have already written one such.
Then all you'll have to do is run this command before you commit your changes. You could perhaps even put this command in a .textmate_init file so that you don't have to remember running it each time, though I guess this might be a bit more complicated.
Sure it is a bit more work than if the editor supported it natively, but it's doable I think.
-- Kind regards, James Milne
Haris
On 9 Nov 2006, at 16:08, Charilaos Skiadas wrote:
Is it hard to write a command that simply goes through all the files in the current project and toggles between the two tabbing styles? Unless I'm mistaken, Allan might have already written one such.
Then all you'll have to do is run this command before you commit your changes. You could perhaps even put this command in a .textmate_init file so that you don't have to remember running it each time, though I guess this might be a bit more complicated.
Sure it is a bit more work than if the editor supported it natively, but it's doable I think.
If it was possible to get TextMate to perform the reverse of the "undo tabs" operation when you saved the file too, then that might be acceptable.
-- Kind regards, James Milne
I'll second this request. I'm maintaining legacy code that's 10 years old and it requires tabstops every 8 characters, but an indent width of 4 spaces. Doing the expand, unexpand trick won't work on this old code because the final unexpand introduces tabs into sections of code that didn't have them before.
Unfortunately, I have to stick with Vim when editing this code. Vim's great, but I prefer TextMate's intuitive interface and elegant appearance and integration with OS X. Great job by the way. If TextMate can help me overcome this tab problem I'll gladly purchase a license.
Cheers, Ryan
Ryan Hodges wrote:
I'll second this request. I'm maintaining legacy code that's 10 years old and it requires tabstops every 8 characters, but an indent width of 4 spaces. Doing the expand, unexpand trick won't work on this old code because the final unexpand introduces tabs into sections of code that didn't have them before.
Unfortunately, I have to stick with Vim when editing this code. Vim's great, but I prefer TextMate's intuitive interface and elegant appearance and integration with OS X. Great job by the way. If TextMate can help me overcome this tab problem I'll gladly purchase a license.
Cheers, Ryan
Sadly it's not just legacy code. The tab behaviour you describe is the one defined as part of the Java Coding Standards; and in the company where I work, deciding to adhere strictly to that was the only way we were able to resolve the code-formatting arguments! :-}
I hates it, personally; one-tabchar-per-indent-level makes obvious sense, but there you go. XCode can do it. (Set Tab width to 8, indent width to 4, tab key inserts tab, and it all happens automatically.) But it's only a global preference, not even per-project. Apart from that the behaviour's perfect for this style of tabbing. And besides, I like TextMate now (and already bought a license!)