Additional Commands 'mark compare|exists|generate'

mark compare markName1 op markName2

Compares the marks given by markName1 and markName2 according to the relational operator given by op, and returns 1 if the relationship is satisfied and 0 if it is not. Op must be one of the operators <, <=, ==, >=, >, or !=. If op is == then 1 is returned if the two marks are the same, if op is < then 1 is returned if markName1 refers to an earlier mark in the text than markName2, and so on. If one of the given operands is not an exisiting mark, then an error will be thrown. This command is especially useful when option -steadymarks is enabled.

When option -steadymarks is enabled the command compare is not sufficient for the check of the relation between two marks. It is possible to use mark prev and mark next for this test, but mark compare is more performant, and easier to use. The practical use of mark compare is in general not very high, but it's an important function for debugging code.

mark exists markName

Returns whether the specified mark is already existing at any position.

A convenient method for testing the existence of a mark. This is especially useful in programmed editor control, when marks will be generated (by the program), or when temporary marks are needed. The modified version of library/text.tcl is also using this command.

Alternatives for the test of the existence of a mark, e.g. using commands like [markName in [$w mark names]], or [catch {$w index markName}], are not convenient, and these commands are not as performant as the new command. Furthermore it's the only way to test the existence of a generated mark (see Additional Command 'mark generate') – when constructions with the use of catch will be avoided. (The other alternative, searching the result of the dump command, is of course unacceptable.)

pathName mark generate

Creates a mark, either for temporary use, or for static use. This mark has the following properties:

  1. Operations on this mark will not be stacked onto the undo stack (relevant only if option -steadymarks is enabled).

  2. It is not visible, this means that the commands mark names, mark next, and mark previous will not return generated marks, and command inspect will not print this mark (but command dump will print it, it has the form ##ID##[:hexdigit:]+##[:hexdigit:]+##[:digit:]+##).

  3. This mark cannot be deleted except with command mark unset (this means that delete -marks will not delete this kind of marks).

  4. Commands clear and load will not delete this mark, but the relative order to other (generated) marks may change after clearing the text content (command load is also clearing before loading).

  5. After deletion of a generated mark (with mark unset) this mark will expire, which means that a subsequent call of mark set with this mark will throw an error.

The initial position of this mark is at start of text. This command returns the generated name of the mark.

With new undo/redo implementation it is very convenient (and a must) to have marks (other than "insert" and "current") which will be discarded by undo/redo operations (although operations on marks will be undoable only if option -steadymarks is enabled). Furthermore it is quite convenient to have marks with unique names only for temporary (or static) use, now the revised implementation of library/text.tcl is using this kind of marks. It is ensured that the generated mark name cannot clash with any exisiting mark (the probability of a clash is less than 1:2028).

It seems appropriate to adapt the documentation of mark unset:

mark unset

Remove the mark corresponding to each of the markName arguments. The removed marks will not be usable in indices and will not be returned by future calls to mark names, mark next, and mark previous. When removing a generated mark (see mark generate) a future call of mark set with this mark will throw an error (even after clearing the widget). This command returns an empty string.