Additional Commands 'tag clear|findnext|findprev|getrange|priority'

pathName tag priority

Returns the priority (an positive integer value, or zero) of the specified tag. This allows to compare the priority of tags.

This little command helps to debug scripts, finding the reasons for unexpected formatting operations. This command does not add new functionality, because [lindex [.t tag names] 0] could be used instead, but the latter form is unconvenient, and for novices it is not obvious that the latter is possible. Furthermore the use of command names only for the retrieval of the priority is a bit over the top (and inperformant).

pathName tag findnext ?-discardselection? index

Finds the first tagged character either at specified position index, or right from specified position index, and returns the index of the detected character. The value of the result will be empty if no character can be found. If option -discardselection is given then the special selection tag sel will be discarded.

pathName tag findprev ?-discardselection? index

Finds the first tagged character either at specified position index, or left from specified position index, and returns the index of the detected character. The value of the result will be empty if no character can be found. If option -discardselection is given then the special selection tag sel will be discarded.

pathName tag getrange tagName index

Returns the range of text that have been tagged with tagName, and which includes the character at the specified position index (inclusive start of range, but exclusive end of range). If the character at specified position index is not tagged with tagName, then the returned value will be empty.

pathName tag clear ?-discardselection? index1 ?index2 index1 index2 ...?

Remove all tags from all of the characters starting at index1 and ending just before index2 (the character at index2 is not affected). A single command may contain any number of index1-index2 pairs. If the last index2 is omitted then all tags will be removed from the single character at index1. If there are no characters in the specified range (e.g. index1 is past the end of the file or index2 is less than or equal to index1) then the command has no effect. This command returns a list of all removed tags, sorted in order from lowest priority to highest priority. If option -discardselection is given then the special selection tag sel will not be removed.

It's quite inconvenient to implement this in Tcl with the help of existing text widget commands, but the C implementations are short, easy, and faster than Tcl implementations (only the clear command implementation is not short and easy).

These little commands helps to search quickly for tag ranges at current position, see this code snippet, which will show the tags under current mouse position:

Compatibility: obviously there is no conflict to existing commands, that's why I did not use command names like next (instead of findnext), prev (instead of findprev), or range (instead of getrange).