[Lazarus] Auto indentation

Martin lazarus at mfriebe.de
Fri Nov 6 06:17:16 CET 2009


Hans-Peter Diettrich wrote:
> Mattias Gaertner schrieb:
>
>> With the new synedit OnPaste event I will try to fix the indent on
>> paste.
>
> IMO you should rethink the handling of insertion/deletion. A single 
> Replace(start, delta, text) method can handle every case, with 
> positive deltas meaning insertion and negative deltas meaning deletion 
> or substitution of text. This single method knows about the range of 
> the affected text, as required for the handling of all related 
> attributes (line count, cursor position, syntax highlighting, blocks, 
> folding, formatting, bookmarks...). All related objects should 
> implement the same method for dealing with updates.
>
Maybe you can elaborate in which context you the above statement should 
be interpreted?

We are talking here about specifically selected (and selected only) 
events for which SynEdit is providing an interface for *external* 
components.
This is the same as a buttons OnClick, or OnFoo event that allows code 
not known to the component to react to events occurring inside the 
component.

Inside the IDE OnPaste is going to be used by codetools, but in user 
apps the programmer is free to use (and of course abuse) this on his/her 
terms.
Codetools does not need to know every edit/modification of the text. In 
fact there are many edits/modifications that this part of codetool 
should not react to.

Clipboard interaction (for an editor component) is a generic event that 
mat be of interest, in the same way as OnClick is on a button.

-----
Internally SynEdit has a small set of methods through which *all* 
modifications to text are done.
Agreed one would have been enough. But it is the same distinction  has 
having 2 methods [cut and copy] or one [CutCopy(DeleteSelection:Boolean)].

They do however not move the caret. This would have meant to add special 
params. After all not every text modification moves the caret.
They do provide hooks, that are used by other editor feature to react to 
the changes.

I am aware that you (IIRC) prefer a micro-controller scenario. But for 
various features it is IMHO better to use generic hooks.
Example: No micro controller is/should be needed to update bookmarks 
(Except for the controlling element in the bookmark manager). The 
bookmark manager hooks into synedit, observes any text change, and 
adjusts all bookmarks.

This is actually a pre-condition for having the same content in multiply 
editor windows. Each SynEdit (using the same shared TextBuffer) can hook 
into the textbuffer and adjust to any change that happens.


> A single Replace(start, delta, text) method 
Can not deal (unless given a specialized argument) with the 
differentiation between smNormal and smColum. smColumn is very specific 
to Block-Selection and therefore translated there.
the basic text modification only knows contineus/flowing text that can 
be edited/replaced.

This again makes it a difference to an OnPaste event, which exposes the 
speciality of smColumn. something that does not exist in other edit 
actions.

Martin







More information about the Lazarus mailing list