tcl_wordchars

$tcl_wordchars and $tcl_nonwordchars are built-in global variables which each contain a regular expression that is used by routines like tcl_endofword to identify whether a character is part of a word.

See Also

tclvars
for other variables used by tcl/tk.

Description

If the pattern in $tcl_wordchars matches a character, the character is considered to be a word character. Under Unix, words are comprised of numbers, letters or underscores. On Windows platforms, Tk interpreted words as comprised of any character that is not a space, tab, or newline. But actually, Tk's behavior on Windows is nowadays generally considered a mistake.

They are auto-loaded along with the commands they control, such as tcl_endOfWord. This means that to change the characters that are valid, you must first do something like:

catch {tcl_endOfWord}

After this, you can then do something like:

# We want the same behaviour on Windows as on Unix for double-clicking
set tcl_wordchars {\w}
set tcl_nonwordchars {\W}

MG: The defaults for Unix (or rather, non-Windows), according to the docs for Tcl 8.4.9, are actually \w and \W (with \S and \s on Windows), which might differ from the above due to locale. Personally, I tend to use

set tcl_wordchars {[a-zA-Z0-9' ]}
set tcl_nonwordchars {[^a-zA-Z0-9']}

for my apps on Windows - I tend to find that gives much more natural behaviour, particularly compared to other apps when you move the cursor a word at a time with Control-Left / Control-Right.


[To Do: Add list of tcl and tk routines that actually use these variables.]