1ctext(n) Ctext a text widget with highlighting support ctext(n)
2
3
4
5______________________________________________________________________________
6
8 ctext - Ctext a text widget with highlighting support
9
11 package require Tk
12
13 package require ctext ?3.1?
14
15 ctext pathName ?options?
16
17 ::ctext::addHighlightClass pathName class color keywordlist
18
19 ::ctext::addHighlightClassWithOnlyCharStart pathName class color char
20
21 ::ctext::addHighlightClassForSpecialChars pathName class color
22 charstring
23
24 ::ctext::addHighlightClassForRegexp pathName class color pattern
25
26 ::ctext::clearHighlightClasses pathName
27
28 ::ctext::getHighlightClasses pathName
29
30 ::ctext::deleteHighlightClass pathName class
31
32 ::ctext::enableComments enable
33
34 ::ctext::disableComments enable
35
36 pathName highlight startIndex endIndex
37
38 pathName fastdelete index1 ?index2?
39
40 pathName fastinsert
41
42 pathName copy
43
44 pathName cut
45
46 pathName paste
47
48 pathName append
49
50_________________________________________________________________
51
53 The ctext package provides the ctext widget which is an enhanced text
54 widget with support for configurable syntax highlighting and some extra
55 commands.
56
57 Ctext overloads the text widget and provides new commands, named high‐
58 light, copy, paste,cut, append, and edit. It also provides several
59 commands that allow you to define classes. Each class corresponds to a
60 tag in the widget.
61
63 ctext pathName ?options?
64 Creates and configures a ctext widget.
65
67 Highlighting is controlled with text widget tags, that are called high‐
68 light classes. The class is a tag name and can be configured like any
69 text widget tag. Four types of highlight classes are supported. All
70 highlight classes are automatically used by the highlight method of the
71 widget.
72
73 ::ctext::addHighlightClass pathName class color keywordlist
74 Add a highlighting class class to the ctext widget pathName.
75 The highligthing will be done with the color color. All words in
76 the keywordlist will be highlighted.
77
78 # highlight some tcl keywords
79 ::ctext::addHighlightClass .t tclkeywords red [list set info interp uplevel upvar]]
80
81
82 ::ctext::addHighlightClassWithOnlyCharStart pathName class color char
83 Add a highlighting class class to the ctext widget pathName.
84 The highligthing will be done with the color color. All words
85 starting with char will be highlighted.
86
87 ::ctext::addHighlightClassWithOnlyCharStart .t vars blue \$
88
89
90 ::ctext::addHighlightClassForSpecialChars pathName class color
91 charstring
92 Add a highlighting class class to the ctext widget pathName.
93 The highligthing will be done with the color color. All chars in
94 charstring will be highlighted.
95
96 ::ctext::addHighlightClassForRegexp pathName class color pattern
97 Add a highlighting class class to the ctext widget pathName.
98 The highligthing will be done with the color color. All text
99 parts matching the regexp pattern will be highligthed.
100
101 ::ctext::clearHighlightClasses pathName
102 Remove all highlight classes from the widget pathName.
103
104 ::ctext::getHighlightClasses pathName
105 List all highlight classes for the widget pathName.
106
107 ::ctext::deleteHighlightClass pathName class
108 Delete the highlight class class from the widget pathName
109
110 ::ctext::enableComments enable
111 Enable C comment highlighting. The class for c-style comments is
112 _cComment. The C comment highlighting is disabled by default.
113
114 ::ctext::disableComments enable
115 Disable C comment highlighting.
116
118 Each ctext widget created with the above command supports the following
119 commands and options in addition to the standard text widget commands
120 and options.
121
122 pathName highlight startIndex endIndex
123 Highlight the text between startIndex and endIndex.
124
125 pathName fastdelete index1 ?index2?
126 Delete text range without updating the highlighting. Arguments
127 are identical to the pathName delete command inherited from the
128 standard text widget.
129
130 pathName fastinsert
131 Insert text without updating the highlighting. Arguments are
132 identical to the pathName insert command inherited from the
133 standard text widget.
134
135 pathName copy
136 Call tk_textCopy for the ctext instance.
137
138 pathName cut
139 Call tk_textCut for the ctext instance.
140
141 pathName paste
142 Call tk_textPaste for the ctext instance.
143
144 pathName append
145 Append the current selection to the clipboard.
146
148 Command-Line Switch: -linemap
149 Database Name:
150 Database Class:
151
152
153 Creates a line number list on the left of the widget
154
155 Command-Line Switch: -linemapfg
156 Database Name:
157 Database Class:
158
159
160 Changes the foreground of the linemap. The default is the same
161 color as the main text widget.
162
163 Command-Line Switch: -linemapbg
164 Database Name:
165 Database Class:
166
167
168 Changes the background of the linemap. The default is the same
169 color as the main text widget.
170
171 Command-Line Switch: -linemap_select_fg
172 Database Name:
173 Database Class:
174
175
176 Changes the selected line foreground. The default is black.
177
178 Command-Line Switch: -linemap_select_bg
179 Database Name:
180 Database Class:
181
182
183 Changes the selected line background. The default is yellow.
184
185 Command-Line Switch: -linemap_mark_command
186 Database Name:
187 Database Class:
188
189
190 Calls a procedure or command with the pathName of the ctext win‐
191 dow, the type which is either marked or unmarked, and finally
192 the line number selected. The proc prototype is:
193
194 proc linemark_cmd {win type line}.
195
196 See also ctext_test_interactive.tcl
197
198 Command-Line Switch: -highlight
199 Database Name:
200 Database Class:
201
202
203 Takes a boolean value which defines whether or not to highlight
204 text which is inserted or deleted. The default is 1.
205
206 Command-Line Switch: -linemap_markable
207 Database Name:
208 Database Class:
209
210
211 Takes a boolean value which specifies whether or not lines in
212 the linemap are markable with the mouse. The default is 1.
213
215 package require Tk
216 package require ctext
217
218 proc main {} {
219 pack [frame .f] -fill both -expand 1
220 pack [scrollbar .f.s -command {.f.t yview}] -side right -fill y
221
222 pack [ctext .f.t -bg black -fg white -insertbackground yellow -yscrollcommand {.f.s set}] -fill both -expand 1
223
224 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]
225
226 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]
227
228 ctext::addHighlightClass .f.t stackControl red {proc uplevel namespace while for foreach if else}
229 ctext::addHighlightClassWithOnlyCharStart .f.t vars mediumspringgreen "\$"
230 ctext::addHighlightClass .f.t variable_funcs gold {set global variable unset}
231 ctext::addHighlightClassForSpecialChars .f.t brackets green {[]{}}
232 ctext::addHighlightClassForRegexp .f.t paths lightblue {\.[a-zA-Z0-9\_\-]+}
233 ctext::addHighlightClassForRegexp .f.t comments khaki {#[^\n\r]*}
234 .f.t fastinsert end [info body main]
235
236 pack [frame .f1] -fill x
237
238 .f.t highlight 1.0 end
239
240 pack [button .f1.exit -text Exit -command exit] -side left
241
242 pack [entry .e] -side bottom -fill x
243 .e insert end "ctext::deleteHighlightClass .f.t "
244 bind .e <Return> {eval [.e get]}
245 }
246 main
247
248
249 Further examples are in the source package for ctext.
250
252 Kevin Kenny, Neil Madden, Jeffrey Hobbs, Richard Suchenwirth, Johan
253 Bengtsson, Mac Cody, Günther, Andreas Sievers, and Michael Schlenker.
254
256 re_syntax, text
257
259 syntax highlighting, text, widget
260
262 Copyright (c) George Peter Staplin <GeorgePS@XMission.com>
263
264
265
266
267ctext 3.1 ctext(n)