[TxMt] Re: Row iterator object

Jacob Carlborg doob at me.com
Fri May 27 16:05:40 UTC 2016


On 2016-05-27 13:24, Josh Bernitt wrote:
> I’ve been digging around more in the effort to “pretty print” the indent
> guides, and my current plan (based on what I’ve seen) is to
>
>  1. iterate over each row in the editor
>  2. parse each row and search for levels of indentation
>  3. draw the indent guide up to the highest level of indentation
>
> I don’t know of a different way to “pretty print” since each indent
> guide is determined by the current indent level at a row. If you have a
> better idea, please let me know.

Sounds right to me.

> As far as parsing goes, I haven’t seen anything specific that will
> automatically pull in a line up until ‘\n’. Is that correct, or did I
> miss a function somewhere? From what I see, I need to use the row
> iterator to pull each line from the buffer object, then use something in
> the text/ framework to parse each line?

There's already a loop that iterates each row and draws the text for 
that row [1]. I guess you can add the indent guide drawing code to that 
loop.

I'm guessing you need to parse each line looking for the first non 
whitespace character and count the number of indentations up to that 
character. You need to know the indentation setting, i.e. tab or space 
and how many spaces. I don't think you need to worry about any Unicode 
because what you'll be looking for is in the ASCII table.

[1] 
https://github.com/textmate/textmate/blob/master/Frameworks/layout/src/layout.cc#L855-L856

-- 
/Jacob Carlborg



More information about the textmate mailing list