Hi,
I found a bug while going through Why's (Poignant) Guide to Ruby.
Whenever you type the following string of characters in Ruby mode:
"#<#{}#{
if you follow up with a '}' (just the right bracket), you end up with
}"}#}<}#}{}}#}{
If you do it in a piece of text, it garbles up your entire file, adding a right bracket after every single character, making your file look like this:
}#} }T}h}e} }g}u}t}s} }o}f} }l}i}f}e} }f}o}r}c}e} }w}i}t}h}i}n} }D}w} e}m}t}h}y}'}s} }A}r}r}a}y} }c}l}a}s}s} }C}r}e}a}t}u}r}e} } } } } } }#} }G}e}t} }a} }m}e}t}a}c}l}a}s}s} }f}o}r} }t}h}i}s} }c}l}a}s}s} } } }d}e}f} }s}e}l}f}.}m}e}t}a}c}l}a}s}s};} }c}l}a}s}s} }<}<} }s}e}l} f};} }s}e}l}f};} }e}n}d};} }e}n}d}
This bug appears both in r847 and the latest r906.
Regards,
Frederik
This is a problem with the Ruby Macro that triggers on }. It's intended to skip past any } at the current position, the purpose being because of the snippet that inserts #{} when you type # in a string. This way you can type } to go past the end, just like if you were using smart typing. Unfortunately I can't figure out a good way to fix the macro to not screw up so badly when triggered the way you are doing it.
My suggest would be to remove both the } macro and the # snippet (the # snippet constantly annoys me because I type #{ and end up with # {{}} ), but at least one other person wants to keep the # snippet, so I'm not sure what the proper response is.
On Jan 8, 2006, at 1:09 PM, Frederik De Bleser wrote:
I found a bug while going through Why's (Poignant) Guide to Ruby.
Whenever you type the following string of characters in Ruby mode:
"#<#{}#{
if you follow up with a '}' (just the right bracket), you end up with
}"}#}<}#}{}}#}{
If you do it in a piece of text, it garbles up your entire file, adding a right bracket after every single character, making your file look like this:
}#} }T}h}e} }g}u}t}s} }o}f} }l}i}f}e} }f}o}r}c}e} }w}i}t}h}i}n} }D} w}e}m}t}h}y}'}s} }A}r}r}a}y} }c}l}a}s}s} }C}r}e}a}t}u}r}e} } } } } } }#} }G}e}t} }a} }m}e}t}a}c}l}a}s}s} }f}o}r} }t}h}i}s} }c}l}a}s}s} } } }d}e}f} }s}e}l}f}.}m}e}t}a}c}l}a}s}s};} }c}l}a}s}s} }<}<} }s}e} l}f};} }s}e}l}f};} }e}n}d};} }e}n}d}
This bug appears both in r847 and the latest r906.
On Jan 8, 2006, at 5:46 PM, Kevin Ballard wrote:
My suggest would be to remove both the } macro and the # snippet (the # snippet constantly annoys me because I type #{ and end up with #{{}} ), but at least one other person wants to keep the # snippet, so I'm not sure what the proper response is.
I second the removal suggestion. I always end up with #{{}} myself, and I don't find it really saves that much time anyway. Plus, what if someone just wants a # in their string?
Haris
On 09/01/2006, at 0:58, Charilaos Skiadas wrote:
On Jan 8, 2006, at 5:46 PM, Kevin Ballard wrote:
My suggest would be to remove both the } macro and the # snippet (the # snippet constantly annoys me because I type #{ and end up with #{{}} ), but at least one other person wants to keep the # snippet, so I'm not sure what the proper response is.
I second the removal suggestion. I always end up with #{{}} myself, and I don't find it really saves that much time anyway. Plus, what if someone just wants a # in their string?
I am very much for keeping it. If you want # in your string (can't be THAT often), delete the {}. For me it's a big time-saver, probably also because { is annoying to type on a danish keymap.
As for the } macro, yeah it seems to mess up if you type } as the last character in the buffer... infinite loop for me :p. I am sure it can be fixed, though I'm heading off for bed now.
-- Sune.
On Jan 8, 2006, at 5:08 PM, Sune Foldager wrote:
I am very much for keeping it. If you want # in your string (can't be THAT often), delete the {}. For me it's a big time-saver, probably also because { is annoying to type on a danish keymap.
The question is, which group of people (people annoyed by it or people who have { as hard to access on their keymap) is larger?
As for the } macro, yeah it seems to mess up if you type } as the last character in the buffer... infinite loop for me :p. I am sure it can be fixed, though I'm heading off for bed now.
I don't understand why it gives you an infinite loop. There's no recursion in that macro. But yeah, the macro definitely has problems.
On 09/01/2006, at 2:17, Kevin Ballard wrote:
On Jan 8, 2006, at 5:08 PM, Sune Foldager wrote:
I am very much for keeping it. If you want # in your string (can't be THAT often), delete the {}. For me it's a big time-saver, probably also because { is annoying to type on a danish keymap.
The question is, which group of people (people annoyed by it or people who have { as hard to access on their keymap) is larger?
Well maybe, but in the meantime you two can change your local settings, why not? :-p. I've been forced to do so on other occations with LaTeX which default setup I very much dislike.
-- Sune. - heads to bed.
On 09/01/2006, at 2:58, Sune Foldager wrote:
Well maybe, but in the meantime you two can change your local settings, why not? :-p. I've been forced to do so on other occations with LaTeX which default setup I very much dislike.
Also, TextMate is about typing less, isn't it? I bet over 95% of the time, when you put # in a double-quoted string in Ruby, you mean to do an interpolation, in which case you always need a { } pair. And having it a snippet even means you can press your choice of tab or } to get out... ok, maybe that's the weaker of my points, but again on my keymap.. :-).
Once I got used to it (and well, I did create this # macro), I luuv having it.
-- Sune.
On Jan 8, 2006, at 5:58 PM, Sune Foldager wrote:
Well maybe, but in the meantime you two can change your local settings, why not? :-p. I've been forced to do so on other occations with LaTeX which default setup I very much dislike.
The problem with doing that is I always have to make sure I don't accidentally commit it when I do other changes.
On Jan 8, 2006, at 6:01 PM, Sune Foldager wrote:
Also, TextMate is about typing less, isn't it? I bet over 95% of the time, when you put # in a double-quoted string in Ruby, you mean to do an interpolation, in which case you always need a { } pair. And having it a snippet even means you can press your choice of tab or } to get out... ok, maybe that's the weaker of my points, but again on my keymap.. :-).
Once I got used to it (and well, I did create this # macro), I luuv having it.
You're probably right about the frequency of #{} vs just #, but I still can't get used to it. I always end up with #{{}} whenever I try to put in #{} and it really interrupts my flow as I have to stop what I'm doing and fix it
Here's a suggestion that will at least fix the } bug - remove the # snippet and } macro, and create a new macro that simply inserts # { and give it the same scope as the old # snippet. Now if you have smart typing turned on it will insert #{} with the cursor between it, and typing } will skip past the close, exactly as if you'd typed # { with no macro at all. Of course, with smart typing off it will simply insert #{ which is kind of odd.
Of course, I'm still for removing it entirely.
On 09/01/2006, at 4:27, Kevin Ballard wrote:
Here's a suggestion that will at least fix the } bug - remove the # snippet and } macro, and create a new macro that simply inserts # { and give it the same scope as the old # snippet. Now if you have smart typing turned on it will insert #{} with the cursor between it, and typing } will skip past the close, exactly as if you'd typed #{ with no macro at all.
Yeah that's fine by me, although it would be best if we could fix the bug :-p. But.. I never even knew there was such a macro in the first place.
-- Sune.
On Jan 9, 2006, at 5:02 AM, Sune Foldager wrote:
Yeah that's fine by me, although it would be best if we could fix the bug :-p. But.. I never even knew there was such a macro in the first place.
-- Sune.
Is the bug really a big issue? It only gets triggered when } would be the last character in the file, but since it is only triggered inside strings, } will almost always be followed by, at the very least, an ". So though it is theoretically troublesome, I am not sure it affects things practically.
Haris
On 09/01/2006, at 14:48, Charilaos Skiadas wrote:
Is the bug really a big issue? It only gets triggered when } would be the last character in the file, but since it is only triggered inside strings, } will almost always be followed by, at the very least, an ". So though it is theoretically troublesome, I am not sure it affects things practically.
I must confess that I never encountered it before either. It would seem _almost_ a pathological case to trigger it.
-- Sune.
On 09 Jan 2006, at 14:53, Sune Foldager wrote:
On 09/01/2006, at 14:48, Charilaos Skiadas wrote:
Is the bug really a big issue? It only gets triggered when } would be the last character in the file, but since it is only triggered inside strings, } will almost always be followed by, at the very least, an ". So though it is theoretically troublesome, I am not sure it affects things practically.
I must confess that I never encountered it before either. It would seem _almost_ a pathological case to trigger it.
Actually, I encountered the bug with a real example in the Poignant guide. Here it is, from (http://www.poignantguide.net/ruby/ chapter-6.html):
class DwemthysArray < Array alias _inspect inspect def inspect; "#<#{ self.class }#{ _inspect }>"; end
The last line triggers the bug, which messes up all the code in the file I already wrote. The results looks downright scary when the bug shows up, so I personally think this must be fixed.
And I personally like the fact that TextMate automatically writes {} when I type # in strings.
Frederik
On Jan 9, 2006, at 8:26 AM, Frederik De Bleser wrote:
Actually, I encountered the bug with a real example in the Poignant guide. Here it is, from (http://www.poignantguide.net/ruby/ chapter-6.html):
class DwemthysArray < Array alias _inspect inspect def inspect; "#<#{ self.class }#{ _inspect }>"; end
The last line triggers the bug, which messes up all the code in the file I already wrote. The results looks downright scary when the bug shows up, so I personally think this must be fixed.
You'll have to explain how you typed the aforementioned code, because when I type it in, the bug is not triggered.
And I personally like the fact that TextMate automatically writes {} when I type # in strings.
So it didn't bother you in the above example where to write the #< part you had to delete the { as well as the consequent } that sticks around?
Frederik
Haris
On 09/01/2006, at 15:34, Charilaos Skiadas wrote:
You'll have to explain how you typed the aforementioned code, because when I type it in, the bug is not triggered.
I agree, since there is always something ahead of the cursor due to smart typing. Unless.. do you have it turned off? I can't get it to trigger either.
And I personally like the fact that TextMate automatically writes {} when I type # in strings.
So it didn't bother you in the above example where to write the #< part you had to delete the { as well as the consequent } that sticks around?
Again, please compare the few cases where you need # without { to the MANY where you need them together.
-- Sune.
Sune Foldager wrote:
So it didn't bother you in the above example where to write the #< part you had to delete the { as well as the consequent } that sticks around?
Again, please compare the few cases where you need # without { to the MANY where you need them together.
I'm no expert on ruby, but perhaps this calls for a macro instead of a snippet? If it is a macro, then the extra } would automatically be deleted. However, then you would lose the ability to use it on selections..
Jeroen.
On Jan 9, 2006, at 8:52 AM, Sune Foldager wrote:
On 09/01/2006, at 15:34, Charilaos Skiadas wrote:
Again, please compare the few cases where you need # without { to the MANY where you need them together.
I do agree that this is the main use of #, that's why I'm only 70% behind the idea of changing the behavior. But I would at least expect that pressing backspace after you've pressed # would remove both braces, not just the left one. It would be great if we can arrange for that. As it stands, it does not behave consistently with smart- typing.
On a slightly related subject, I do find it a bit irritating that it is much easier to add smart pairs around some text than it is to remove them. It would be nice if there was a command that looks at the characters at either side of the cursor/selection, and if they match then it removes them. This could help in this case also. I am not used to forward deleting, so the extra } is a real pain for me.
-- Sune.
Haris
On 9/1/2006, at 16:00, Charilaos Skiadas wrote:
On Jan 9, 2006, at 8:52 AM, Sune Foldager wrote:
On 09/01/2006, at 15:34, Charilaos Skiadas wrote: Again, please compare the few cases where you need # without { to the MANY where you need them together.
I do agree that this is the main use of #, that's why I'm only 70% behind the idea of changing the behavior. But I would at least expect that pressing backspace after you've pressed # would remove both braces, not just the left one. It would be great if we can arrange for that. As it stands, it does not behave consistently with smart-typing.
The #{…} snippet is (for me) also very useful for wrapping text in strings. Otherwise the macro approach sounds good.
As for the } macro, I think we can remove that w/o any real loss -- ideally snippets should be able to (implicitly) markup text as being smart-typing pairs.
I'm curious to why the OP has smart typing disabled as I am very close to remove the ability to disable smart typing.
On a slightly related subject, I do find it a bit irritating that it is much easier to add smart pairs around some text than it is to remove them. It would be nice if there was a command that looks at the characters at either side of the cursor/selection, and if they match then it removes them. This could help in this case also. I am not used to forward deleting, so the extra } is a real pain for me.
Some sort of strip command sounds like a good idea. I.e. it'd strip any paired characters that surrounds the current word. Should be doable as a command, if only we can find a good key for that :)
The last line triggers the bug, which messes up all the code in the file I already wrote. The results looks downright scary when the bug shows up, so I personally think this must be fixed.
You'll have to explain how you typed the aforementioned code, because when I type it in, the bug is not triggered.
Actually, the example can be much, much easier. Just open a new document and type the following:
"#{hello}#{there}"
The moment the two pound sign groups are right next to each other, it triggers the bug, as long as those are the final characters in the document.
And I personally like the fact that TextMate automatically writes {} when I type # in strings.
So it didn't bother you in the above example where to write the #< part you had to delete the { as well as the consequent } that sticks around?
That's more the exception than the rule, so I deleted it there. Most of the time, the auto-completion does the right thing.
Frederik
On Jan 9, 2006, at 9:00 AM, Frederik De Bleser wrote:
"#{hello}#{there}"
The moment the two pound sign groups are right next to each other, it triggers the bug, as long as those are the final characters in the document.
still can't reproduce it here. Maybe you have some setting somewhere? What have you set as "word characters" in the preferences?
Haris
On 09 Jan 2006, at 16:09, Charilaos Skiadas wrote:
On Jan 9, 2006, at 9:00 AM, Frederik De Bleser wrote:
"#{hello}#{there}"
The moment the two pound sign groups are right next to each other, it triggers the bug, as long as those are the final characters in the document.
still can't reproduce it here. Maybe you have some setting somewhere? What have you set as "word characters" in the preferences?
Oh, I'm sorry, forgot to mention that Smart Typing and Re-Indent is off in Text Editing. Word characters is "_". When I turn Smart Typing off, the error disappears.
Frederik
On 09/01/06, Sune Foldager cryo@cyanite.org wrote:
I am very much for keeping it. If you want # in your string (can't be THAT often), delete the {}. For me it's a big time-saver, probably also because { is annoying to type on a danish keymap.
I'm with Sune. I think it's a time saver overall.
Regards,
Matt
-- Matt Mower :: http://matt.blogs.it/