Additional Option '-marks' for 'delete'

pathName delete ?options? index1 ?index2 …?

Delete a range of characters from the text. If both index1 and index2 are specified, then delete all the characters starting with the one given by index1 and stopping just before index2 (i.e. the character at index2 is not deleted). If index2 does not specify a position later in the text than index1 then no characters are deleted. If index2 is not specified then the single character at index1 is deleted. Attempts to delete characters in a way that would leave the text without a newline as the last character will be tweaked by the text widget to avoid this. In particular, deletion of text up to the end of the text (inclusively the last newline) will not delete the last newline, but the tag associations of this newline will be cleared. The command returns an empty string. If more indices are given, multiple ranges of text will be deleted. All indices are first checked for validity before any deletions are made. They are sorted and the text is removed from the last range to the first range so deleted text does not cause an undesired index shifting side-effects. If multiple ranges with the same start index are given, then the longest range is used. If overlapping ranges are given, then they will be merged into spans that do not cause deletion of text outside the given ranges due to text shifted during deletion.

This command allows the following options:


Additionally all the marks belonging to the specified range will be deleted. Here the indices will be interpreted differenty (but it's important to note that this re-interpretation is not affecting the range of character deletion). If index1 is specified in a numerical form the deletion of the marks starts with the first mark at this position, otherwise it starts with the next mark after that mark; provided that a mark at this position exists, otherwise the deletion starts at first character position. If index2 is specified in a numerical form the deletion ends with the first mark at this position (not including this mark), otherwise it ends immediately before that mark; provided that a mark at this position exists, otherwise the deletion ends just before last character position (specified with index2). If index2 is unspecified then index2 will be assumed as equal to "$index1+1c". This option is especially intended for programmed editor control, if option -steadymarks is activated. Note that the special marks insert and current, and also generated marks (see mark generate), will not be deleted.


This option is useful only if combined with option -marks. It causes that also the marks referred to by index1 and index2 will be deleted (provided that the concerned mark is neither a special mark – insert or current, – nor a generated mark).

Removing the marks inside a range now is very convenient for the user (when combined with character deletion). Currently there is no other method to remove the marks inside a range as bookkeeping, or via iteration with mark next.

Although the deletion of marks has no effect on the display content, it is a good help for writing programmed editor control. Now with the existence of this feature it is clear for the reader of the program (script) whether marks inside a range are intended to be re-usable (undeleted) or not. If the developer is referencing a deleted mark an error will be thrown, this supports debugging.

In the revised version the implementation of this feature was quite trivial.

In the description above I replaced the following line:

In particular, deletion of complete lines of text up to the end of the text will also delete the newline character just before the deleted block so that it is replaced by the new final newline of the text widget.

This description is based on the way how the tagging is implemented in old widget implementation. But with revised implementation this method – to replace newlines – is erroneous.