Sublime Forum

Indent Guides

#33

gist.github.com/1127063

I hacked it a bit (emphasis on hack). Just got it to working well enough for myself.

Made a bunch of style changes inline with PEP 8.
Added an option to enable the active guide highlighting.
Stopped guides from being drawn in selections.
Edited the regex to not draw the guide if itā€™s up against anything but the end of a line when flush_with_text is on.

Also I think I fixed the bug but no idea why it fixes it. I tracked it down to module reloading and grabbing multiple selections with ctrl+d. Sometimes when the module would get reloaded it wouldnā€™t call refresh() until their was an actual file modification. Second, for some reason when grabbing multiple selections with ctrl+d the guides would disappear. I fixed it by forcing a refresh() if self.guides was empty after being loaded. Seems it gets emptied erroneously. No idea why though.

0 Likes

#34

I made a real repo for this plugin at github.com/SublimeText/IndentGuides. Iā€™m going to work on incorporating all your changes hopefully sometime this weekend.
Thanks!

0 Likes

#35

Eugh, I hate it when plugins stop working because someone added a new setting. Such a pain. Personally, I think it is really weird and annoying that most plugins in sublime default to being off. Why would I install a plugin if I didnā€™t want to use it. Plugins should default to being on.

You need parentheses on line 166. You could have a situation like not True and False which is interpreted as (not True) and False but you want not (True and False) so that it gets in the if.

Also, I donā€™t like that when I select text, all indent guides go away. I actually used that a good bit in my 76 space indent to select the correct text.

0 Likes

#36

It was 2 in the morning and I was just hacking a bit with what was there.

That refresh only needs to be run when self.guides is empty and self.loaded is True. It was a quick hack to get it working around that odd bug I explained earlier.

Iā€™ll play around with it a bit more and add it as an option and try and cleanup my mess a bit :s

0 Likes

#37

Heh, yea, itā€™s cool.

The thing Iā€™ve noticed is that it can be a little slow. Itā€™s because of the way regions are done in sublime. What we end up doing is redrawing ALL of the guides every time I type or move the cursor in any way. That is causing lag. I think we need to either a: remove that option or b: move that code to run in a timer so it doesnā€™t lag while i am typing. In a 5,000 line file, it might add like 20k regions to it. We are iterating through each of them every time and replace all the regions every time the selection changes.

0 Likes

#38

If we could capture when the view changes, we could do it only in the current viewable area. Or if we could capture what changes in the buffer, we could only update lines that change.
Because neither of these things is possible at the moment, I just only edit small files. :stuck_out_tongue:
Seriously though, a timerā€™s probably a good idea. I might look into doing that over the weekend.

0 Likes

#39

Thereā€™s a half decent implementation of a timer here (it executes a callback .1 seconds after the most recent call to on_sel_modified) github.com/ajpalkovic/SublimePl ā€¦ edFiles.py

0 Likes

#40

Thanks for the update.

There is any way of setting the highlight color other than editing the theme file? Like a setting or something?

0 Likes

#41

Not really, you basically have to edit the theme.

0 Likes

#42

I updated mine with a couple changes. I merged Anomarehā€™s changes, crudely disabled hiding indent guides in selections and changed it to use dicts instead of lists for cursor positions.

More importantly, for showing the active guide, it now uses the end of whitespace for the line instead of the cursor position. The idea is that if I type , as I am typing, I still want the active indent guide to show up at the beginning of the line, not at the end of , doesnā€™t really make sense there.

0 Likes

#43

Alright, I got around to rewriting it.

gist.github.com/1136448

Itā€™s bug free as far as I can tell. I donā€™t think itā€™s possible to make it really friendly with large files past a timer which I personally find kind of meh. For it to get any better it probably just has to be implemented internally.

Quick run down of the options:

[code]ā€˜indent_guides_enabledā€™: true
Enables indent guides.

ā€˜indent_guides_max_file_charactersā€™: 524288
The max file size a file is allowed to be and have indent guides.

ā€˜indent_guides_scopeā€™: ā€˜commentā€™
The scope name assigned to guides.

ā€˜indent_guides_active_scopeā€™: ā€˜indent_guides_scopeā€™
The scope name assigned to active guides.

[NOTE] To enable active guides you have to set this option. Active guides
       default to the same scope as inactive guides.

ā€˜indent_guides_hide_in_selectionā€™: true
Indent guides will be hidden within selections.

ā€˜indent_guides_hide_on_lineā€™: true
Indent guides will not be drawn on the current line.

[NOTE] This only applies to empty selections.

ā€˜indent_guides_active_wrap_to_textā€™: true
If true, the active guide will always be the deepest guide on the cursorā€™s line.
If false, the active guide will be the guide closest to the left of the cursor.[/code]

0 Likes

#44

@Anomareh, working great for me! Thanks a lot!

0 Likes

#45

@pod Great :]

Also, I just updated it (same link as before gist.github.com/1136448). Fixed a bug when interacting with the console and also added a check to disable the built-in guides if theyā€™re enabled alongside the plugin.

0 Likes

#46

[quote=ā€œAnomarehā€]@pod Great :]

Also, I just updated it (same link as before gist.github.com/1136448). Fixed a bug when interacting with the console and also added a check to disable the built-in guides if theyā€™re enabled alongside the plugin.[/quote]

So, is this plugin already part of dev build 2104?

"Build 2104
Release Date: 24 August 2011
Added indentation guides. These may be disabled with the draw_indent_guides setting.
ā€¦
"

0 Likes

#47

Is this plugin already part of sublime in dev build 2104?

Because it tells this:

Build 2104
Release Date: 24 August 2011
Added indentation guides. These may be disabled with the draw_indent_guides setting.

0 Likes

#48

Partly yes. The active indent guides are not in 2104. If they arenā€™t made into a native feature Iā€™ll just pull them out into a separate plugin.

0 Likes

#49

What ajpalkovic said.

The gist also has a few extra options the built-in guides donā€™t have (active guides aside). Namely the ability to toggle whether they are shown in selections or on the current line. Also the built-in guides will not show the last guide on a line that contains nothing but whitespace, the gist will. For example, if a line consists of nothing but 4 tabs, the built-in guides will only draw 3 guides ignoring the last one where as the gist will draw 4.

0 Likes

#50

[quote=ā€œAnomarehā€]
The gist also has a few extra options the built-in guides donā€™t have (active guides aside). Namely the ability to toggle whether they are shown in selections or on the current line. Also the built-in guides will not show the last guide on a line that contains nothing but whitespace, the gist will. For example, if a line consists of nothing but 4 tabs, the built-in guides will only draw 3 guides ignoring the last one where as the gist will draw 4.[/quote]

I find this functionality to be worth using the plugin over the default guides, thanks :smile:

0 Likes

#51

No problem, glad someone else can make use of it :]

I also forgot to mention there is also the ability to make the active guide wrap to text. If itā€™s set to wrap, regardless of the cursor position on the line, the active guide will always be the guide furthest to the right on the line. If itā€™s set to not wrap, the guide closest to the left of the cursor will be the active guide.

0 Likes

#52

@Anomareh very cool, thank you again! Is it possible to make guide dotted?

0 Likes