logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

ctext - Ctext a text widget with highlighting support

Bugs, Ideas, Feedback

       This  document,  and  the package it describes, will undoubtedly contain bugs and other problems.  Please
       report such in the category ctext of the TklibTrackers  [http://core.tcl.tk/tklib/reportlist].   Please
       also report any ideas for enhancements you may have for either package and/or documentation.

Commands

ctextpathName ?options?
              Creates and configures a ctext widget.

Description

       The  ctext  package  provides  the  ctext  widget  which  is  an  enhanced  text  widget with support for
       configurable syntax highlighting and some extra commands.

       Ctext overloads the text widget and provides new commands, named highlight, copy, paste,cut, append,  and
       edit.   It  also provides several commands that allow you to define classes.  Each class corresponds to a
       tag in the widget.

Example

                package require Tk
                package require ctext

                proc main {} {
                pack [frame .f] -fill both -expand 1
                pack [scrollbar .f.s -command {.f.t yview}] -side right -fill y

                pack [ctext .f.t -bg black -fg white -insertbackground yellow  -yscrollcommand {.f.s set}] -fill both -expand 1

                ctext::addHighlightClass .f.t widgets purple  [list ctext button label text frame toplevel  scrollbar checkbutton canvas listbox menu menubar menubutton  radiobutton scale entry message tk_chooseDir tk_getSaveFile  tk_getOpenFile tk_chooseColor tk_optionMenu]

                ctext::addHighlightClass .f.t flags orange  [list -text -command -yscrollcommand  -xscrollcommand -background -foreground -fg -bg  -highlightbackground -y -x -highlightcolor -relief -width  -height -wrap -font -fill -side -outline -style -insertwidth  -textvariable -activebackground -activeforeground -insertbackground  -anchor -orient -troughcolor -nonewline -expand -type -message  -title -offset -in -after -yscroll -xscroll -forward -regexp -count  -exact -padx -ipadx -filetypes -all -from -to -label -value -variable  -regexp -backwards -forwards -bd -pady -ipady -state -row -column  -cursor -highlightcolors -linemap -menu -tearoff -displayof -cursor  -underline -tags -tag]

                ctext::addHighlightClass .f.t stackControl red  {proc uplevel namespace while for foreach if else}
                ctext::addHighlightClassWithOnlyCharStart .f.t vars mediumspringgreen "\$"
                ctext::addHighlightClass .f.t variable_funcs gold {set global variable unset}
                ctext::addHighlightClassForSpecialChars .f.t brackets green {[]{}}
                ctext::addHighlightClassForRegexp .f.t paths lightblue {\.[a-zA-Z0-9\_\-]+}
                ctext::addHighlightClassForRegexp .f.t comments khaki {#[^\n\r]*}
                .f.t fastinsert end [info body main]

                pack [frame .f1] -fill x

                .f.t highlight 1.0 end

                pack [button .f1.exit -text Exit -command exit] -side left

                pack [entry .e] -side bottom -fill x
                .e insert end "ctext::deleteHighlightClass .f.t "
                bind .e <Return> {eval [.e get]}
                }
                main

       Further examples are in the source package for ctext.

Highlighting

       Highlighting is controlled with text widget tags, that are called highlight classes.  The class is a  tag
       name  and can be configured like any text widget tag.  Four types of highlight classes are supported. All
       highlight classes are automatically used by the highlight method of the widget.

       ::ctext::addHighlightClasspathNameclasscolorkeywordlist
              Add a highlighting class class to the ctext widget pathName.  The highlighting will be  done  with
              the color color. All words in the keywordlist will be highlighted.

                # highlight some tcl keywords
                ::ctext::addHighlightClass .t tclkeywords red [list set info interp uplevel upvar]

       ::ctext::addHighlightClassWithOnlyCharStartpathNameclasscolorchar
              Add  a  highlighting class class to the ctext widget pathName.  The highlighting will be done with
              the color color. All words starting with char will be highlighted.

                ::ctext::addHighlightClassWithOnlyCharStart .t vars blue \$

       ::ctext::addHighlightClassForSpecialCharspathNameclasscolorcharstring
              Add a highlighting class class to the ctext widget pathName.  The highlighting will be  done  with
              the color color. All chars in charstring will be highlighted.

       ::ctext::addHighlightClassForRegexppathNameclasscolorpattern
              Add  a  highlighting class class to the ctext widget pathName.  The highlighting will be done with
              the color color. All text parts matching the regexp pattern will be highlighted.

       ::ctext::clearHighlightClassespathName
              Remove all highlight classes from the widget pathName.

       ::ctext::getHighlightClassespathName
              List all highlight classes for the widget pathName.

       ::ctext::deleteHighlightClasspathNameclass
              Delete the highlight class class from the widget pathName::ctext::enableCommentsenable
              Enable C comment highlighting. The class  for  c-style  comments  is  _cComment.   The  C  comment
              highlighting is disabled by default.

       ::ctext::disableCommentsenable
              Disable C comment highlighting.

Keywords

       syntax highlighting, text, widget

Name

       ctext - Ctext a text widget with highlighting support

See Also

       re_syntax, text

Synopsis

       package require Tk

       package require ctext?3.3?ctextpathName ?options?

       ::ctext::addHighlightClasspathNameclasscolorkeywordlist::ctext::addHighlightClassWithOnlyCharStartpathNameclasscolorchar::ctext::addHighlightClassForSpecialCharspathNameclasscolorcharstring::ctext::addHighlightClassForRegexppathNameclasscolorpattern::ctext::clearHighlightClassespathName::ctext::getHighlightClassespathName::ctext::deleteHighlightClasspathNameclass::ctext::enableCommentsenable::ctext::disableCommentsenablepathNamehighlightstartIndexendIndexpathNamefastdeleteindex1 ?index2?

       pathNamefastinsertpathNamecopypathNamecutpathNamepastepathNameappendpathNameconfigureoptionvalue ?...?

________________________________________________________________________________________________________________

Thanks

       Kevin Kenny, Neil Madden, Jeffrey Hobbs, Richard Suchenwirth, Johan Bengtsson, Mac Cody, Günther, Andreas
       Sievers, and Michael Schlenker.

Widget Commands

       Each  ctext widget created with the above command supports the following commands and options in addition
       to the standard text widget commands and options.

       pathNamehighlightstartIndexendIndex
              Highlight the text between startIndex and endIndex.

       pathNamefastdeleteindex1 ?index2?
              Delete text range without updating the highlighting.  Arguments  are  identical  to  the  pathNamedelete command inherited from the standard text widget.

       pathNamefastinsert
              Insert  text  without  updating  the  highlighting. Arguments are identical to the pathNameinsert
              command inherited from the standard text widget.

       pathNamecopy
              Call tk_textCopy for the ctext instance.

       pathNamecut
              Call tk_textCut for the ctext instance.

       pathNamepaste
              Call tk_textPaste for the ctext instance.

       pathNameappend
              Append the current selection to the clipboard.

       pathNameconfigureoptionvalue ?...?
              Set the options for the ctext widget. Each option name must be followed the new value.

Widget Options

       Command-Line Switch:    -linemap
       Database Name:
       Database Class:

              Creates (-linemap 1) or deletes (-linemap 0) a line number list on the left  of  the  widget.  The
              default is to have a linemap displayed.

       Command-Line Switch:    -linemapfg
       Database Name:
       Database Class:

              Changes the foreground of the linemap.  The default is the same color as the main text widget.

       Command-Line Switch:    -linemapbg
       Database Name:
       Database Class:

              Changes the background of the linemap.  The default is the same color as the main text widget.

       Command-Line Switch:    -linemap_select_fg
       Database Name:
       Database Class:

              Changes the selected line foreground.  The default is black.

       Command-Line Switch:    -linemap_select_bg
       Database Name:
       Database Class:

              Changes the selected line background.  The default is yellow.

       Command-Line Switch:    -linemap_mark_command
       Database Name:
       Database Class:

              Calls  a  procedure  or  command  with  the pathName of the ctext window, the type which is either
              marked or unmarked, and finally the line number selected.  The proc prototype is:

              proc linemark_cmd {win type line}.

              See also ctext_test_interactive.tcl

       Command-Line Switch:    -highlight
       Database Name:
       Database Class:

              Takes a boolean value which defines whether or not to highlight text which is inserted or deleted.
              The default is 1.

       Command-Line Switch:    -linemap_markable
       Database Name:
       Database Class:

              Takes a boolean value which specifies whether or not lines in the linemap are  markable  with  the
              mouse.  The default is 1.

See Also