TKE  3.6
Advanced code editor for programmers
indent Namespace Reference

Functions

 handle_spaces_per_tab name1 name2 op
 
 handle_indent_spaces name1 name2 op
 
 add_bindings txt
 
 set_tabstop txtt value
 
 get_tabstop txtt
 
 set_shiftwidth txtt value
 
 get_shiftwidth txtt
 
 set_current_indent_mode mode
 
 set_indent_mode txt mode
 
 get_indent_mode txt
 
 is_auto_indent_available txt
 
 check_reindent_for_unindent txtt index
 
 check_indent txtt index do_update
 
 line_contains_indentation txtt index
 
 get_match_indent txtt index
 
 get_start_of_line txtt index
 
 newline txtt index do_update
 
 backspace txtt index do_update
 
 get_previous_indent_space txtt index
 
 get_tag_count txtt tag start end
 
 format_text txtt startpos endpos ?add_separator?
 
 set_indent_expressions txtt indent unindent reindent
 
 update_auto_indent txtt w
 
 populate_indent_menu mnu
 
 create_menu w
 
 update_button w
 

Function Documentation

§ add_bindings()

indent::add_bindings   txt  

Definition at line 80 of file indent.tcl.

80  proc add_bindings {txt} {
81 
82  # Initialize the tabstop
83  set_tabstop $txt.t [preferences::get Editor/SpacesPerTab]
84  set_shiftwidth $txt.t [preferences::get Editor/IndentSpaces]
85 
86  bind indent$txt <Any-Key> { indent::check_indent %W insert 1 }
87  bind indent$txt <Return> { indent::newline %W insert 1 }
88  bind indent$txt <BackSpace> { indent::backspace %W insert 1 }
89 
90  # Add the indentation tag into the bindtags list just after Text
91  set text_index [lsearch [bindtags $txt.t] Text]
92  bindtags $txt.t [linsert [bindtags $txt.t] [expr $text_index + 1] indent$txt]
93 
94  }

§ backspace()

indent::backspace   txtt index do_update  

Definition at line 523 of file indent.tcl.

523  proc backspace {txtt index do_update} {
524 
525  variable data
526 
527  # If the auto-indent feature was disabled, we are in vim start mode, or
528  # the current language doesn't have an indent expression, quit now
529  if {($data($txtt,mode) eq "OFF") || [vim::in_vim_mode $txtt]} {
530  return $index
531  }
532 
533  # Figure out the leading space
534  set space ""
535  if {[set endpos [lassign [$txtt tag prevrange __prewhite $index "$index linestart"] startpos]] ne ""} {
536  if {[$txtt compare $endpos == "$index+1c"]} {
537  set space [$txtt get $startpos $index]
538  } else {
539  return $index
540  }
541  } else {
542  set space [$txtt get "$index linestart" "$index lineend"]
543  }
544 
545  # If the leading whitespace only consists of spaces, attempt to delete to the previous tab
546  if {([string map {{ } {}} $space] eq "")} {
547 
548  # Calculate the new indentation
549  set shiftwidth [get_shiftwidth $txtt]
550  set tab_count [expr [string length $space] / $shiftwidth]
551  set indent_space [string repeat " " [expr $tab_count * $shiftwidth]]
552 
553  # Replace the whitespace with the appropriate amount of indentation space
554  if {$indent_space ne $space} {
555  $txtt fastreplace -update $do_update "$index linestart" $index $indent_space
556  set offset [string length $indent_space]
557  return [$txtt index "$index linestart+${offset}c"]
558  }
559 
560  }
561 
562  return $index
563 
564  }

§ check_indent()

indent::check_indent   txtt index do_update  

Definition at line 249 of file indent.tcl.

249  proc check_indent {txtt index do_update} {
250 
251  variable data
252 
253  # If the auto-indent feature was disabled, we are in vim start mode, or
254  # the current language doesn't have an indent expression, quit now
255  if {($data($txtt,mode) ne "IND+") || [vim::in_vim_mode $txtt]} {
256  return $index
257  }
258 
259  # If the current line contains an unindent expression, is not within a comment or string,
260  # and is preceded in the line by only whitespace, replace the whitespace with the proper
261  # indentation whitespace.
262  if {([set endpos [lassign [$txtt tag prevrange __unindent $index] startpos]] ne "") && [$txtt compare $endpos >= $index]} {
263 
264  if {[string trim [set space [$txtt get "$index linestart" $startpos]]] eq ""} {
265 
266  # Find the matching indentation index
267  if {[set tindex [get_match_indent $txtt $startpos]] ne ""} {
268  set indent_space [get_start_of_line $txtt $tindex]
269  } else {
270  set indent_space [get_start_of_line $txtt $index]
271  }
272 
273  # Replace the whitespace with the appropriate amount of indentation space
274  if {$indent_space ne $space} {
275  $txtt fastreplace -update $do_update "$index linestart" $startpos $indent_space
276  set offset [expr [lindex [split $index .] 1] + ([string length $indent_space] - [lindex [split $startpos .] 1])]
277  return [$txtt index "$index linestart+${offset}c"]
278  }
279 
280  }
281 
282  } elseif {(([set endpos [lassign [$txtt tag prevrange __reindent $index] startpos]] ne "") && [$txtt compare $endpos == $index]) && [set type [check_reindent_for_unindent $txtt $startpos]]} {
283 
284  if {[string trim [set space [$txtt get "$index linestart" $startpos]]] eq ""} {
285 
286  if {$type == 1} {
287 
288  # Get the starting whitespace of the previous line
289  set indent_space [get_start_of_line $txtt [$txtt index "$index-1l lineend"]]
290 
291  # Check to see if the previous line contained a reindent
292  if {[$txtt compare "$index-1l linestart" > [lindex [$txtt tag prevrange __reindent "$index linestart"] 0]]} {
293  set indent_space [string range $indent_space [get_shiftwidth $txtt] end]
294  }
295 
296  } else {
297 
298  # Set the indentation space to the same as the reindentStart line
299  set indent_space [get_start_of_line $txtt [lindex [$txtt tag prevrange __reindentStart $index] 0]]
300 
301  }
302 
303  # Replace the whitespace with the appropriate amount of indentation space
304  if {$indent_space ne $space} {
305  $txtt fastreplace -update $do_update "$index linestart" $startpos $indent_space
306  set offset [expr [lindex [split $index .] 1] + ([string length $indent_space] - [lindex [split $startpos .] 1])]
307  return [$txtt index "$index linestart+${offset}c"]
308  }
309 
310  }
311 
312  }
313 
314  return $index
315 
316  }

§ check_reindent_for_unindent()

indent::check_reindent_for_unindent   txtt index  

Definition at line 216 of file indent.tcl.

216  proc check_reindent_for_unindent {txtt index} {
217 
218  if {[set spos [lindex [$txtt tag prevrange __reindentStart $index] 0]] ne ""} {
219 
220  # If the starting reindent is also an indent, return 1
221  if {[lsearch [$txtt tag names $spos] __indent*] != -1} {
222  return 2
223  }
224 
225  # Get the starting position of the previous reindent string
226  set rpos [lindex [$txtt tag prevrange __reindent $index] 0]
227 
228  if {($rpos ne "") && [$txtt compare $rpos > $spos]} {
229 
230  # Find the indent symbol that is just before the reindentStart symbol
231  while {([lassign [$txtt tag prevrange __indent $index] ipos] ne "") && [$txtt compare $ipos > $spos]} {
232  set index $ipos
233  }
234 
235  return [$txtt compare $index < $rpos]
236 
237  }
238 
239  }
240 
241  return 0
242 
243  }

§ create_menu()

indent::create_menu   w  

Definition at line 758 of file indent.tcl.

758  proc create_menu {w} {
759 
760  # Create the menubutton menu
761  set mnu [menu ${w}Menu -tearoff 0]
762 
763  # Populate the indent menu
765 
766  # Register the menu
767  theme::register_widget $mnu menus
768 
769  return $mnu
770 
771  }

§ format_text()

indent::format_text   txtt startpos endpos ?add_separator?  

Definition at line 608 of file indent.tcl.

608  proc format_text {txtt startpos endpos {add_separator 1}} {
609 
610  variable data
611 
612  # Create a separator
613  if {$add_separator} {
614  $txtt edit separator
615  }
616 
617  # If we are the first line containing non-whitespace, preserve the indentation
618  if {([$txtt tag prevrange __prewhite "$startpos linestart"] eq "") || \
619  ([string trim [$txtt get "$startpos linestart" $startpos]] ne "")} {
620  set curpos [$txtt index "$startpos+1l linestart"]
621  } else {
622  set curpos [$txtt index "$startpos linestart"]
623  }
624 
625  set endpos [$txtt index $endpos]
626  set indent_space ""
627  set shiftwidth [get_shiftwidth $txtt]
628 
629  while {[$txtt compare $curpos < $endpos]} {
630 
631  if {$curpos ne "1.0"} {
632 
633  # If the current line contains an unindent expression, is not within a comment or string,
634  # and is preceded in the line by only whitespace, replace the whitespace with the proper
635  # indentation whitespace.
636  if {[set epos [lassign [$txtt tag nextrange __unindent $curpos "$curpos lineend"] spos]] ne ""} {
637  if {[set tindex [get_match_indent $txtt $spos]] ne ""} {
638  if {[$txtt compare "$tindex linestart" == "$spos linestart"]} {
639  set indent_space [get_start_of_line $txtt "$tindex-1l lineend"]
640  if {[line_contains_indentation $txtt "$tindex-1l lineend"]} {
641  append indent_space [string repeat " " $shiftwidth]
642  }
643  } else {
644  set indent_space [get_start_of_line $txtt $tindex]
645  }
646  } else {
647  set indent_space [get_start_of_line $txtt $epos]
648  }
649 
650  } elseif {([set epos [lassign [$txtt tag nextrange __reindent $curpos "$curpos lineend"] spos]] ne "") && [check_reindent_for_unindent $txtt $spos]} {
651  set indent_space [get_start_of_line $txtt [$txtt index "$curpos-1l lineend"]]
652  if {[string trim [$txtt get "$curpos linestart" $spos]] eq ""} {
653  if {[$txtt compare "$curpos-1l linestart" > [lindex [$txtt tag prevrange __reindent "$curpos linestart"] 1]]} {
654  set indent_space [string range $indent_space $shiftwidth end]
655  }
656  }
657 
658  } else {
659  set indent_space [get_start_of_line $txtt [$txtt index "$curpos-1l lineend"]]
660  if {[line_contains_indentation $txtt "$curpos-1l lineend"]} {
661  append indent_space [string repeat " " $shiftwidth]
662  }
663  }
664 
665  }
666 
667  # Remove any leading whitespace and update indentation level
668  # (if the first non-whitespace char is a closing bracket)
669  set whitespace ""
670  if {[lsearch [$txtt tag names $curpos] __prewhite] != -1} {
671  set whitespace [string range [$txtt get {*}[$txtt tag nextrange __prewhite $curpos]] 0 end-1]
672  }
673 
674  # Replace the leading whitespace with the calculated amount of indentation space
675  if {$whitespace ne $indent_space} {
676  $txtt replace $curpos "$curpos+[string length $whitespace]c" $indent_space
677  }
678 
679  # Adjust the startpos
680  set curpos [$txtt index "$curpos+1l linestart"]
681 
682  }
683 
684  # Create a separator
685  $txtt edit separator
686 
687  # Perform syntax highlighting
688  $txtt syntax highlight $startpos $endpos
689 
690  }

§ get_indent_mode()

indent::get_indent_mode   txt  

Definition at line 192 of file indent.tcl.

192  proc get_indent_mode {txt} {
193 
194  variable data
195 
196  if {![info exists data($txt.t,mode)]} {
197  return "OFF"
198  } else {
199  return [lindex $data($txt.t,mode) 0]
200  }
201 
202  }

§ get_match_indent()

indent::get_match_indent   txtt index  

Definition at line 343 of file indent.tcl.

343  proc get_match_indent {txtt index} {
344 
345  set count 1
346 
347  lassign [$txtt tag prevrange __indent $index] sfirst slast
348  lassign [$txtt tag prevrange __unindent $index] ofirst olast
349 
350  if {($olast ne "") && [$txtt compare $olast >= $index]} {
351  set olast $index
352  }
353 
354  while {($ofirst ne "") && ($sfirst ne "")} {
355  if {[$txtt compare $sfirst > $ofirst]} {
356  if {[incr count -1] == 0} {
357  return $sfirst
358  }
359  lassign [$txtt tag prevrange __indent $sfirst] sfirst slast
360  } else {
361  incr count
362  lassign [$txtt tag prevrange __unindent $ofirst] ofirst olast
363  }
364  }
365 
366  while {$sfirst ne ""} {
367  if {[incr count -1] == 0} {
368  return $sfirst
369  }
370  lassign [$txtt tag prevrange __indent $sfirst] sfirst slast
371  }
372 
373  return ""
374 
375  }

§ get_previous_indent_space()

indent::get_previous_indent_space   txtt index  

Definition at line 568 of file indent.tcl.

568  proc get_previous_indent_space {txtt index} {
569 
570  variable data
571 
572  if {($data($txtt,mode) eq "OFF") || \
573  [vim::in_vim_mode $txtt] || \
574  ([lindex [split $index .] 0] == 1)} {
575  return 0
576  }
577 
578  if {[set range [$txtt tag prevrange __prewhite "$index-1l lineend"]] ne ""} {
579  return [string range [$txtt get {*}$range] 0 end-1]
580  } else {
581  return ""
582  }
583 
584  }

§ get_shiftwidth()

indent::get_shiftwidth   txtt  

Definition at line 147 of file indent.tcl.

147  proc get_shiftwidth {txtt} {
148 
149  variable shiftwidths
150 
151  if {[info exists shiftwidths($txtt)]} {
152  return $shiftwidths($txtt)
153  }
154 
155  return -code error "Shiftwidth information for $txtt does not exist"
156 
157  }

§ get_start_of_line()

indent::get_start_of_line   txtt index  

Definition at line 380 of file indent.tcl.

380  proc get_start_of_line {txtt index} {
381 
382  # Ignore whitespace
383  if {[lsearch [$txtt tag names "$index linestart"] __prewhite] == -1} {
384  if {[set range [$txtt tag prevrange __prewhite "$index lineend"]] ne ""} {
385  set index [$txtt index "[lindex $range 1] lineend"]
386  } else {
387  set index 1.0
388  }
389  }
390 
391  # Find an ending bracket on the current line
392  set win_type "none"
393  set startpos(none) "$index linestart"
394  foreach type [list curlyR parenR squareR angledR] {
395  if {([lassign [$txtt tag prevrange __$type $index] startpos($type)] ne "") && \
396  [$txtt compare $startpos($type) >= "$index linestart"] && \
397  [$txtt compare $startpos($type) >= $startpos($win_type)]} {
398  set win_type $type
399  }
400  }
401 
402  # If we could not find a right bracket, we have found the line that we are looking for
403  if {$win_type eq "none"} {
404  if {[lsearch [$txtt tag names "$index linestart"] __prewhite] != -1} {
405  return [string range [$txtt get {*}[$txtt tag nextrange __prewhite "$index linestart"]] 0 end-1]
406  } else {
407  return ""
408  }
409 
410  # Otherwise, jump the insertion cursor to the line containing the matching bracket and
411  # do the search again.
412  } else {
413  array set other_type [list curlyR curlyL parenR parenL squareR squareL angledR angledL]
414  if {[set match_index [ctext::getMatchBracket [winfo parent $txtt] $other_type($win_type) $startpos($win_type)]] ne ""} {
415  return [get_start_of_line $txtt $match_index]
416  } elseif {[lsearch [$txtt tag names "$index linestart"] __prewhite] != -1} {
417  return [string range [$txtt get {*}[$txtt tag nextrange __prewhite "$index linestart"]] 0 end-1]
418  } else {
419  return ""
420  }
421  }
422 
423  }

§ get_tabstop()

indent::get_tabstop   txtt  

Definition at line 117 of file indent.tcl.

117  proc get_tabstop {txtt} {
118 
119  variable tabstops
120 
121  if {[info exists tabstops($txtt)]} {
122  return $tabstops($txtt)
123  }
124 
125  return -code error "Tabstop information for $txtt does not exist"
126 
127  }

§ get_tag_count()

indent::get_tag_count   txtt tag start end  

Definition at line 588 of file indent.tcl.

588  proc get_tag_count {txtt tag start end} {
589 
590  variable data
591 
592  # Initialize the indent_level
593  set count 0
594 
595  # Count all tags that are not within comments or are escaped
596  while {[set range [$txtt tag nextrange __$tag $start $end]] ne ""} {
597  incr count
598  set start [lindex $range 1]
599  }
600 
601  return $count
602 
603  }

§ handle_indent_spaces()

indent::handle_indent_spaces   name1 name2 op  

Definition at line 64 of file indent.tcl.

64  proc handle_indent_spaces {name1 name2 op} {
65 
66  variable shiftwidths
67 
68  foreach txtt [array names shiftwidths] {
69  if {[winfo exists $txtt]} {
70  set_shiftwidth $txtt [preferences::get Editor/IndentSpaces]
71  } else {
72  unset shiftwidths($txtt)
73  }
74  }
75 
76  }

§ handle_spaces_per_tab()

indent::handle_spaces_per_tab   name1 name2 op  

Definition at line 46 of file indent.tcl.

46  proc handle_spaces_per_tab {name1 name2 op} {
47 
48  variable tabstops
49 
50  foreach txtt [array names tabstops] {
51  if {[winfo exists $txtt]} {
52  set_tabstop $txtt [preferences::get Editor/SpacesPerTab]
53  } else {
54  unset tabstops($txtt)
55  }
56  }
57 
58  }

§ is_auto_indent_available()

indent::is_auto_indent_available   txt  

Definition at line 206 of file indent.tcl.

206  proc is_auto_indent_available {txt} {
207 
208  variable data
209 
210  return $data($txt.t,auto,avail)
211 
212  }

§ line_contains_indentation()

indent::line_contains_indentation   txtt index  

Definition at line 320 of file indent.tcl.

320  proc line_contains_indentation {txtt index} {
321 
322  # Ignore whitespace
323  if {[lsearch [$txtt tag names "$index linestart"] __prewhite] == -1} {
324  if {[set range [$txtt tag prevrange __prewhite "$index lineend"]] ne ""} {
325  set index [$txtt index "[lindex $range 1] lineend"]
326  } else {
327  set index 1.0
328  }
329  }
330 
331  # Check to see if the current line contains an indentation symbol towards the end of the line
332  if {[lassign [$txtt tag prevrange __indent $index "$index linestart"] ipos] ne ""} {
333  return [expr {([lassign [$txtt tag prevrange __unindent $index] upos] eq "") || [$txtt compare $ipos > $upos]}]
334  }
335 
336  # Returns true if we have a reindent symbol in the current line
337  return [expr {[lassign [$txtt tag prevrange __reindent $index "$index linestart"] ipos] ne ""}]
338 
339  }

§ newline()

indent::newline   txtt index do_update  

Definition at line 428 of file indent.tcl.

428  proc newline {txtt index do_update} {
429 
430  variable data
431 
432  # If the auto-indent feature was disabled, we are in vim start mode,
433  # or the current language doesn't have an indent expression, quit now
434  if {($data($txtt,mode) eq "OFF") || [vim::in_vim_mode $txtt]} {
435  if {[$txtt cget -autoseparators]} {
436  $txtt edit separator
437  }
438  return $index
439  }
440 
441  # If we do not need smart indentation, use the previous space
442  if {$data($txtt,mode) eq "IND"} {
443 
444  set indent_space [get_previous_indent_space $txtt $index]
445 
446  # Otherwise, do smart indentation
447  } else {
448 
449  # Get the current indentation level
450  set indent_space [get_start_of_line $txtt [$txtt index "$index-1l lineend"]]
451 
452  # If the previous line indicates an indentation is required,
453  if {[line_contains_indentation $txtt "$index-1l lineend"]} {
454  append indent_space [string repeat " " [get_shiftwidth $txtt]]
455  }
456 
457  }
458 
459  # Create an index to restore the insertion cursor, if necessary
460  set restore_insert ""
461 
462  # Remove any leading whitespace and update indentation level
463  # (if the first non-whitespace char is a closing bracket)
464  if {[lsearch [$txtt tag names "$index linestart"] __prewhite] != -1} {
465 
466  lassign [$txtt tag nextrange __prewhite "$index linestart"] startpos endpos
467 
468  # If the first non-whitespace characters match an unindent pattern,
469  # lessen the indentation by one
470  if {[lsearch [$txtt tag names "$endpos-1c"] __unindent*] != -1} {
471  $txtt fastinsert -update 0 insert "$indent_space\n"
472  set startpos [$txtt index $startpos+1l]
473  set endpos [$txtt index $endpos+1l]
474  set restore_insert [$txtt index insert-1c]
475  if {$data($txtt,mode) eq "IND+"} {
476  set indent_space [string range $indent_space [get_shiftwidth $txtt] end]
477  }
478 
479  # Otherwise, if the first non-whitepace characters match a reindent pattern, lessen the
480  # indentation by one
481  } elseif {([lsearch [$txtt tag names "$endpos-1c"] __reindent*] != -1) && [check_reindent_for_unindent $txtt [lindex [$txtt tag prevrange __reindent $endpos] 0]]} {
482  # $txtt insert insert "$indent_space\n"
483  # set restore_insert [$txtt index insert-1c]
484  if {$data($txtt,mode) eq "IND+"} {
485  set indent_space [string range $indent_space [get_shiftwidth $txtt] end]
486  }
487  }
488 
489  # See if we are deleting a multicursor
490  set mcursor [lsearch [$txtt tag names $index] "mcursor"]
491 
492  # Delete the whitespace
493  $txtt fastdelete -update [expr {($do_update && ($indent_space eq "")) ? 1 : 0}] $startpos "$endpos-1c"
494 
495  # If the newline was from a multicursor, we need to re-add the tag since we have deleted it
496  if {$mcursor != -1} {
497  $txtt tag add mcursor $index
498  }
499 
500  }
501 
502  # Insert leading whitespace to match current indentation level
503  if {$indent_space ne ""} {
504  $txtt fastinsert -update $do_update "$index linestart" $indent_space
505  }
506 
507  # If we need to restore the insertion cursor, do it now
508  if {$restore_insert ne ""} {
509  ::tk::TextSetCursor $txtt $restore_insert
510  }
511 
512  # If autoseparators are called for, add it now
513  if {[$txtt cget -autoseparators]} {
514  $txtt edit separator
515  }
516 
517  return [$txtt index "$index+[string length $indent_space]c"]
518 
519  }

§ populate_indent_menu()

indent::populate_indent_menu   mnu  

Definition at line 738 of file indent.tcl.

738  proc populate_indent_menu {mnu} {
739 
740  variable langs
741 
742  # Clear the menu
743  $mnu delete 0 end
744 
745  # Populate the menu with the available languages
746  foreach {lbl mode} [list [msgcat::mc "No Indent"] "OFF" [msgcat::mc "Auto-Indent"] "IND" [msgcat::mc "Smart Indent"] "IND+"] {
747  $mnu add radiobutton -label $lbl -variable indent::current_indent \
748  -value $mode -command [list indent::set_current_indent_mode $mode]
749  }
750 
751  return $mnu
752 
753  }

§ set_current_indent_mode()

indent::set_current_indent_mode   mode  

Definition at line 161 of file indent.tcl.

161  proc set_current_indent_mode {mode} {
162 
164 
165  }

§ set_indent_expressions()

indent::set_indent_expressions   txtt indent unindent reindent  

Definition at line 694 of file indent.tcl.

694  proc set_indent_expressions {txtt indent unindent reindent} {
695 
696  variable data
697 
698  # Update the auto-indent settings
699  set data($txtt,auto,avail) [expr {$indent ne ""}]
700  set data($txtt,auto,enable) 1
701 
702  # Set the default indentation mode
703  if {[preferences::get Editor/EnableAutoIndent]} {
704  if {($indent ne "") && [$txtt cget -highlight]} {
705  set data($txtt,mode) "IND+"
706  } else {
707  set data($txtt,mode) "IND"
708  }
709  } else {
710  set data($txtt,mode) "OFF"
711  }
712 
713  }

§ set_indent_mode()

indent::set_indent_mode   txt mode  

Definition at line 169 of file indent.tcl.

169  proc set_indent_mode {txt mode} {
170 
171  variable data
172  variable indent_mode_map
173  variable current_indent
174 
175  # Set the current mode
176  set data($txt.t,mode) $indent_mode_map($mode)
177  set current_indent $indent_mode_map($mode)
178 
179  # Set the text widget's indent mode
180  folding::add_folds $txt 1.0 end
181 
182  # Update the menu button
183  $gui::widgets(info_indent) configure -text $mode
184 
185  # Set the focus back to the text widget
187 
188  }

§ set_shiftwidth()

indent::set_shiftwidth   txtt value  

Definition at line 131 of file indent.tcl.

131  proc set_shiftwidth {txtt value} {
132 
133  variable shiftwidths
134 
135  # Check to make sure that the value is an integer
136  if {![string is integer $value]} {
137  return -code error "Shiftwidth value is not an integer"
138  }
139 
140  # Save the shiftwidth value
141  set shiftwidths($txtt) $value
142 
143  }

§ set_tabstop()

indent::set_tabstop   txtt value  

Definition at line 98 of file indent.tcl.

98  proc set_tabstop {txtt value} {
99 
100  variable tabstops
101 
102  # Check to make sure that the value is an integer
103  if {![string is integer $value]} {
104  return -code error "Tabstop value is not an integer"
105  }
106 
107  # Save the tabstop value
108  set tabstops($txtt) $value
109 
110  # Set the text widget tabstop value
111  $txtt configure -tabs [list [expr $value * [font measure [$txtt cget -font] 0]] left]
112 
113  }

§ update_auto_indent()

indent::update_auto_indent   txtt w  

Definition at line 718 of file indent.tcl.

718  proc update_auto_indent {txtt w} {
719 
720  variable data
721  variable current_indent
722 
723  set data($txtt,auto,enable) [expr [$txtt cget -highlight] && $data($txtt,auto,avail)]
724  set state [expr {$data($txtt,auto,enable) ? "normal" : "disabled"}]
725 
726  if {!$data($txtt,auto,enable) && ($data($txtt,mode) eq "IND+")} {
727  set data($txtt,mode) "IND"
728  }
729 
730  set current_indent $data($txtt,mode)
731 
732  ${w}Menu entryconfigure [msgcat::mc "Smart Indent"] -state $state
733 
734  }

§ update_button()

indent::update_button   w  

Definition at line 775 of file indent.tcl.

775  proc update_button {w} {
776 
777  variable data
778  variable current_indent
779 
780  # Get the current text widget
781  set txtt [gui::current_txt].t
782 
783  # Configure the menubutton
784  if {[info exists data($txtt,mode)]} {
785  $w configure -text [set current_indent $data($txtt,mode)]
786  }
787 
788  # Update the selectable state of the button
789  ${w}Menu entryconfigure [msgcat::mc "Smart Indent"] -state [expr {[$txtt cget -highlight] ? "normal" : "disabled"}]
790 
791  }