Re: [code] textadept indent to correct level

From: Mitchell <m.att.foicica.com>
Date: Wed, 11 Jun 2014 10:26:03 -0400 (Eastern Daylight Time)

Hi Joe,

On Tue, 10 Jun 2014, Joseph McDonald wrote:

>
>
> On 06/09/2014 11:25 AM, Mitchell wrote:
>
>>> One of my most used functions is to hit TAB on any line, *anywhere* in
>>> the line, and that line is then correctly indented. If there is a
>>> syntax error above the current line, then the line is indented
>>> incorrectly which alerts you to fix the code above.
>>>
>>> In languages with significant whitespace, hitting tab cycles between
>>> valid positions for the current line (again, hitting tab anywhere in the
>>> line, even in the middle of a word)
>>
>> First you'd have to bind a function to the Tab key (`keys['\t'] = f`).
>> That function would have access the the current buffer's contents and
>> either analyze it itself, or pass it to another program for analysis. At
>> that point you'd know what the proper indent level is or that there is a
>> syntax error. You then would use the `buffer.line_indentation[line]`
>> property to set indentation as you see fit.
>>
>>> I also have a key bound to indent the entire buffer correctly.
>>
>> You'd probably want to use `textadept.editing.filter_through()`[1] with
>> a code formatter (e.g. tidy).
>
>
> I was thinking that the syntax highliting code (lpeg) has the info
> necessary to indent correctly. Perhaps what it uses to create the
> expand/collapse folds. Is there a "fold level" associated with each line?

Yes: `buffer.fold_level[line_num]`[1]

> Here's something that I think would be really neat for textadept:
> "Enhanced Scope Visibility" . slightly shade the background of each
> "level" of indent (scope).
>
> some pictures:
> http://hbfs.wordpress.com/2010/02/02/features-id-like-to-see-in-my-editor/
> http://marketplace.eclipse.org/content/editbox
>
> Not sure how hard that would be to implement in textadept. what do you
> think?

This would be extremely difficult, as each style has a background color.
You'd have to redefine existing styles with different shades of background
color and write a new lexer to make use of them.

Cheers,
Mitchell

[1]: http://foicica.com/textadept/api/buffer.html#fold_level

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Wed 11 Jun 2014 - 10:26:03 EDT

This archive was generated by hypermail 2.2.0 : Thu 12 Jun 2014 - 06:27:19 EDT