ntext(3tk)
β¨ NAME β¨
okay so bestie, welcome to the ntext(3tk) page π β the whole vibe here is ntext β Alternative Bindings for the Text Widget. that's the name, that's the assignment, and we are obsessed π«Ά
π¦ SYNOPSIS π¦
the way you summon all this, literally:
package require Tcl 8.5-
package require Tk 8.5-
package require ntext ?1.0?
::ntext::new_textCopy pathName
::ntext::new_textCut pathName
::ntext::new_textPaste pathName
::ntext::syncIndentColor pathName
::ntext::syncTabColor pathName
no cap, that's the whole opening move β¨
πΈ DESCRIPTION πΈ
so the whole purpose of the ntext package is to make the text widget behave more like other text-editing applications π
like, it makes the text widget way more useful for implementing a text editor, and it makes it behave in a way that will be more familiar to most users. iconic behaviour, honestly.
The package provides a binding tag named Ntext for use by text widgets in place of the default Text binding tag. π
Package ntext's functions and variables are contained entirely in the ::ntext namespace; its other code is contained in the binding tag Ntext. ntext has no exports to the global or other namespaces, and no new widget commands. It uses modified copies of the Tk code, leaving the original code, and the Text binding tag, unchanged. very much "i made my own version, yours is safe" energy π§
The differences between the Ntext binding tag and the default Text binding tag are in three categories:
- Some
Textbindings behave differently from most text-editing applications.Ntextgives these bindings more familiar behaviour. For details seentextBindings. - When a logical line with leading whitespace is word-wrapped onto more than one display line, the wrapped display lines begin further to the left than the first display line, which can make the text layout untidy and difficult to read.
Ntextcan indent the wrapped lines to match the leading whitespace of the first display line (this facility is switched off by default π). For details seentextIndent. - When the user navigates or selects text, Tcl/Tk sometimes needs to detect word boundaries.
Ntextprovides improved rules for word boundary detection. For details seentextWordBreak.
The remainder of this page describes the basic use and configuration of all three aspects of Ntext. For more detailed information on the different facilities of Ntext, see the pages ntextBindings, ntextIndent, and ntextWordBreak.
See Section EXAMPLE for how to apply the Ntext binding tag in place of the Text binding tag. β
π COMMANDS π
::ntext::new_textCopy pathNameβ Replacement for::tk_textCopy.::ntext::new_textCut pathNameβ Replacement for::tk_textCutthat also maintains Ntext indentation (seentextIndent).::ntext::new_textPaste pathNameβ Replacement for::tk_textPastethat also maintains Ntext indentation (seentextIndent).::ntext::syncIndentColor pathNameβ Command to apply the current value of the variable::ntext::indentColorto existing lines in a text widget. This command is useful if a text widget has been created, text has been inserted in the widget, and then the value of::ntext::indentColoris changed (seentextIndent).::ntext::syncTabColor pathNameβ Command to apply the current values of the variables::ntext::tabColorand::ntext::tabSelColorto tab spaces in a text widget. This command is useful if a text widget has been created, text has been inserted in the widget, and then the value of::ntext::tabColoror::ntext::tabSelColoris changed.
π CONFIGURATION OPTIONS π
Ntext provides alternatives to a number of behaviours of the classic Text binding tag. Where there is an option, the Ntext behaviour (except for display-line indentation) is switched on by default. π
The behaviour of Ntext may be configured application-wide by setting the values of a number of namespace variables:
π ::ntext::classicAnchor
0β (default value) selects Ntext behaviour, i.e. the anchor point is fixed1β selects classic Text behaviour, i.e. the anchor point is variable- For more information see
ntextBindings
π ::ntext::classicExtras
0β (default value) selects Ntext behaviour, i.e. several traditional Text bindings are de-activated1β selects classic Text behaviour, i.e. all Text bindings are activated- For more information see
ntextBindings
π ::ntext::classicMouseSelect
0β (default value) selects Ntext behaviour, i.e. the anchor point for mouse selection operations is moved by keyboard navigation1β selects classic Text behaviour- For more information see
ntextBindings
π ::ntext::classicParagraphs
0β (default value) on macOS Aqua, certain keyboard bindings are made to behave in the same way as the Mac application TextEdit. The bindings involve vertical scrolling of the screen and are<?Shift-?Option-(Up|Down)>.1β on macOS Aqua, certain keyboard bindings are made to behave in the same way as classic Text, ignoring the conventions of Aqua. The bindings involve vertical scrolling of the screen and are<?Shift-?Option-(Up|Down)>.- For more information see
ntextBindings
π ::ntext::classicSelection
0β (default value on macOS Aqua) selects Mac-like behaviour, i.e. when a navigation keystroke cancels a selection, the insert mark first moves to the end of the selection determined by the navigation direction of the keystroke, and then the keystroke is applied.1β (default value except on macOS Aqua) selects PC-like behaviour (the same as classic Text), i.e. when a navigation keystroke cancels a selection, the insert mark is not moved before the keystroke is applied.- For more information see
ntextBindings
π ::ntext::classicWordBreak
0β (default value) selects Ntext behaviour, i.e. platform-independent, two classes of word characters and one class of non-word characters.1β selects classic Text behaviour, i.e. platform-dependent, one class of word characters and one class of non-word characters- After changing this value, the matching patterns should be recalculated. See
ntextWordBreakfor details and advanced configuration options.
π ::ntext::classicWrap
0β selects Ntext behaviour, i.e. display lines of text widgets in-wrap wordmode are indented to match the initial whitespace of the first display line of a logical line. If the widget already holds text when this value is set, a function call may be necessary. SeentextIndentfor detailed instructions on the use of Ntext's indentation.1β (default value) selects classic Text behaviour, i.e. no indentation- For more information see
ntextIndent
π ::ntext::indentColor
{}β if the value is the empty string, then the indent of wrapped display lines has the same color as the widget background.colorβ a valid Tk color to use for the indent of wrapped display lines (default value#d9d9d9).- Coloring is implemented with the text widget tag option
-lmargincolor, which is available from Tk 8.6.6 onwards. Ntext indent coloring has no effect in earlier versions of Tk. π - The value of
::ntext::indentColorwill often be set at startup. If the value is changed when text widgets already exist and contain text, those widgets can be updated by calling command::ntext::syncIndentColor.
- Coloring is implemented with the text widget tag option
- For more information see
ntextIndent
π ::ntext::overwrite
0β (initial value) text typed at the keyboard is inserted into the widget1β text typed at the keyboard overwrites text already in the widget- The value is toggled by the Insert key (except on macOS Aqua where there is no such key π).
- For more information see
ntextBindings
π ::ntext::tabColor
{}β if the value is the empty string, then the tab spaces have the same color as the widget background.colorβ a valid Tk color to use for tab spaces (default value#ffffaa).- The value of
::ntext::tabColorwill often be set at startup. If the value is changed when text widgets already exist and contain text, those widgets can be updated by calling command::ntext::syncTabColor.
- The value of
π ::ntext::tabSelColor
{}β if the value is the empty string, then the color of tab spaces in the selection defaults to the same color as unselected tabs (see::ntext::tabColor), and not to the widget-selectbackgroundcolor.colorβ a valid Tk color to use for tab spaces in the selection (default value#418bd4).- The value of
::ntext::tabSelColorwill often be set at startup. If the value is changed when text widgets already exist and contain text, those widgets can be updated by calling command::ntext::syncTabColor.
- The value of
π ::ntext::useBlockCursor
0β the block cursor will not be used. When the widget is in overwrite mode (see::ntext::overwrite), the ordinary cursor will change color instead.1β the block cursor will be used when the widget is in overwrite mode (see::ntext::overwrite).- The default value depends on the version of Tk. In versions of Tk earlier than 8.5.12, the sizing of the block cursor had a bug, and
::ntext::useBlockCursordefaults to0. From 8.5.12 onwards the bug is fixed, and::ntext::useBlockCursordefaults to1. - For more information see
ntextBindings
π BUGS π
This version of ntext is intended to be compatible with all releases of Tk 8.5, 8.6, and 8.7, and with the branches core-8-5-branch, core-8-6-branch, and trunk in the source code repository for Tk. Any incompatibility with any of these versions, for any Tk windowing system, should be reported as a bug. Please report such in the category ntext of the Tklib Trackers https://core.tcl-lang.org/tklib/reportlist.
bestie if it breaks, tell the trackers, don't just suffer in silence ππ«Ά
β EXAMPLE β
To create a text widget .t and use the Ntext bindings:
package require ntext
text .t
bindtags .t {.t Ntext . all}
See bindtags for more information.
π₯ SEE ALSO π₯
bindtags, ntextBindings, ntextIndent, ntextWordBreak, re_syntax, regexp, text
π KEYWORDS π
bindtags, re_syntax, regexp, text
and that's the whole page, bestie π this one came from tklib, version 1.0, and you've been reading the ntext(3tk) manual β go forth and let your text widget slay π
β¨π
π¦ where this page comes from
- debian trixie: tklib 0.9-1
- ubuntu questing: tklib 0.9-1
- ubuntu resolute: tklib 0.9-1build1
- ubuntu stonking: tklib 0.9-1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms