File: example_c.tcl

package info (click to toggle)
r-cran-tcltk2 1.2-10-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,356 kB
  • ctags: 1,386
  • sloc: tcl: 37,888; ansic: 792; python: 324; sh: 68; sed: 16; makefile: 1
file content (70 lines) | stat: -rwxr-xr-x 2,266 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh 
# the next line restarts using wish \
exec wish "$0" ${1+"$@"} 

#use :: so I don't forget it's global
#set ::tcl_traceExec 1

proc highlight:addClasses {win} {
	ctext::addHighlightClassForSpecialChars $win brackets green {[]}
	ctext::addHighlightClassForSpecialChars $win braces lawngreen {{}}
	ctext::addHighlightClassForSpecialChars $win parentheses palegreen {()}
	ctext::addHighlightClassForSpecialChars $win quotes "#c65e3c" {"'}

	ctext::addHighlightClass $win control red [list namespace while for if else do switch case]
		
	ctext::addHighlightClass $win types purple [list \
	int char u_char u_int long double float typedef unsigned signed]
	
	ctext::addHighlightClass $win macros mediumslateblue [list \
	#define #undef #if #ifdef #ifndef #endif #elseif #include #import #exclude]
	
	ctext::addHighlightClassForSpecialChars $win math cyan {+=*-/&^%!|<>}
}

proc main {} {
	source ./ctext.tcl

	pack [frame .f] -fill both -expand 1
	#Of course this could be cscrollbar instead, but it's not as common.
	pack [scrollbar .f.s -command ".f.t yview"] -side right -fill y

	#Dark colors			
	pack [ctext .f.t -linemap 1 \
		-bg black -fg white -insertbackground yellow \
		-yscrollcommand ".f.s set"] -fill both -expand 1

	highlight:addClasses .f.t
	ctext::enableComments .f.t

	set fi [open test.c r]
	.f.t fastinsert end [read $fi]
	close $fi
	
	pack [button .append -text Append -command {.f.t append}] -side left
	pack [button .cut -text Cut -command {.f.t cut}] -side left
	pack [button .copy -text Copy -command {.f.t copy}] -side left
	pack [button .paste -text Paste -command {.f.t paste}] -side left
	.f.t highlight 1.0 end
	pack [button .test -text {Remove all Tags and Highlight} \
		-command {puts [time {
			foreach tag [.f.t tag names] {
				.f.t tag remove $tag 1.0 end
			}
			update idletasks
			.f.t highlight 1.0 end
			}]
		}
	] -side left
	pack [button .test2 -text {Scrollbar Command {}} -command {.f.t config -yscrollcommand {}}] -side left
	pack [button .cl -text {Clear Classes} \
		-command {ctext::clearHighlightClasses .f.t}] -side left
	pack [button .exit -text Exit -command exit] -side left
	#pack [ctext .ct2 -linemap 1] -side bottom	

	#update
	#console show
	#puts [.f.t cget -linemap]
	#puts [.f.t cget -bg]
}
main