SublimeText / ElasticTabstops

Tab characters automatically adjust to keep adjacent lines aligned.
https://github.com/SublimeText/ElasticTabstops
67 stars 6 forks source link

Can't get it working #1

Closed Naatan closed 12 years ago

Naatan commented 12 years ago

Sublime Text 2, Build: 2165 on Ubuntu 11.10 64bit.

At first it seemed to do something, as in it changed alignment of several lines of code, but the alignment seemed random and did not match one another at all. After a while I got an error saying the ElasticTabstops script was running for too long (ie. hanging).

I tried installing an older version, but this one doesn't seem to do anything at all.

Hopefully this is'll be fixed soon, as this package seems invaluable once you get used to it :)

adzenith commented 12 years ago

Just to make sure: are you indenting with tabs? Can you turn on invisibles and confirm whether or not the tabs are being aligned? I use this plugin just about every day that I code and it seems to work ok for me :)

Naatan commented 12 years ago

Yes I use tabs for indentation.

Here's an example:

    DB::factory(array(
        'driver'            => 'pdo',
        'connection_string' => PHP_OS == 'Darwin' ? 'mysql:dbname=test;host=127.0.0.1;port=8889' : 'mysql:dbname=test;host=127.0.0.1',
        'username'          => 'root',
        'password'          => PHP_OS == 'Darwin' ? 'root' : '',
    ));

As soon as I press tab on the second line after 'connection_string' the result becomes:

    DB::factory(array(
        'driver'                    => 'pdo',
        'connection_string'  => PHP_OS == 'Darwin' ? 'mysql:dbname=test;host=127.0.0.1;port=8889' : 'mysql:dbname=test;host=127.0.0.1',
        'username'                  => 'root',
        'password'                  => PHP_OS == 'Darwin' ? 'root' : '',
    ));

Not sure what I would be doing wrong.

Also, oddly enough it only works if I indent on the connection_string or username lines, choosing either of the outer lines only indents those lines.

adzenith commented 12 years ago

The text that you pasted in unfortunately had all of its tabs converted to spaces, so it's hard for me to tell what's going on. Is there one non-indentation tab per line, immediately before each '=>'?

Naatan commented 12 years ago

Pretty hard to find a pastebin online that properly preserves whitespace, so I uploaded a screenshot and a txt with the whitespace in tact:

https://dl-web.dropbox.com/get/Support%20Links/bugged_whitespace.png?w=98331276 https://dl-web.dropbox.com/get/Support%20Links/bugged_whitespace.txt?w=b1780f45

adzenith commented 12 years ago

I think those links are not public links, unfortunately. Here's what it should look like, where S is a space and T is a tab:

TDB::factory(array(
TT'driver'SSSSSSSSSSST=> 'pdo',
TT'connection_string'T=> PHP_OS == 'Darwin' ? 'mysql:dbname=test;host=127.0.0.1;port=8889' : 'mysql:dbname=test;host=127.0.0.1',
TT'username'SSSSSSSSST=> 'root',
TT'password'SSSSSSSSST=> PHP_OS == 'Darwin' ? 'root' : '',
T));
Naatan commented 12 years ago

Sorry I'm not that used to dropbox, these should work:

http://dl.dropbox.com/u/41125814/bugged_whitespace.png http://dl.dropbox.com/u/41125814/bugged_whitespace.txt

Naatan commented 12 years ago

By the way, when I open the txt in Firefox the indentation in the original version does not seem aligned either, whilst in Sublime text it does. I'm pretty sure this is due to a combination of font selection and font size, but I'd expect a plugin such as yours to account for that by mixing spaces and tabs.

Also, part of the bug is that it doesn't do anything when indenting the first or last line.

adzenith commented 12 years ago

It looks like the plugin is doing the right thing. Did you see the example code that I pasted in my last comment? The reason the equals are not being aligned in the second block is because the connection_string line has fewer tabs than the other three lines. In the top block, just edit any line and things will sort themselves out -- the plugin works lazily on text you're editing, though I believe there's a command to reprocess the whole file if you're opening an existing file and want everything aligned. The plugin makes it so that each tabstop is aligned with all other tabstops in the block. Therefore you don't need three tab characters before the = sign; just one should do it. The plugin does in fact use a combination of spaces and tabs for alignment, so it should look good everywhere. I'm not sure what you're saying about the first and last line though. Let me know if that still doesn't make sense. Thanks!

Naatan commented 12 years ago

I get what you're saying, it just seems irrelevant to me. Of course I can produce a use case where your plugin does the indentation properly. I get that from your perspective it's my code that's the problem, not the plugin. All I'm saying is that the plugin ought to be intelligent enough to work around use-cases such as these. Maybe by replacing tabs with spaces where necessary.. ?

Anyway, I see now that as far as the scope of this plugin is concerned this is more of a feature request than it is a bug report, nevertheless it's still something I'd really like to see added, I hope you will consider it :)

adzenith commented 12 years ago

I guess I'm just not sure what your desired behaviour is in this situation. Do you think the plugin should be detecting the equals signs or some such?

adzenith commented 12 years ago

Hey, just following up on this issue: I'm still not quite certain what your desired behaviour is—would you be able to elaborate? Thanks a lot!

Naatan commented 12 years ago

Sorry for the late reply. Basically I'd like it to be smart enough to workaround use-cases such as the ones I described, rather than it needing me to have my code already done in a certain way for it's convenience. Basically I would need to always ensure I'm indenting with a mix of spaces and tabs for this addon to be useful. Why not have it convert targeted lines to spaces and tabs prior to executing the auto alignment?

adzenith commented 12 years ago

Could you describe what exactly you would like it to have done with your code? Are you saying you want it to look for equals signs or something? Or groups of spaces?

Naatan commented 12 years ago

Well from what you were saying it seems to me that the reason my code wasn't indenting equally (from 'my' perspective, not from your codes perspective) was because I had multiple tabs on each line. I would guess that an "easy" way to fix this is to have your code convert those multiple tabs to spaces and only keep the last tab in there, then execute the rest of the flow as normal.

But in a nutshell, the code I showed you before should indent equally, if doesn't then there is no added value in using this addon, regardless of whether or not you meant it to do that.

adzenith commented 12 years ago

Oh, maybe I was just unclear? What the plugin does is align the tab characters on subsequent lines. So you can have as many tabs as you like, and each one will line up with the tabs above and below it. The plugin right now doesn't do any spaces-to-tabs or tabs-to-spaces conversions.

Naatan commented 12 years ago

No I get that :) I'm just suggesting that it should, as without it the plugin is not of much use, unless you are already mixing spaces and tabs some other way.

adzenith commented 12 years ago

I guess this is why I'm confused—I use this plugin every day and I find it incredibly useful. If it converted your tabs to spaces then it could no longer align the tabs because they wouldn't exist anymore, right? I just feel like there's something I'm not understanding. :)

Naatan commented 12 years ago

Let's just boil it down to the core problem here; your plugin REQUIRES the developer that uses it to indent their code in a certain specific way in order for your plugin to be able to work. What I'm suggesting is that your code instead works with the developer and converts whatever needs to be converted so that your plugin can work as intended.

As it stands you are expecting developers to compromise the way they code in order to utilize your plugin. Seeing as your plugin could easily automate the process needed to eliminate the need for compromise on the developers end, why not just go ahead and do that?

I get that you're simply sharing a tool that you found useful for yourself, and I appreciate you've done so. If I was any good at Python myself I'd gladly provide a patch for the improvement I'm suggesting. As it stands I'm not much good at Python though, so I'm simply suggesting a feature you might want to add that I (as well as others I'm sure) will greatly appreciate.

Also worth noting that when I started this issue I thought it was a bug, while we have now found out that it's actually by design. As such this is really a feature request and not a bug report.

adzenith commented 12 years ago

I guess I'm just trying to figure out what this conversion would be. How does the plugin know what you want aligned with what?

Naatan commented 12 years ago

I don't think there's a simple answer to that question, obviously the plugin would need to have quite some intelligence, which the original elastic tabstops concept does have.

I've found this python library for elastic tabstops, but from looking at the code it seems you'd still need to detect what block of text needs to be indented, and it pretty much auto indents anything within the selection you pass to it.

I might look into it myself once I have some more time on my hands, ideally I'd like to see the exact same functionality as demo'ed on Nick Gravgaard's website.

adzenith commented 12 years ago

Wait, what? My plugin does the same thing as the original concept, and has the same amount of intelligence. The only difference is that Sublime Text doesn't support variable-width tabstops, so I have to use spaces to make the tabs seem wider. How is that one more intelligent? You still have to place the tab characters yourself etc. The exact same functionality as on his website is impossible in ST2 right now, but I believe this is as close as can be gotten.

Naatan commented 12 years ago

So sorry, it seems my mind has played tricks on me as in my memory it would indent when pressing tab as well, which is the feature I have been talking about. I just tried the demo again and found it doesn't do that at all.

I sincerely apologize for the confusion this has caused.