[Lazarus] Auto indentation

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Nov 3 22:31:41 CET 2009


On 03/11/2009, Martin <lazarus at mfriebe.de> wrote:
>  Yes it is possible, and yes it should be very easy to do so.
>  With one exception: Any form of auto Indent will not work with it yet

That is good to know. With Elastic Tabstops, "auto indent" is not
really needed. A simple press of the Tab key will automatically indent
the correct amount of pixels to align with the block (Cell) above it.

This page explains the "cells" or "code blocks" in a visual form to
understand it better.
http://nickgravgaard.com/elastictabstops/


>  The calculation of tabs is done entirely (with the exception of auto
> indent) in the unit SynEditTextTabExpander

So where would I start with an elastic tabstops implementation. I
remember years ago you (or somebody else) mentioned that the best
approach might be some synedit plugin.


>  The unit can set the "width" (amount of spaces covered by) each tab
> individually.

Is "width" in characters or in pixels? Currently elastic tabstops work
like a word processor where tabstop width is set in pixels.

Just to be clear of how Elastic Tabstops work, here follows a simple
explanation.

eg: Using the elastic tabstops plugin for Gnome's gEdit editor, I can
set some custom user defined parameters values.

gconftool-2 --type int --set
/apps/gedit-2/plugins/elastictabstops/minimumwidth 10
gconftool-2 --type int --set
/apps/gedit-2/plugins/elastictabstops/paddingwidth 16

This sets the miminum stabstop width to 10 pixels. And paddingwidth to
16 pixels. The later is used for tabs after text, not the first tab on
a line. So if I was at the left edge of my editor window and I press
the Tab key, I would jump 10 pixels right. That 10 pixel width is only
constant for the first tabstop in a line. After that, pressing the Tab
key, it will align to the tab cell/block above it.

eg:  <t> = Tab key pressed and Char(09) is inserted

begin
<t>i := 0;<t>// line one comment
<t><t>// line 2 comment
end;

Using a minimumwidth and paddingwidth of above. With elastic tabstops
the first tab will be 10 pixels from the left. The second tab on that
same line with be 10 + 16 pixels (minimumwidth + paddingwidth) away
from the text before the "// line one comment" is located.

On line 2, the first Tabstop is again 10 pixels. The second Tabstop
will jump a large about so it lines up with the second tabstop of the
previous line.

So even though the second line only has two physical Tab characters
($09), the comment will start wherever the previous lines second
tabstop is set. This is the "elastic" part of elastic tabstops.


So the current SynEdit used in Lazarus should be able to support this?
Sorry if I sound repetitive, but I don't want to start a possible
complex implementation, just to find out later that SynEdit doesn't
actually support what "elastic tabstops" required from a editor
component. :-)


>  If you subclass it, and then do the calculation inside (and add callbacks
> to tell synedit, that lines must be repainted), then it should work out of
> the box

I'll take a closer look at the synedit code in a week or two, when
time permits. But from what I remember in my last synedit adventure,
the synedit code was quite complex and riddled with IFDEF statements.



-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/




More information about the Lazarus mailing list