dgw::txmixins - functionality extensions for the tk::text widget such as folding, auto-indenting and abbreviations.


dgw::txmixins - The package dgw::txmixins implements several snit::widgetadaptors which extend the standard *tk::text* widget with different functionalities. Different adaptors can be chained together to add the required functionalities. Please note that most of the functionalities are not coded mainly by the author of the package DDG but just wrappers of the functionalities into snit::widgetadaptors for easy usage and combining the different properties and functionalities.

The following adaptors are currently available:

  • dgw::txfold - provide fold marks to hide and show certain parts of the text, for instance to navigate fast a large markdown file by just showing the section headers
  • dgw::txautorep - short abbreviations snippets invoked after closing parenthesis
  • dgw::txindent - keep indentation of previous line
  • dgw::txrotext - read only text widget

There is further a convenience function which simplifies addition of adaptors without a lot of nesting calls:

  • dgw::txmixin - add widgets adaptors to existing widgets after widget creation



Let's create a folding text editor for Markdown files:

# demo: txfold
dgw::txfold [tk::text .txt]
foreach col [list A B C] { 
   .txt insert  end "# Header $col\n\nSome text\n\n"
.txt insert end "Place the cursor on the header lines and press F2\n"
.txt insert end "or press F3 to fold or unfold the complete text.\n"
.txt tag configure fold -background #cceeff
.txt configure -borderwidth 10 -relief flat
pack .txt -side top -fill both -expand yes
# next line would fold by double click (although I like F2 more ...)
# .txt configure -foldkey Double-1 
bind .txt <Enter> { focus -force .txt }


Walking to the second section and pressing F2:


Global overview after two times pressing F3 (first unfold, then fold all):


You can navigate fast with the cursor into a section and unfold this section using F2. After editing here you can fold this section again and go to the next section.

Now an example for a Tcl or C folding editor: This will fold all lines starting with a letter and ending with a opening curly brace up to lines beginning with a closing curly brace.

set tcltxt [tk::text .tcl -borderwidth 5 -relief flat]
dgw::txmixin $tcltxt dgw::txfold -foldstart "^\[A-Za-z\].+\{" -foldend "^\}"
$tcltxt tag configure fold -background #aaccff
$tcltxt insert end "package require Tk\nproc test {} {\n    puts Hi\n}\n\nsnit::widget wid {\n\n}\n"
pack $tcltxt -side left -fill both -expand true


  • 2021-08-19: 0.1 first release



Please discuss here.

DDG 2021-08-21 - the principal idea of mixins or snit widgetdaptors is to avoid huge megawidget constructions but just extend on the fly existing widgets with new functionalities.