Additional Commands 'isclean|isdead|isempty'

pathName isempty ?-overall?

Returns whether this widget does not contain any character, soft hyphen, embedded window, or embedded image, except a sole newline. If option -overall is specified, then this test will discard any restrictions given with widget options -startindex and -endindex.

Note that this is a fast and easy to use command, and an alternative like

is very inconvenient. And [.t edit modified/altered] is in general not working for this test. Also {[.t get begin end] eq "\n"} is of course not acceptable as an alternative. Note that for statement [.t isempty -overall] there exists no alternative (in general).

pathName isclean ?-overall? ?-discardselection?

Returns whether this widget does not contain any character, soft hyphen, embedded window, or embedded image, except an untagged sole newline. Furthermore a clean widget does not contain any marks, except the special marks current and insert, and generated marks. If option -overall is specified, then this test will discard any restrictions given with widget options -startindex and -endindex. If option -discardselection is given then the special selection tag sel will be discarded when testing whether the sole newline is tagged.

This is a convenient shortcut for:

And if option -overall is involved then there exists no alternative expression for [.t isclean -overall] (in general).

Command isclean is also supporting the new option -steadymarks, because this option can be set only if the widget is overall clean.

Note that after applying command clear the widget is overall clean.

Here is an useful example for isempty:

This code snippet is deleting all leading newlines. Without the additional test ![.t isempty] this loop may not terminate; consider that the text widget always ensures at least one newline (except dead peers).

The next example demonstrates why isempty and isclean are quite different:

The first output statement prints an empty string, and the second prints character "a".

pathName isdead

A text widget is dead if it does not contain any line (in this case no insertion is possible anymore). This only happens if one of the widget options -start/endindex is specified.

A convenient command for testing if a peer is dead. Another possibility is something like [.t compare begin == end], or [.t lineno end] == 0, but the use of command isdead is more expressive.