TKE  3.6
Advanced code editor for programmers
edit Namespace Reference

Functions

 insert_line_above_current txtt
 
 insert_line_below_current txtt
 
 insert_file txt fname
 
 delete_selected txtt line
 
 delete_current_line txtt copy ?num?
 
 delete txtt startpos endpos copy adjust
 
 delete_to_end txtt copy ?num?
 
 delete_from_start txtt copy
 
 delete_to_firstchar txtt copy
 
 delete_next_numbers txtt copy
 
 delete_prev_numbers txtt copy
 
 delete_next_space txtt
 
 delete_prev_space txtt
 
 delete_to_next_char txtt char copy ?num? ?exclusive?
 
 delete_to_prev_char txtt char copy ?num? ?exclusive?
 
 get_char_positions txtt char
 
 delete_between_char txtt char copy
 
 convert_case_toggle txtt startpos endpos
 
 convert_case_to_title txtt startpos endpos
 
 convert_to_lower_case txtt startpos endpos
 
 convert_to_upper_case txtt startpos endpos
 
 convert_to_rot13 txtt startpos endpos
 
 transform_toggle_case_selected txtt
 
 transform_toggle_case txtt startpos endpos ?cursorpos?
 
 transform_to_lower_case_selected txtt
 
 transform_to_lower_case txtt startpos endpos ?cursorpos?
 
 transform_to_upper_case_selected txtt
 
 transform_to_upper_case txtt startpos endpos ?cursorpos?
 
 transform_to_rot13_selected txtt
 
 transform_to_rot13 txtt startpos endpos ?cursorpos?
 
 transform_to_title_case txtt startpos endpos ?cursorpos?
 
 transform_join_lines txtt ?num?
 
 newline_count str
 
 transform_bubble_up txtt
 
 transform_bubble_down txtt
 
 save_selection txt from to overwrite fname
 
 comment_text txt
 
 comment
 
 uncomment_text txt
 
 uncomment
 
 comment_toggle_text txt
 
 comment_toggle
 
 do_uncomment txt startpos endpos
 
 do_indent txtt startpos endpos
 
 do_unindent txtt startpos endpos
 
 indent_selected txtt
 
 indent txtt ?startpos? ?endpos?
 
 unindent_selected txtt
 
 unindent txtt ?startpos? ?endpos?
 
 replace_line_with_script
 
 current_line_empty
 
 align_cursors
 
 align_cursors_and_text
 
 insert_enumeration
 
 jump_to_line txt linenum
 
 get_char txt dir ?num? ?start?
 
 get_wordstart txt dir ?num? ?start? ?exclusive?
 
 get_wordend txt dir ?num? ?start? ?exclusive?
 
 get_WORDstart txtt dir ?num? ?start? ?exclusive?
 
 get_WORDend txtt dir ?num? ?start? ?exclusive?
 
 find_char txtt dir char num startpos exclusive
 
 between_char txtt dir char ?startpos?
 
 get_sentence txtt dir num ?startpos?
 
 get_paragraph txtt dir num ?start?
 
 get_index txtt position args
 
 get_range_word txtt type num inner adjust ?cursor?
 
 get_range_WORD txtt num inner adjust ?cursor?
 
 get_range_sentences txtt type num inner adjust ?cursor?
 
 get_range_block txtt type num inner adjust ?cursor?
 
 get_range_string txtt char tag inner adjust ?cursor?
 
 get_range txtt pos1args pos2args object move ?cursor?
 
 move_cursor txtt position args
 
 move_cursor_by_page txtt dir
 
 move_cursors txtt modifier
 
 format txtt type
 
 unformat txtt
 

Function Documentation

§ align_cursors()

edit::align_cursors

Definition at line 1261 of file edit.tcl.

1261  proc align_cursors {} {
1262 
1263  # Get the current text widget
1264  set txt [gui::current_txt]
1265 
1266  # Align multicursors only
1267  multicursor::align $txt
1268 
1269  }

§ align_cursors_and_text()

edit::align_cursors_and_text

Definition at line 1274 of file edit.tcl.

1274  proc align_cursors_and_text {} {
1275 
1276  # Get the current text widget
1277  set txt [gui::current_txt]
1278 
1279  # Align multicursors
1281 
1282  }

§ between_char()

edit::between_char   txtt dir char ?startpos?  

Definition at line 1590 of file edit.tcl.

1590  proc between_char {txtt dir char {startpos "insert"}} {
1591 
1592  array set pairs {
1593  \{ {\\\} L}
1594  \} {\\\{ R}
1595  \( {\\\) L}
1596  \) {\\\( R}
1597  \[ {\\\] L}
1598  \] {\\\[ R}
1599  < {> L}
1600  > {< R}
1601  }
1602 
1603  # Get the matching character
1604  if {[info exists pairs($char)]} {
1605  if {[lindex $pairs($char) 1] eq "R"} {
1606  if {$dir eq "prev"} {
1607  set index [gui::find_match_pair $txtt [lindex $pairs($char) 0] \\$char -backwards]
1608  } else {
1609  set index [gui::find_match_pair $txtt \\$char [lindex $pairs($char) 0] -forwards]
1610  }
1611  } else {
1612  if {$dir eq "prev"} {
1613  set index [gui::find_match_pair $txtt \\$char [lindex $pairs($char) 0] -backwards]
1614  } else {
1615  set index [gui::find_match_pair $txtt [lindex $pairs($char) 0] \\$char -forwards]
1616  }
1617  }
1618  } else {
1619  if {$dir eq "prev"} {
1620  set index [gui::find_match_char $txtt $char -backwards]
1621  } else {
1622  set index [gui::find_match_char $txtt $char -forwards]
1623  }
1624  }
1625 
1626  if {$index == -1} {
1627  return [expr {($dir eq "prev") ? 1.0 : "end-1c"}]
1628  } else {
1629  return [expr {($dir eq "prev") ? "$index+1c" : $index}]
1630  }
1631 
1632  }

§ comment()

edit::comment

Definition at line 982 of file edit.tcl.

982  proc comment {} {
983 
984  # Get the current text widget
986 
987  }

§ comment_text()

edit::comment_text   txt  

Definition at line 939 of file edit.tcl.

939  proc comment_text {txt} {
940 
941  # Create a separator
942  $txt edit separator
943 
944  # Get the selection ranges
945  set selected [$txt tag ranges sel]
946 
947  # Get the comment syntax
948  lassign [syntax::get_comments $txt] icomment lcomments bcomments
949 
950  # Insert comment lines/blocks
951  foreach {endpos startpos} [lreverse $selected] {
952  if {[llength $icomment] == 1} {
953  set i 0
954  foreach line [split [$txt get $startpos $endpos] \n] {
955  if {$i == 0} {
956  $txt insert $startpos "[lindex $icomment 0]"
957  $txt tag add sel $startpos "$startpos lineend"
958  } else {
959  $txt insert "$startpos+${i}l linestart" "[lindex $icomment 0]"
960  }
961  incr i
962  }
963  } else {
964  $txt insert $endpos "[lindex $icomment 1]"
965  $txt insert $startpos "[lindex $icomment 0]"
966  if {[lindex [split $startpos .] 0] == [lindex [split $endpos .] 0]} {
967  set endpos "$endpos+[expr [string length [lindex $icomment 0]] + [string length [lindex $icomment 1]]]c"
968  } else {
969  set endpos "$endpos+[string length [lindex $icomment 1]]c"
970  }
971  $txt tag add sel $startpos $endpos
972  }
973  }
974 
975  # Create a separator
976  $txt edit separator
977 
978  }

§ comment_toggle()

edit::comment_toggle

Definition at line 1104 of file edit.tcl.

1104  proc comment_toggle {} {
1105 
1106  # Get the current text widget
1108 
1109  }

§ comment_toggle_text()

edit::comment_toggle_text   txt  

Definition at line 1037 of file edit.tcl.

1037  proc comment_toggle_text {txt} {
1038 
1039  # Create a separator
1040  $txt edit separator
1041 
1042  # Get various comments
1043  lassign [syntax::get_comments $txt] icomment lcomments bcomments
1044 
1045  # Get the current selection
1046  set selected 1
1047  if {[llength [set ranges [$txt tag ranges sel]]] == 0} {
1048  if {[llength [set mcursors [$txt tag ranges mcursor]]] > 0} {
1049  foreach {startpos endpos} $mcursors {
1050  lappend ranges [$txt index "$startpos linestart"] [$txt index "$startpos lineend"]
1051  }
1052  } elseif {[lsearch [$txt tag names insert] __cComment] != -1} {
1053  lassign [$txt tag prevrange __cComment insert] startpos endpos
1054  if {[regexp "^[lindex $bcomments 0 0](.*)[lindex $bcomments 0 1]\$" [$txt get $startpos $endpos] -> str]} {
1055  $txt replace $startpos $endpos $str
1056  $txt edit separator
1057  }
1058  return
1059  } else {
1060  set ranges [list [$txt index "insert linestart"] [$txt index "insert lineend"]]
1061  }
1062  set selected 0
1063  }
1064 
1065  # Iterate through each range
1066  foreach {endpos startpos} [lreverse $ranges] {
1067  if {![do_uncomment $txt $startpos $endpos]} {
1068  if {[llength $icomment] == 1} {
1069  set i 0
1070  foreach line [split [$txt get $startpos $endpos] \n] {
1071  if {$i == 0} {
1072  $txt insert $startpos "[lindex $icomment 0]"
1073  if {$selected} {
1074  $txt tag add sel $startpos "$startpos lineend"
1075  }
1076  } else {
1077  $txt insert "$startpos+${i}l linestart" "[lindex $icomment 0]"
1078  }
1079  incr i
1080  }
1081  } else {
1082  $txt insert $endpos "[lindex $icomment 1]"
1083  $txt insert $startpos "[lindex $icomment 0]"
1084  if {$selected} {
1085  if {[lindex [split $startpos .] 0] == [lindex [split $endpos .] 0]} {
1086  set endpos "$endpos+[expr [string length [lindex $icomment 0]] + [string length [lindex $icomment 1]]]c"
1087  } else {
1088  set endpos "$endpos+[string length [lindex $icomment 1]]c"
1089  }
1090  $txt tag add sel $startpos $endpos
1091  }
1092  }
1093  }
1094  }
1095 
1096  # Create a separator
1097  $txt edit separator
1098 
1099  }

§ convert_case_to_title()

edit::convert_case_to_title   txtt startpos endpos  

Definition at line 493 of file edit.tcl.

493  proc convert_case_to_title {txtt startpos endpos} {
494 
495  set i 0
496  foreach index [$txtt search -all -count lengths -regexp -- {\w+} $startpos $endpos] {
497  set endpos [$txtt index "$index+[lindex $lengths $i]c"]
498  set word [$txtt get $index $endpos]
499  $txtt replace $index $endpos [string totitle $word]
500  incr i
501  }
502 
503  # Set the cursor
504  ::tk::TextSetCursor $txtt $startpos
505 
506  }

§ convert_case_toggle()

edit::convert_case_toggle   txtt startpos endpos  

Definition at line 469 of file edit.tcl.

469  proc convert_case_toggle {txtt startpos endpos} {
470 
471  # Get the string
472  set str [$txtt get $startpos $endpos]
473 
474  # Adjust the string so that we don't add an extra new line
475  if {[string index $str end] eq "\n"} {
476  set str [string range $str 0 end-1]
477  }
478 
479  set strlen [string length $str]
480  set newstr ""
481 
482  for {set i 0} {$i < $strlen} {incr i} {
483  set char [string index $str $i]
484  append newstr [expr {[string is lower $char] ? [string toupper $char] : [string tolower $char]}]
485  }
486 
487  $txtt replace $startpos "$startpos+${strlen}c" $newstr
488 
489  }

§ convert_to_lower_case()

edit::convert_to_lower_case   txtt startpos endpos  

Definition at line 510 of file edit.tcl.

510  proc convert_to_lower_case {txtt startpos endpos} {
511 
512  # Get the string
513  set str [$txtt get $startpos $endpos]
514 
515  # Substitute the text
516  $txtt replace $startpos "$startpos+[string length $str]c" [string tolower $str]
517 
518  }

§ convert_to_rot13()

edit::convert_to_rot13   txtt startpos endpos  

Definition at line 534 of file edit.tcl.

534  proc convert_to_rot13 {txtt startpos endpos} {
535 
536  variable rot13_map
537 
538  # Get the string
539  set str [$txtt get $startpos $endpos]
540 
541  # Perform the substitution
542  $txtt replace $startpos "$startpos+[string length $str]c" [string map $rot13_map $str]
543 
544  # Set the cursor
545  ::tk::TextSetCursor $txtt $startpos
546 
547  }

§ convert_to_upper_case()

edit::convert_to_upper_case   txtt startpos endpos  

Definition at line 522 of file edit.tcl.

522  proc convert_to_upper_case {txtt startpos endpos} {
523 
524  # Get the string
525  set str [$txtt get $startpos $endpos]
526 
527  # Substitute the text
528  $txtt replace $startpos "$startpos+[string length $str]c" [string toupper $str]
529 
530  }

§ current_line_empty()

edit::current_line_empty

Definition at line 1249 of file edit.tcl.

1249  proc current_line_empty {} {
1250 
1251  # Get the current text widget
1252  set txt [gui::current_txt]
1253 
1254  return [expr {[$txt get "insert linestart" "insert lineend"] eq ""}]
1255 
1256  }

§ delete()

edit::delete   txtt startpos endpos copy adjust  

Definition at line 202 of file edit.tcl.

202  proc delete {txtt startpos endpos copy adjust} {
203 
204  # If the starting and ending position are the same, return now
205  if {[$txtt compare $startpos == $endpos]} {
206  return
207  }
208 
209  # Copy the text to the clipboard, if specified
210  if {$copy} {
211  clipboard clear
212  clipboard append [$txtt get $startpos $endpos]
213  }
214 
215  set insertpos ""
216 
217  if {[$txtt compare $endpos == end]} {
218  if {[$txtt compare $startpos == 1.0]} {
219  set endpos "$startpos lineend"
220  } elseif {[$txtt compare $startpos == "$startpos linestart"]} {
221  set insertpos "$startpos-1l"
222  set startpos "$startpos-1l lineend"
223  set endpos "end-1c"
224  }
225  }
226 
227  # Delete the text
228  $txtt delete $startpos $endpos
229 
230  # Adjust the insertion cursor if this was a delete and not a change
231  if {$adjust} {
232  if {$insertpos ne ""} {
233  $txtt mark set insert $insertpos
234  }
235  vim::adjust_insert $txtt
236  }
237 
238  }

§ delete_between_char()

edit::delete_between_char   txtt char copy  

Definition at line 452 of file edit.tcl.

452  proc delete_between_char {txtt char copy} {
453 
454  if {[lassign [get_char_positions $txtt $char] start_index end_index]} {
455  if {$copy} {
456  clipboard clear
457  clipboard append [$txtt get $start_index+1c $end_index]
458  }
459  $txtt delete $start_index+1c $end_index
460  return 1
461  }
462 
463  return 0
464 
465  }

§ delete_current_line()

edit::delete_current_line   txtt copy ?num?  

Definition at line 169 of file edit.tcl.

169  proc delete_current_line {txtt copy {num 1}} {
170 
171  # Clear the clipboard and copy the line(s) that will be deleted
172  if {$copy} {
173  clipboard clear
174  clipboard append [$txtt get "insert linestart" "insert+${num}l linestart"]
175  }
176 
177  # If we are deleting the last line, move the cursor up one line
178  if {[$txtt compare "insert+${num}l linestart" == end]} {
179  if {[$txtt compare "insert linestart" == 1.0]} {
180  $txtt delete "insert linestart" "insert lineend"
181  } else {
182  set new_index [$txtt index "insert-1l"]
183  $txtt delete "insert-1l lineend" "end-1c"
184  $txtt mark set insert $new_index
185  }
186  } else {
187  $txtt delete "insert linestart" "insert+${num}l linestart"
188  }
189 
190  # Position the cursor at the beginning of the first word
191  move_cursor $txtt firstchar
192 
193  # Adjust the insertion cursor
194  if {$copy} {
195  vim::adjust_insert $txtt
196  }
197 
198  }

§ delete_from_start()

edit::delete_from_start   txtt copy  

Definition at line 263 of file edit.tcl.

263  proc delete_from_start {txtt copy} {
264 
265  # Delete from the beginning of the line to just before the current cursor
266  if {[multicursor::enabled $txtt]} {
267  multicursor::delete $txtt "linestart"
268  } else {
269  if {$copy} {
270  clipboard clear
271  clipboard append [$txtt get "insert linestart" insert]
272  }
273  $txtt delete "insert linestart" insert
274  }
275 
276  }

§ delete_next_numbers()

edit::delete_next_numbers   txtt copy  

Definition at line 308 of file edit.tcl.

308  proc delete_next_numbers {txtt copy} {
309 
310  variable patterns
311 
312  if {[multicursor::enabled $txtt]} {
313  multicursor::delete $txtt pattern $patterns(nnumber)
314  } elseif {[regexp $patterns(nnumber) [$txtt get insert "insert lineend"] match]} {
315  if {$copy} {
316  clipboard clear
317  clipboard append [$txtt get insert "insert+[string length $match]c"]
318  }
319  $txtt delete insert "insert+[string length $match]c"
320  if {$copy} {
321  vim::adjust_insert $txtt
322  }
323  }
324 
325  }

§ delete_next_space()

edit::delete_next_space   txtt  

Definition at line 349 of file edit.tcl.

349  proc delete_next_space {txtt} {
350 
351  variable patterns
352 
353  if {[multicursor::enabled $txtt]} {
354  multicursor::delete $txtt pattern $patterns(nspace)
355  } elseif {[regexp $patterns(nspace) [$txtt get insert "insert lineend"] match]} {
356  $txtt delete insert "insert+[string length $match]c"
357  }
358 
359  }

§ delete_prev_numbers()

edit::delete_prev_numbers   txtt copy  

Definition at line 330 of file edit.tcl.

330  proc delete_prev_numbers {txtt copy} {
331 
332  variable patterns
333 
334  if {[multicursor::enabled $txtt]} {
335  multicursor::delete $txtt pattern $patterns(pnumber)
336  } elseif {[regexp $patterns(pnumber) [$txtt get "insert linestart" insert] match]} {
337  if {$copy} {
338  clipboard clear
339  clipboard append [$txtt get "insert-[string length $match]c" insert]
340  }
341  $txtt delete "insert-[string length $match]c" insert
342  }
343 
344  }

§ delete_prev_space()

edit::delete_prev_space   txtt  

Definition at line 364 of file edit.tcl.

364  proc delete_prev_space {txtt} {
365 
366  variable patterns
367 
368  if {[multicursor::enabled $txtt]} {
369  multicursor::delete $txtt pattern $patterns(pspace)
370  } elseif {[regexp $patterns(pspace) [$txtt get "insert linestart" insert] match]} {
371  $txtt delete "insert-[string length $match]c" insert
372  }
373 
374  }

§ delete_selected()

edit::delete_selected   txtt line  

Definition at line 115 of file edit.tcl.

115  proc delete_selected {txtt line} {
116 
117  # If we have selected text, perform the deletion
118  if {[llength [set selected [$txtt tag ranges sel]]] > 0} {
119 
120  # Allow multicursors to be handled, if enabled
121  if {![multicursor::delete $txtt selected]} {
122 
123  if {$line} {
124 
125  # Save the selected text to the clipboard
126  clipboard clear
127  foreach {start end} $selected {
128  clipboard append [$txtt get "$start linestart" "$end lineend"]
129  }
130 
131  # Set the cursor to the first character of the selection prior to deletion
132  $txtt mark set insert [lindex $selected 0]
133 
134  # Delete the text
135  foreach {end start} [lreverse $selected] {
136  $txtt delete "$start linestart" "$end lineend"
137  }
138 
139  } else {
140 
141  # Save the selected text to the clipboard
142  clipboard clear
143  foreach {start end} $selected {
144  clipboard append [$txtt get $start $end]
145  }
146 
147  # Set the cursor to the first character of the selection prior to deletion
148  $txtt mark set insert [lindex $selected 0]
149 
150  # Delete the text
151  foreach {end start} [lreverse $selected] {
152  $txtt delete $start $end
153  }
154 
155  }
156 
157  }
158 
159  return 1
160 
161  }
162 
163  return 0
164 
165  }

§ delete_to_end()

edit::delete_to_end   txtt copy ?num?  

Definition at line 242 of file edit.tcl.

242  proc delete_to_end {txtt copy {num 1}} {
243 
244  # Delete from the current cursor to the end of the line
245  if {[multicursor::enabled $txtt]} {
246  multicursor::delete $txtt "lineend"
247  } else {
248  set endpos [get_index $txtt lineend -num $num]+1c
249  if {$copy} {
250  clipboard clear
251  clipboard append [$txtt get insert $endpos]
252  }
253  $txtt delete insert $endpos
254  if {$copy} {
255  vim::adjust_insert $txtt
256  }
257  }
258 
259  }

§ delete_to_firstchar()

edit::delete_to_firstchar   txtt copy  

Definition at line 280 of file edit.tcl.

280  proc delete_to_firstchar {txtt copy} {
281 
282  if {[multicursor::enabled $txtt]} {
283  multicursor::delete $txtt firstchar
284  } else {
285  set firstchar [get_index $txtt firstchar]
286  if {[$txtt compare $firstchar < insert]} {
287  if {$copy} {
288  clipboard clear
289  clipboard append [$txtt get $firstchar insert]
290  }
291  $txtt delete $firstchar insert
292  } elseif {[$txtt compare $firstchar > insert]} {
293  if {$copy} {
294  clipboard clear
295  clipboard append [$txtt get insert $firstchar]
296  }
297  $txtt delete insert $firstchar
298  if {$copy} {
299  vim::adjust_insert $txtt
300  }
301  }
302  }
303 
304  }

§ delete_to_next_char()

edit::delete_to_next_char   txtt char copy ?num? ?exclusive?  

Definition at line 379 of file edit.tcl.

379  proc delete_to_next_char {txtt char copy {num 1} {exclusive 0}} {
380 
381  if {[set index [find_char $txtt next $char $num insert $exclusive]] ne "insert"} {
382  if {$copy} {
383  clipboard clear
384  clipboard append [$txtt get insert $index]
385  }
386  $txtt delete insert $index
387  if {$copy && $inclusive} {
388  vim::adjust_insert $txtt
389  }
390  }
391 
392  }

§ delete_to_prev_char()

edit::delete_to_prev_char   txtt char copy ?num? ?exclusive?  

Definition at line 397 of file edit.tcl.

397  proc delete_to_prev_char {txtt char copy {num 1} {exclusive 0}} {
398 
399  if {[set index [find_char $txtt prev $char $num insert $exclusive]] ne "insert"} {
400  if {$copy} {
401  clipboard clear
402  clipboard append [$txtt get $index insert]
403  }
404  $txtt delete $index insert
405  }
406 
407  }

§ do_indent()

edit::do_indent   txtt startpos endpos  

Definition at line 1142 of file edit.tcl.

1142  proc do_indent {txtt startpos endpos} {
1143 
1144  # Get the indent spacing
1145  set indent_str [string repeat " " [indent::get_shiftwidth $txtt]]
1146 
1147  while {[$txtt index "$startpos linestart"] <= [$txtt index "$endpos linestart"]} {
1148  $txtt insert "$startpos linestart" $indent_str
1149  set startpos [$txtt index "$startpos linestart+1l"]
1150  }
1151 
1152  }

§ do_uncomment()

edit::do_uncomment   txt startpos endpos  

Definition at line 1114 of file edit.tcl.

1114  proc do_uncomment {txt startpos endpos} {
1115 
1116  set retval 0
1117 
1118  # Get the comment syntax
1119  lassign [syntax::get_comments $txt] icomment lcomments bcomments
1120 
1121  # Get the comment syntax to remove
1122  set comments [join [eval concat $lcomments $bcomments] |]
1123 
1124  set linestart $startpos
1125  foreach line [split [$txt get $startpos $endpos] \n] {
1126  if {[regexp -indices -- "($comments)+?" $line -> com]} {
1127  set delstart [$txt index "$linestart+[lindex $com 0]c"]
1128  set delend [$txt index "$linestart+[expr [lindex $com 1] + 1]c"]
1129  $txt delete $delstart $delend
1130  set retval 1
1131  }
1132  set linestart [$txt index "$linestart+1l linestart"]
1133  incr i
1134  }
1135 
1136  return $retval
1137 
1138  }

§ do_unindent()

edit::do_unindent   txtt startpos endpos  

Definition at line 1156 of file edit.tcl.

1156  proc do_unindent {txtt startpos endpos} {
1157 
1158  # Get the indent spacing
1159  set unindent_str [string repeat " " [indent::get_shiftwidth $txtt]]
1160  set unindent_len [string length $unindent_str]
1161 
1162  while {[$txtt index "$startpos linestart"] <= [$txtt index "$endpos linestart"]} {
1163  if {[regexp "^$unindent_str" [$txtt get "$startpos linestart" "$startpos lineend"]]} {
1164  $txtt delete "$startpos linestart" "$startpos linestart+${unindent_len}c"
1165  }
1166  set startpos [$txtt index "$startpos linestart+1l"]
1167  }
1168 
1169  }

§ find_char()

edit::find_char   txtt dir char num startpos exclusive  

Definition at line 1565 of file edit.tcl.

1565  proc find_char {txtt dir char num startpos exclusive} {
1566 
1567  # Perform the character search
1568  if {$dir eq "next"} {
1569  set indices [$txtt search -all -- $char "$startpos+1c" "$startpos lineend"]
1570  if {[set index [lindex $indices [expr $num - 1]]] eq ""} {
1571  set index "insert"
1572  } elseif {$exclusive} {
1573  set index "$index-1c"
1574  }
1575  } else {
1576  set indices [$txtt search -all -- $char "$startpos linestart" insert]
1577  if {[set index [lindex $indices end-[expr $num - 1]]] eq ""} {
1578  set index "insert"
1579  } elseif {$exclusive} {
1580  set index "$index+1c"
1581  }
1582  }
1583 
1584  return $index
1585 
1586  }

§ format()

edit::format   txtt type  

Definition at line 2241 of file edit.tcl.

2241  proc format {txtt type} {
2242 
2243  # Get the range of lines to modify
2244  if {[set ranges [$txtt tag ranges sel]] eq ""} {
2245  if {[multicursor::enabled $txtt]} {
2246  foreach {start end} [$txtt tag ranges mcursor] {
2247  if {[string trim [$txtt get "$start wordstart" "$start wordend"]] ne ""} {
2248  lappend ranges [$txtt index "$start wordstart"] [$txtt index "$start wordend"]
2249  } else {
2250  lappend ranges $start $start
2251  }
2252  }
2253  } else {
2254  if {[string trim [$txtt get "insert wordstart" "insert wordend"]] ne ""} {
2255  set ranges [list [$txtt index "insert wordstart"] [$txtt index "insert wordend"]]
2256  } else {
2257  set ranges [list [$txtt index "insert"] [$txtt index "insert"]]
2258  }
2259  }
2260  }
2261 
2262  if {[set ranges_len [llength $ranges]] > 0} {
2263 
2264  # Get the formatting information for the current text widget
2265  array set formatting [syntax::get_formatting [winfo parent $txtt]]
2266 
2267  if {[info exists formatting($type)]} {
2268 
2269  lassign $formatting($type) stype pattern
2270 
2271  # Figure out the string to use when asking the user for a reference
2272  switch $type {
2273  link { set refmsg [msgcat::mc "Link URL"]}
2274  image { set refmsg [msgcat::mc "Image URL"]}
2275  default { set refmsg ""}
2276  }
2277 
2278  # If we need to resolve a reference do that now
2279  if {$refmsg ne ""} {
2280  set ref ""
2281  if {[gui::get_user_response $refmsg ref -allow_vars 1]} {
2282  set pattern [string map [list \{REF\} $ref] $pattern]
2283  } else {
2284  return
2285  }
2286  }
2287 
2288  # Find the position of the {TEXT} substring
2289  set textpos [string first \{TEXT\} $pattern]
2290 
2291  # Remove any multicursors
2292  multicursor::disable $txtt
2293 
2294  $txtt edit separator
2295 
2296  if {$stype eq "line"} {
2297  set last ""
2298  foreach {end start} [lreverse $ranges] {
2299  if {($last eq "") || [$txtt compare "$start linestart" != "$last linestart"]} {
2300  while {[$txtt compare $start < $end]} {
2301  set oldstr [$txtt get "$start linestart" "$start lineend"]
2302  set newstr [string map [list \{TEXT\} $oldstr] $pattern]
2303  $txtt replace "$start linestart" "$start lineend" $newstr
2304  if {$oldstr eq ""} {
2305  if {($ranges_len == 2) && [$txtt compare $start+1l >= $end]} {
2306  $txtt mark set insert "$start linestart+${textpos}c"
2307  } else {
2308  multicursor::add_cursor $txtt "$start linestart+${textpos}c"
2309  }
2310  }
2311  if {[string first \n $newstr]} {
2312  indent::format_text $txtt "$start linestart" "$start linestart+[string length $newstr]c" 0
2313  }
2314  set last $start
2315  set start [$txtt index "$start+1l"]
2316  }
2317  }
2318  }
2319  } else {
2320  foreach {end start} [lreverse $ranges] {
2321  set oldstr [$txtt get $start $end]
2322  set newstr [string map [list \{TEXT\} $oldstr] $pattern]
2323  $txtt replace $start $end $newstr
2324  if {$oldstr eq ""} {
2325  if {$ranges_len == 2} {
2326  $txtt mark set insert "$start+${textpos}c"
2327  } else {
2328  multicursor::add_cursor $txtt [$txtt index "$start+${textpos}c"]
2329  }
2330  }
2331  if {[string first \n $newstr]} {
2332  indent::format_text $txtt $start "$start+[string length $newstr]c" 0
2333  }
2334  }
2335  }
2336 
2337  $txtt edit separator
2338 
2339  }
2340 
2341  }
2342 
2343  }

§ get_char()

edit::get_char   txt dir ?num? ?start?  

Definition at line 1311 of file edit.tcl.

1311  proc get_char {txt dir {num 1} {start insert}} {
1312 
1313  if {$dir eq "next"} {
1314 
1315  while {($num > 0) && [$txt compare $start < end-2c]} {
1316  if {[set line_chars [$txt count -displaychars $start "$start lineend"]] == 0} {
1317  set start [$txt index "$start+1 display lines"]
1318  set start "$start linestart"
1319  incr num -1
1320  } elseif {$line_chars <= $num} {
1321  set start [$txt index "$start+1 display lines"]
1322  set start "$start linestart"
1323  incr num -$line_chars
1324  } else {
1325  set start "$start+$num display chars"
1326  set num 0
1327  }
1328  }
1329 
1330  return [$txt index $start]
1331 
1332  } else {
1333 
1334  set first 1
1335  while {($num > 0) && [$txt compare $start > 1.0]} {
1336  if {([set line_chars [$txt count -displaychars "$start linestart" $start]] == 0) && !$first} {
1337  if {[incr num -1] > 0} {
1338  set start [$txt index "$start-1 display lines"]
1339  set start "$start lineend"
1340  }
1341  } elseif {$line_chars < $num} {
1342  set start [$txt index "$start-1 display lines"]
1343  set start "$start lineend"
1344  incr num -$line_chars
1345  } else {
1346  set start "$start-$num display chars"
1347  set num 0
1348  }
1349  set first 0
1350  }
1351 
1352  return [$txt index $start]
1353 
1354  }
1355 
1356  }

§ get_char_positions()

edit::get_char_positions   txtt char  

Definition at line 411 of file edit.tcl.

411  proc get_char_positions {txtt char} {
412 
413  array set pairs {
414  \{ {\\\} L}
415  \} {\\\{ R}
416  \( {\\\) L}
417  \) {\\\( R}
418  \[ {\\\] L}
419  \] {\\\[ R}
420  < {> L}
421  > {< R}
422  }
423 
424  # Initialize
425  set retval [set end_index 0]
426 
427  # Get the matching character
428  if {[info exists pairs($char)]} {
429  if {[lindex $pairs($char) 1] eq "R"} {
430  if {[set start_index [gui::find_match_pair $txtt [lindex $pairs($char) 0] \\$char -backwards]] != -1} {
431  set retval [expr {[set end_index [gui::find_match_pair $txtt \\$char [lindex $pairs($char) 0] -forwards]] != -1}]
432  }
433  } else {
434  if {[set start_index [gui::find_match_pair $txtt \\$char [lindex $pairs($char) 0] -backwards]] != -1} {
435  set retval [expr {[set end_index [gui::find_match_pair $txtt [lindex $pairs($char) 0] \\$char -forwards]] != -1}]
436  }
437  }
438  } else {
439  if {[set start_index [gui::find_match_char $txtt $char -backwards]] != -1} {
440  set retval [expr {[set end_index [gui::find_match_char $txtt $char -forwards]] != -1}]
441  }
442  }
443 
444  return [list $start_index $end_index $retval]
445 
446  }

§ get_index()

edit::get_index   txtt position args  

Definition at line 1791 of file edit.tcl.

1791  proc get_index {txtt position args} {
1792 
1793  variable patterns
1794 
1795  array set opts {
1796  -dir "next"
1797  -startpos "insert"
1798  -num 1
1799  -char ""
1800  -exclusive 0
1801  -column ""
1802  -adjust ""
1803  -forceadjust ""
1804  }
1805  array set opts $args
1806 
1807  # Create a default index to use
1808  set index $opts(-startpos)
1809 
1810  # Get the new cursor position
1811  switch $position {
1812  left {
1813  if {[$txtt compare "$opts(-startpos) display linestart" > "$opts(-startpos)-$opts(-num) display chars"]} {
1814  set index "$opts(-startpos) display linestart"
1815  } else {
1816  set index "$opts(-startpos)-$opts(-num) display chars"
1817  }
1818  }
1819  right {
1820  if {[$txtt compare "$opts(-startpos) display lineend" < "$opts(-startpos)+$opts(-num) display chars"]} {
1821  set index "$opts(-startpos) display lineend"
1822  } else {
1823  set index "$opts(-startpos)+$opts(-num) display chars"
1824  }
1825  }
1826  up {
1827  if {[set $opts(-column)] eq ""} {
1828  set $opts(-column) [lindex [split [$txtt index $opts(-startpos)] .] 1]
1829  }
1830  set index $opts(-startpos)
1831  for {set i 0} {$i < $opts(-num)} {incr i} {
1832  set index [$txtt index "$index linestart-1 display lines"]
1833  }
1834  set index [lindex [split $index .] 0].[set $opts(-column)]
1835  }
1836  down {
1837  if {[set $opts(-column)] eq ""} {
1838  set $opts(-column) [lindex [split [$txtt index $opts(-startpos)] .] 1]
1839  }
1840  set index $opts(-startpos)
1841  for {set i 0} {$i < $opts(-num)} {incr i} {
1842  if {[$txtt compare [set index [$txtt index "$index lineend+1 display lines"]] == end]} {
1843  set index [$txtt index "end-1c"]
1844  break
1845  }
1846  }
1847  set index [lindex [split $index .] 0].[set $opts(-column)]
1848  }
1849  first {
1850  if {[$txtt get -displaychars 1.0] eq ""} {
1851  set index "1.0+1 display chars"
1852  } else {
1853  set index "1.0"
1854  }
1855  }
1856  last { set index "end"}
1857  char { set index [get_char $txtt $opts(-dir) $opts(-num) $opts(-startpos)]}
1858  dchar {
1859  if {$opts(-dir) eq "next"} {
1860  set index "$opts(-startpos)+$opts(-num) display chars"
1861  } else {
1862  set index "$opts(-startpos)-$opts(-num) display chars"
1863  }
1864  }
1865  findchar { set index [find_char $txtt $opts(-dir) $opts(-char) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1866  betweenchar { set index [between_char $txtt $opts(-dir) $opts(-char) $opts(-startpos)]}
1867  firstchar {
1868  if {$opts(-num) == 0} {
1869  set index $opts(-startpos)
1870  } elseif {$opts(-dir) eq "next"} {
1871  if {[$txtt compare [set index [$txtt index "$opts(-startpos)+$opts(-num) display lines"]] == end]} {
1872  set index [$txtt index "$index-1 display lines"]
1873  }
1874  } else {
1875  set index [$txtt index "$opts(-startpos)-$opts(-num) display lines"]
1876  }
1877  if {[lsearch [$txtt tag names "$index linestart"] __prewhite] != -1} {
1878  set index [lindex [$txtt tag nextrange __prewhite "$index linestart"] 1]-1c
1879  } else {
1880  set index "$index lineend"
1881  }
1882  }
1883  lastchar {
1884  set line [expr [lindex [split [$txtt index $opts(-startpos)] .] 0] + ($opts(-num) - 1)]
1885  set index "$line.0+[string length [string trimright [$txtt get $line.0 $line.end]]]c"
1886  }
1887  wordstart { set index [get_wordstart $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1888  wordend { set index [get_wordend $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1889  WORDstart { set index [get_WORDstart $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1890  WORDend { set index [get_WORDend $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1891  column { set index [lindex [split [$txtt index $opts(-startpos)] .] 0].[expr $opts(-num) - 1]}
1892  linenum {
1893  if {[lsearch [$txtt tag names "$opts(-num).0"] __prewhite] != -1} {
1894  set index [lindex [$txtt tag nextrange __prewhite "$opts(-num).0"] 1]-1c
1895  } else {
1896  set index "$opts(-num).0 lineend"
1897  }
1898  }
1899  linestart {
1900  if {$opts(-num) > 1} {
1901  if {[$txtt compare [set index [$txtt index "$opts(-startpos)+[expr $opts(-num) - 1] display lines linestart"]] == end]} {
1902  set index "end"
1903  } else {
1904  set index "$index+1 display chars"
1905  }
1906  } else {
1907  set index [$txtt index "$opts(-startpos) linestart+1 display chars"]
1908  }
1909  if {[$txtt compare "$index-1 display chars" >= "$index linestart"]} {
1910  set index "$index-1 display chars"
1911  }
1912  }
1913  lineend {
1914  if {$opts(-num) == 1} {
1915  set index "$opts(-startpos) lineend"
1916  } else {
1917  set index [$txtt index "$opts(-startpos)+[expr $opts(-num) - 1] display lines"]
1918  set index "$index lineend"
1919  }
1920  }
1921  dispstart { set index "@0,[lindex [$txtt bbox $opts(-startpos)] 1]"}
1922  dispmid { set index "@[expr [winfo width $txtt] / 2],[lindex [$txtt bbox $opts(-startpos)] 1]"}
1923  dispend { set index "@[winfo width $txtt],[lindex [$txtt bbox $opts(-startpos)] 0]"}
1924  sentence { set index [get_sentence $txtt $opts(-dir) $opts(-num) $opts(-startpos)]}
1925  paragraph { set index [get_paragraph $txtt $opts(-dir) $opts(-num) $opts(-startpos)]}
1926  screentop { set index "@0,0"}
1927  screenmid { set index "@0,[expr [winfo height $txtt] / 2]"}
1928  screenbot { set index "@0,[winfo height $txtt]"}
1929  numberstart {
1930  if {[regexp $patterns(pnumber) [$txtt get "$opts(-startpos) linestart" $opts(-startpos)] match]} {
1931  set index "$opts(-startpos)-[string length $match]c"
1932  }
1933  }
1934  numberend {
1935  if {[regexp $patterns(nnumber) [$txtt get $opts(-startpos) "$opts(-startpos) lineend"] match]} {
1936  set index "$opts(-startpos)+[expr [string length $match] - 1]c"
1937  }
1938  }
1939  spacestart {
1940  if {[regexp $patterns(pspace) [$txtt get "$opts(-startpos) linestart" $opts(-startpos)] match]} {
1941  set index "$opts(-startpos)-[string length $match]c"
1942  }
1943  }
1944  spaceend {
1945  if {[regexp $patterns(nspace) [$txtt get $opts(-startpos) "$opts(-startpos) lineend"] match]} {
1946  set index "$opts(-startpos)+[expr [string length $match] - 1]c"
1947  }
1948  }
1949  tagstart {
1950  set insert [$txtt index insert]
1951  while {[set ranges [emmet::get_node_range [winfo parent $txtt]]] ne ""} {
1952  if {[incr opts(-num) -1] == 0} {
1953  set index [expr {$opts(-exclusive) ? [lindex $ranges 1] : [lindex $ranges 0]}]
1954  break
1955  } else {
1956  $txtt mark set insert "[lindex $ranges 0]-1c"
1957  }
1958  }
1959  $txtt mark set insert $insert
1960  }
1961  tagend {
1962  set insert [$txtt index insert]
1963  while {[set ranges [emmet::get_node_range [winfo parent $txtt]]] ne ""} {
1964  if {[incr opts(-num) -1] == 0} {
1965  set index [expr {$opts(-exclusive) ? [lindex $ranges 2] : [lindex $ranges 3]}]
1966  break
1967  } else {
1968  $txtt mark set insert "[lindex $ranges 0]-1c"
1969  }
1970  }
1971  $txtt mark set insert $insert
1972  }
1973  }
1974 
1975  # Make any necessary adjustments, if needed
1976  if {$opts(-forceadjust) ne ""} {
1977  set index [$txtt index "$index$opts(-forceadjust)"]
1978  } elseif {($index ne $opts(-startpos)) && ($opts(-adjust) ne "")} {
1979  set index [$txtt index "$index$opts(-adjust)"]
1980  }
1981 
1982  return $index
1983 
1984  }

§ get_paragraph()

edit::get_paragraph   txtt dir num ?start?  

Definition at line 1715 of file edit.tcl.

1715  proc get_paragraph {txtt dir num {start insert}} {
1716 
1717  if {$dir eq "next"} {
1718 
1719  set nl 0
1720  while {[$txtt compare $start < end-1c]} {
1721  if {([$txtt get "$start linestart" "$start lineend"] eq "") || \
1722  ([lsearch [$txtt tag names $start] dspace] != -1)} {
1723  set nl 1
1724  } elseif {$nl && ([incr num -1] == 0)} {
1725  return "$start linestart"
1726  } else {
1727  set nl 0
1728  }
1729  set start [$txtt index "$start+1 display lines"]
1730  }
1731 
1732  return [$txtt index end-1c]
1733 
1734  } else {
1735 
1736  set last_start "end"
1737 
1738  # If the start position is in the first column adjust the starting
1739  # line to the line above to avoid matching ourselves
1740  if {[$txtt compare $start == "$start linestart"]} {
1741  set last_start $start
1742  set start [$txtt index "$start-1 display lines"]
1743  }
1744 
1745  set nl 1
1746  while {[$txtt compare $start < $last_start]} {
1747  if {([$txtt get "$start linestart" "$start lineend"] ne "") && \
1748  ([lsearch [$txtt tag names $start] dspace] == -1)} {
1749  set nl 0
1750  } elseif {!$nl && ([incr num -1] == 0)} {
1751  return [$txtt index "$start+1 display lines linestart"]
1752  } else {
1753  set nl 1
1754  }
1755  set last_start $start
1756  set start [$txtt index "$start-1 display lines"]
1757  }
1758 
1759  if {(([$txtt get "$start linestart" "$start lineend"] eq "") || \
1760  ([lsearch [$txtt tag names $start] dspace] != -1)) && !$nl && \
1761  ([incr num -1] == 0)} {
1762  return [$txtt index "$start+1 display lines linestart"]
1763  } else {
1764  return 1.0
1765  }
1766 
1767  }
1768 
1769  }

§ get_range()

edit::get_range   txtt pos1args pos2args object move ?cursor?  

Definition at line 2138 of file edit.tcl.

2138  proc get_range {txtt pos1args pos2args object move {cursor insert}} {
2139 
2140  if {$object ne ""} {
2141 
2142  set type [lindex $pos1args 0]
2143  set num [lindex $pos1args 1]
2144  set inner [expr {$object eq "i"}]
2145  set adjust [expr {$move ? "" : "+1c"}]
2146 
2147  switch [lindex $pos1args 0] {
2148  "word" { return [get_range_word $txtt word $num $inner $adjust $cursor]}
2149  "WORD" { return [get_range_word $txtt WORD $num $inner $adjust $cursor]}
2150  "paragraph" { return [get_range_sentences $txtt paragraph $num $inner $adjust $cursor]}
2151  "sentence" { return [get_range_sentences $txtt sentence $num $inner $adjust $cursor]}
2152  "tag" {
2153  set insert [$txtt index $cursor]
2154  while {[set ranges [emmet::get_node_range [winfo parent $txtt]]] ne ""} {
2155  if {[incr num -1] == 0} {
2156  $txtt mark set insert $insert
2157  if {$inner} {
2158  return [list [lindex $ranges 1] [$txtt index "[lindex $ranges 2]-1c$adjust"]]
2159  } else {
2160  return [list [lindex $ranges 0] [$txtt index "[lindex $ranges 3]-1c$adjust"]]
2161  }
2162  } else {
2163  $txtt mark set insert "[lindex $ranges 0]-1c"
2164  }
2165  }
2166  $txtt mark set insert $insert
2167  }
2168  "paren" -
2169  "curly" -
2170  "square" -
2171  "angled" { return [get_range_block $txtt $type $num $inner $adjust $cursor]}
2172  "double" { return [get_range_string $txtt \" comstr0d $inner $adjust $cursor]}
2173  "single" { return [get_range_string $txtt \' comstr0s $inner $adjust $cursor]}
2174  "btick" { return [get_range_string $txtt \` comstr0b $inner $adjust $cursor]}
2175  }
2176 
2177  } else {
2178 
2179  set pos1 [$txtt index [edit::get_index $txtt {*}$pos1args -startpos $cursor]]
2180 
2181  if {$pos2args ne ""} {
2182  set pos2 [$txtt index [edit::get_index $txtt {*}$pos2args -startpos $cursor]]
2183  } else {
2184  set pos2 [$txtt index $cursor]
2185  }
2186 
2187  # Return the start/end position in the correct order.
2188  return [expr {[$txtt compare $pos1 < $pos2] ? [list $pos1 $pos2] : [list $pos2 $pos1]}]
2189 
2190  }
2191 
2192  }

§ get_range_block()

edit::get_range_block   txtt type num inner adjust ?cursor?  

Definition at line 2091 of file edit.tcl.

2091  proc get_range_block {txtt type num inner adjust {cursor insert}} {
2092 
2093  # Search backwards
2094  set txt [winfo parent $txtt]
2095  set number $num
2096  set startpos [expr {([lsearch [$txtt tag names $cursor] __${type}L] == -1) ? $cursor : "$cursor+1c"}]
2097 
2098  while {[set index [ctext::getMatchBracket $txt ${type}L $startpos]] ne ""} {
2099  if {[incr number -1] == 0} {
2100  set right [ctext::getMatchBracket $txt ${type}R $index]
2101  if {($right eq "") || [$txtt compare $right < $cursor]} {
2102  return [list "" ""]
2103  } else {
2104  return [expr {$inner ? [list [$txt index "$index+1c"] [$txt index "$right-1c$adjust"]] : [list $index [$txt index "$right$adjust"]]}]
2105  }
2106  } else {
2107  set startpos $index
2108  }
2109  }
2110 
2111  return [list "" ""]
2112 
2113  }

§ get_range_sentences()

edit::get_range_sentences   txtt type num inner adjust ?cursor?  

Definition at line 2072 of file edit.tcl.

2072  proc get_range_sentences {txtt type num inner adjust {cursor insert}} {
2073 
2074  set pos_list [list [get_index $txtt $type -dir prev -startpos "$cursor+1c"] [get_index $txtt $type -dir next -num $num]]
2075 
2076  if {$inner} {
2077  set str [$txtt get {*}$pos_list]
2078  set less [expr ([string length $str] - [string length [string trimright $str]]) + 1]
2079  } else {
2080  set less 1
2081  }
2082 
2083  lset pos_list 1 [$txtt index "[lindex $pos_list 1]-${less}c$adjust"]
2084 
2085  return $pos_list
2086 
2087  }

§ get_range_string()

edit::get_range_string   txtt char tag inner adjust ?cursor?  

Definition at line 2117 of file edit.tcl.

2117  proc get_range_string {txtt char tag inner adjust {cursor insert}} {
2118 
2119  if {[$txtt get $cursor] eq $char} {
2120  if {[lsearch [$txtt tag names $cursor-1c] __${tag}*] == -1} {
2121  set index [gui::find_match_char [winfo parent $txtt] $char -forwards]
2122  return [expr {$inner ? [list [$txtt index "$cursor+1c"] [$txtt index "$index-1c$adjust"]] : [list [$txtt index $cursor] [$txtt index "$index$adjust"]]}]
2123  } else {
2124  set index [gui::find_match_char [winfo parent $txtt] $char -backwards]
2125  return [expr {$inner ? [list [$txtt index "$index+1c"] [$txtt index "$cursor-1c$adjust"]] : [list $index [$txtt index "$cursor$adjust"]]}]
2126  }
2127  } elseif {[set tag [lsearch -inline [$txtt tag names $cursor] __${tag}*]] ne ""} {
2128  lassign [$txtt tag prevrange $tag $cursor] startpos endpos
2129  return [expr {$inner ? [list [$txtt index "$startpos+1c"] [$txtt index "$endpos-2c$adjust"]] : [list $startpos [$txtt index "$endpos-1c$adjust"]]}]
2130  }
2131 
2132  return [list "" ""]
2133 
2134  }

§ get_range_word()

edit::get_range_word   txtt type num inner adjust ?cursor?  

Definition at line 1988 of file edit.tcl.

1988  proc get_range_word {txtt type num inner adjust {cursor insert}} {
1989 
1990  if {$inner} {
1991 
1992  # Get the starting position of the selection
1993  if {[string is space [$txtt get $cursor]]} {
1994  set startpos [get_index $txtt spacestart -dir prev -startpos "$cursor+1c"]
1995  } else {
1996  set startpos [get_index $txtt ${type}start -dir prev -startpos "$cursor+1c"]
1997  }
1998 
1999  # Count spaces and non-spaces
2000  set endpos $cursor
2001  for {set i 0} {$i < $num} {incr i} {
2002  if {$type eq "WORD"} {
2003  set endpos [$txtt index "$endpos+1c"]
2004  }
2005  if {[string is space [$txtt get $endpos]]} {
2006  set endpos [get_index $txtt spaceend -dir next -startpos $endpos]
2007  } else {
2008  set endpos [get_index $txtt ${type}end -dir next -startpos $endpos]
2009  }
2010  }
2011 
2012  } else {
2013 
2014  set endpos [get_index $txtt ${type}end -dir next -num $num -startpos [expr {($type eq "word") ? $cursor : "$cursor-1c"}]]
2015 
2016  # If the cursor is within a space, make the startpos be the start of the space
2017  if {[string is space [$txtt get $cursor]]} {
2018  set startpos [get_index $txtt spacestart -dir prev -startpos "$cursor+1c"]
2019 
2020  # Otherwise, the insertion cursor is within a word, if the character following
2021  # the end of the word is a space, the start is the start of the word while the end is
2022  # the whitspace after the word.
2023  } elseif {[$txtt compare "$endpos+1c" < "$endpos lineend"] && [string is space [$txtt get "$endpos+1c"]]} {
2024  set startpos [get_index $txtt ${type}start -dir prev -startpos "$cursor+1c"]
2025  set endpos [get_index $txtt spaceend -dir next -startpos "$endpos+1c"]
2026 
2027  # Otherwise, set the start of the selection to the be the start of the preceding
2028  # whitespace.
2029  } else {
2030  set startpos [get_index $txtt ${type}start -dir prev -startpos "$cursor+1c"]
2031  if {[$txtt compare $startpos > "$startpos linestart"] && [string is space [$txtt get "$startpos-1c"]]} {
2032  set startpos [get_index $txtt spacestart -dir prev -startpos "$startpos-1c"]
2033  }
2034  }
2035 
2036  }
2037 
2038  return [list $startpos [$txtt index "$endpos$adjust"]]
2039 
2040  }

§ get_range_WORD()

edit::get_range_WORD   txtt num inner adjust ?cursor?  

Definition at line 2044 of file edit.tcl.

2044  proc get_range_WORD {txtt num inner adjust {cursor insert}} {
2045 
2046  if {[string is space [$txtt get $cursor]]} {
2047  set pos_list [list [get_index $txtt spacestart -dir prev -startpos "$cursor+1c"] [get_index $txtt spaceend -dir next -adjust "-1c"]]
2048  } else {
2049  set pos_list [list [get_index $txtt $start -dir prev -startpos "$cursor+1c"] [get_index $txtt $end -dir next -num $num]]
2050  }
2051 
2052  if {!$inner} {
2053  set index [$txtt search -forwards -regexp -- {\S} "[lindex $pos_list 1]+1c" "[lindex $pos_list 1] lineend"]
2054  if {($index ne "") && [$txtt compare "[lindex $pos_list 1]+1c" != $index]} {
2055  lset pos_list 1 [$txtt index "$index-1c"]
2056  } else {
2057  set index [$txtt search -backwards -regexp -- {\S} [lindex $pos_list 0] "[lindex $pos_list 0] linestart"]
2058  if {($index ne "") && [$txtt compare "[lindex $pos_list 0]-1c" != $index]} {
2059  lset pos_list 0 [$txtt index "$index+1c"]
2060  }
2061  }
2062  }
2063 
2064  lset pos_list 1 [$txtt index "[lindex $pos_list 1]$adjust"]
2065 
2066  return $pos_list
2067 
2068  }

§ get_sentence()

edit::get_sentence   txtt dir num ?startpos?  

Definition at line 1636 of file edit.tcl.

1636  proc get_sentence {txtt dir num {startpos "insert"}} {
1637 
1638  variable patterns
1639 
1640  # Search for the end of the previous sentence
1641  set index [$txtt search -backwards -count lengths -regexp -- $patterns(sentence) $startpos 1.0]
1642  set beginpos "1.0"
1643  set endpos "end-1c"
1644 
1645  # If the startpos is within a comment block and the found index lies outside of that
1646  # block, set the sentence starting point on the first non-whitespace character within the
1647  # comment block.
1648  if {[set comment [ctext::commentCharRanges [winfo parent $txtt] $startpos]] ne ""} {
1649  lassign [lrange $comment 1 2] beginpos endpos
1650  if {($index ne "") && [$txtt compare $index < [lindex $comment 1]]} {
1651  set index ""
1652  }
1653 
1654  # If the end of the found sentence is within a comment block, set the beginning position
1655  # to the end of that comment and clear the index.
1656  } elseif {($index ne "") && ([set comment [ctext::commentCharRanges [winfo parent $txtt] $index]] ne "")} {
1657  set beginpos [lindex $comment end]
1658  set index ""
1659  }
1660 
1661  if {$dir eq "next"} {
1662 
1663  # If we could not find the end of a previous sentence, find the first
1664  # non-whitespace character in the file and if it is after the startpos,
1665  # return the index.
1666  if {($index eq "") && ([set index [$txtt search -forwards -count lengths -regexp -- {\S} $beginpos $endpos]] ne "")} {
1667  if {[$txtt compare $index > $startpos] && ([incr num -1] == 0)} {
1668  return $index
1669  }
1670  set index ""
1671  }
1672 
1673  # If the insertion cursor is just before the beginning of the sentence.
1674  if {($index ne "") && [$txtt compare $startpos < "$index+[expr [lindex $lengths 0] - 1]c"]} {
1675  set startpos $index
1676  }
1677 
1678  while {[set index [$txtt search -forwards -count lengths -regexp -- $patterns(sentence) $startpos $endpos]] ne ""} {
1679  set startpos [$txtt index "$index+[expr [lindex $lengths 0] - 1]c"]
1680  if {[incr num -1] == 0} {
1681  return $startpos
1682  }
1683  }
1684 
1685  return $endpos
1686 
1687  } else {
1688 
1689  # If the insertion cursor is between sentences, adjust the starting position
1690  if {($index ne "") && [$txtt compare $startpos <= "$index+[expr [lindex $lengths 0] - 1]c"]} {
1691  set startpos $index
1692  }
1693 
1694  while {[set index [$txtt search -backwards -count lengths -regexp -- $patterns(sentence) $startpos-1c $beginpos]] ne ""} {
1695  set startpos $index
1696  if {[incr num -1] == 0} {
1697  return [$txtt index "$index+[expr [lindex $lengths 0] - 1]c"]
1698  }
1699  }
1700 
1701  if {([incr num -1] == 0) && \
1702  ([set index [$txtt search -forwards -regexp -- {\S} $beginpos $endpos]] ne "") && \
1703  ([$txtt compare $index < $startpos])} {
1704  return $index
1705  } else {
1706  return $beginpos
1707  }
1708 
1709  }
1710 
1711  }

§ get_wordend()

edit::get_wordend   txt dir ?num? ?start? ?exclusive?  

Definition at line 1435 of file edit.tcl.

1435  proc get_wordend {txt dir {num 1} {start insert} {exclusive 0}} {
1436 
1437  lassign [split [$txt index $start] .] curr_row curr_col
1438 
1439  if {$dir eq "next"} {
1440 
1441  while {1} {
1442 
1443  set line [$txt get -displaychars $curr_row.0 $curr_row.end]
1444 
1445  while {1} {
1446  if {[regexp -indices -start [expr $curr_col + 1] -- {(\w+|\s+|[^\w\s]+)} $line index]} {
1447  set curr_col [lindex $index 1]
1448  } else {
1449  break
1450  }
1451  if {![string is space [string index $line $curr_col]] && ([incr num -1] == 0)} {
1452  return [$txt index "$curr_row.0 + $curr_col display chars"]
1453  }
1454  }
1455 
1456  lassign [split [$txt index "$curr_row.end + 1 display chars"] .] curr_row curr_col
1457 
1458  if {![$txt compare $curr_row.$curr_col < end]} {
1459  return [$txt index "end-1 display chars"]
1460  }
1461 
1462  }
1463 
1464  } else {
1465 
1466  while {1} {
1467 
1468  set line [$txt get -displaychars $curr_row.0 $curr_row.end]
1469 
1470  while {1} {
1471  set char [string index $line $curr_col]
1472  if {[set isword [string is wordchar $char]] && [regexp -indices -- {\W\w*$} [string range $line 0 $curr_col] index]} {
1473  set curr_col [lindex $index 0]
1474  } elseif {[set isspace [string is space $char]] && [regexp -indices -- {\S\s*$} [string range $line 0 $curr_col] index]} {
1475  set curr_col [lindex $index 0]
1476  } elseif {!$isword && !$isspace && [regexp -indices -- {[\w\s][^\w\s]*$} [string range $line 0 $curr_col] index]} {
1477  set curr_col [lindex $index 0]
1478  } else {
1479  break
1480  }
1481  if {![string is space [string index $line $curr_col]] && ([incr num -1] == 0)} {
1482  return [$txt index "$curr_row.0 + $curr_col display chars"]
1483  }
1484  }
1485 
1486  lassign [split [$txt index "$curr_row.0 - 1 display chars"] .] curr_row curr_col
1487 
1488  if {![$txt compare $curr_row.$curr_col > 1.0]} {
1489  return "1.0"
1490  } elseif {![string is space [$txt index $curr_row.$curr_col]] && ([incr num -1] == 0)} {
1491  return [$txt index "$curr_row.0 + $curr_col display chars"]
1492  }
1493 
1494  }
1495 
1496  }
1497 
1498  }

§ get_WORDend()

edit::get_WORDend   txtt dir ?num? ?start? ?exclusive?  

Definition at line 1532 of file edit.tcl.

1532  proc get_WORDend {txtt dir {num 1} {start insert} {exclusive 0}} {
1533 
1534  if {$dir eq "next"} {
1535  set diropt "-forwards"
1536  set startpos "$start+1c"
1537  set endpos "end"
1538  set suffix "+1c"
1539  } else {
1540  set diropt "-backwards"
1541  set startpos $start
1542  set endpos "1.0"
1543  set suffix ""
1544  }
1545 
1546  while {[set index [$txtt search $diropt -regexp -- {\S\s|\n\n} $startpos $endpos]] ne ""} {
1547  if {[$txtt get $index] eq "\n"} {
1548  if {[incr num -1] == 0} {
1549  return [$txtt index $index+1c]
1550  }
1551  } else {
1552  if {[incr num -1] == 0} {
1553  return [$txtt index $index]
1554  }
1555  }
1556  set startpos "$index$suffix"
1557  }
1558 
1559  return $start
1560 
1561  }

§ get_wordstart()

edit::get_wordstart   txt dir ?num? ?start? ?exclusive?  

Definition at line 1363 of file edit.tcl.

1363  proc get_wordstart {txt dir {num 1} {start insert} {exclusive 0}} {
1364 
1365  lassign [split [$txt index $start] .] curr_row curr_col
1366 
1367  if {$dir eq "next"} {
1368 
1369  while {1} {
1370 
1371  set line [$txt get -displaychars $curr_row.0 $curr_row.end]
1372 
1373  while {1} {
1374  set char [string index $line $curr_col]
1375  if {[set isword [string is wordchar $char]] && [regexp -indices -start $curr_col -- {\W} $line index]} {
1376  set curr_col [lindex $index 1]
1377  } elseif {[set isspace [string is space $char]] && [regexp -indices -start $curr_col -- {\S} $line index]} {
1378  set curr_col [lindex $index 1]
1379  } elseif {!$isword && !$isspace && [regexp -indices -start $curr_col -- {[\w\s]} $line index]} {
1380  set curr_col [lindex $index 1]
1381  } else {
1382  break
1383  }
1384  if {![string is space [string index $line $curr_col]] && ([incr num -1] == 0)} {
1385  return [$txt index "$curr_row.0 + $curr_col display chars"]
1386  }
1387  }
1388 
1389  lassign [split [$txt index "$curr_row.end + 1 display chars"] .] curr_row curr_col
1390 
1391  if {![$txt compare $curr_row.$curr_col < end]} {
1392  return [$txt index "end-1 display chars"]
1393  } elseif {(![string is space [$txt index $curr_row.$curr_col]] || [$txt compare $curr_row.0 == $curr_row.end]) && ([incr num -1] == 0)} {
1394  return [$txt index "$curr_row.0 + $curr_col display chars"]
1395  }
1396 
1397  }
1398 
1399  } else {
1400 
1401  while {1} {
1402 
1403  set line [$txt get -displaychars $curr_row.0 $curr_row.$curr_col]
1404 
1405  while {1} {
1406  if {[regexp -indices -- {(\w+|\s+|[^\w\s]+)$} [string range $line 0 [expr $curr_col - 1]] index]} {
1407  set curr_col [lindex $index 0]
1408  } else {
1409  break
1410  }
1411  if {![string is space [string index $line $curr_col]] && ([incr num -1] == 0)} {
1412  return [$txt index "$curr_row.0 + $curr_col display chars"]
1413  }
1414  }
1415 
1416  lassign [split [$txt index "$curr_row.0 - 1 display chars"] .] curr_row curr_col
1417 
1418  if {![$txt compare $curr_row.$curr_col > 1.0]} {
1419  return "1.0"
1420  } elseif {(![string is space [string index $line $curr_col]] || ($curr_col == 0)) && ([incr num -1] == 0)} {
1421  return [$txt index "$curr_row.0 + $curr_col display chars"]
1422  }
1423 
1424  }
1425 
1426  }
1427 
1428  }

§ get_WORDstart()

edit::get_WORDstart   txtt dir ?num? ?start? ?exclusive?  

Definition at line 1504 of file edit.tcl.

1504  proc get_WORDstart {txtt dir {num 1} {start insert} {exclusive 0}} {
1505 
1506  if {$dir eq "next"} {
1507  set diropt "-forwards"
1508  set startpos $start
1509  set endpos "end"
1510  set suffix "+1c"
1511  } else {
1512  set diropt "-backwards"
1513  set startpos "$start-1c"
1514  set endpos "1.0"
1515  set suffix ""
1516  }
1517 
1518  while {[set index [$txtt search $diropt -regexp -- {\s\S|\n\n} $startpos $endpos]] ne ""} {
1519  if {[incr num -1] == 0} {
1520  return [$txtt index $index+1c]
1521  }
1522  set startpos "$index$suffix"
1523  }
1524 
1525  return $start
1526 
1527  }

§ indent()

edit::indent   txtt ?startpos? ?endpos?  

Definition at line 1191 of file edit.tcl.

1191  proc indent {txtt {startpos "insert"} {endpos "insert"}} {
1192 
1193  if {![indent_selected $txtt]} {
1194  do_indent $txtt $startpos $endpos
1195  ::tk::TextSetCursor $txtt [get_index $txtt firstchar -startpos $startpos -num 0]
1196  }
1197 
1198  }

§ indent_selected()

edit::indent_selected   txtt  

Definition at line 1174 of file edit.tcl.

1174  proc indent_selected {txtt} {
1175 
1176  if {[llength [set range [$txtt tag ranges sel]]] > 0} {
1177  foreach {endpos startpos} [lreverse $range] {
1178  do_indent $txtt $startpos $endpos
1179  }
1180  ::tk::TextSetCursor $txtt [get_index $txtt firstchar -startpos $startpos -num 0]
1181  return 1
1182  }
1183 
1184  return 0
1185 
1186  }

§ insert_enumeration()

edit::insert_enumeration

Definition at line 1286 of file edit.tcl.

1286  proc insert_enumeration {} {
1287 
1288  # Get the current text widget
1289  set txt [gui::current_txt]
1290 
1291  # Perform the insertion
1292  gui::insert_numbers $txt
1293 
1294  }

§ insert_file()

edit::insert_file   txt fname  

Definition at line 93 of file edit.tcl.

93  proc insert_file {txt fname} {
94 
95  # Attempt to open the file
96  if {[catch { open $fname r} rc]} {
97  return
98  }
99 
100  # Read the contents of the file and close the file
101  set contents [read $rc]
102  close $rc
103 
104  # Insert the file contents beneath the current insertion line
105  $txt insert "insert lineend" "\n$contents"
106 
107  # Adjust the insertion point, if necessary
108  vim::adjust_insert $txt
109 
110  }

§ insert_line_above_current()

edit::insert_line_above_current   txtt  

Definition at line 45 of file edit.tcl.

45  proc insert_line_above_current {txtt} {
46 
47  # If we are operating in Vim mode,
48  vim::edit_mode $txtt
49 
50  # Create the new line
51  if {[multicursor::enabled $txtt]} {
52  multicursor::move $txtt up
53  } elseif {[$txtt compare "insert linestart" == 1.0]} {
54  $txtt insert "insert linestart" "\n"
55  ::tk::TextSetCursor $txtt "insert-1l"
56  } else {
57  ::tk::TextSetCursor $txtt "insert-1l lineend"
58  $txtt insert "insert lineend" "\n"
59  }
60 
61  indent::newline $txtt insert 1
62 
63  }

§ insert_line_below_current()

edit::insert_line_below_current   txtt  

Definition at line 67 of file edit.tcl.

67  proc insert_line_below_current {txtt} {
68 
69  # If we are operating in Vim mode, switch to edit mode
70  vim::edit_mode $txtt
71 
72  # Get the current insertion point
73  set insert [$txtt index insert]
74 
75  # Add the line(s)
76  if {[multicursor::enabled $txtt]} {
77  multicursor::move $txtt down
78  } else {
79  ::tk::TextSetCursor $txtt "insert lineend"
80  $txtt insert "insert lineend" "\n"
81  }
82 
83  # Make sure the inserted text is seen
84  $txtt see insert
85 
86  # Perform the proper indentation
87  indent::newline $txtt insert 1
88 
89  }

§ jump_to_line()

edit::jump_to_line   txt linenum  

Definition at line 1298 of file edit.tcl.

1298  proc jump_to_line {txt linenum} {
1299 
1300  # Set the insertion cursor to the given line number
1301  ::tk::TextSetCursor $txt $linenum
1302 
1303  # Adjust the insertion cursor
1304  vim::adjust_insert $txt
1305 
1306  }

§ move_cursor()

edit::move_cursor   txtt position args  

Definition at line 2196 of file edit.tcl.

2196  proc move_cursor {txtt position args} {
2197 
2198  # Get the index to move to
2199  set index [get_index $txtt $position {*}$args]
2200 
2201  # Set the insertion position and make it visible
2202  ::tk::TextSetCursor $txtt $index
2203 
2204  # Adjust the insertion cursor in Vim mode
2205  vim::adjust_insert $txtt
2206 
2207  }

§ move_cursor_by_page()

edit::move_cursor_by_page   txtt dir  

Definition at line 2213 of file edit.tcl.

2213  proc move_cursor_by_page {txtt dir} {
2214 
2215  # Adjust the view
2216  eval [string map {%W $txtt} [bind Text <[string totitle $dir]>]]
2217 
2218  # Adjust the insertion cursor in Vim mode
2219  vim::adjust_insert $txtt
2220 
2221  }

§ move_cursors()

edit::move_cursors   txtt modifier  

Definition at line 2225 of file edit.tcl.

2225  proc move_cursors {txtt modifier} {
2226 
2227  variable columns
2228 
2229  # Clear the selection
2230  $txtt tag remove sel 1.0 end
2231 
2232  set columns ""
2233 
2234  # Adjust the cursors
2235  multicursor::move $txtt [list $modifier -column edit::columns]
2236 
2237  }

§ newline_count()

edit::newline_count   str  

Definition at line 754 of file edit.tcl.

754  proc newline_count {str} {
755 
756  return [expr {[string length $str] - [string length [string map {\n {}} $str]]}]
757 
758  }

§ replace_line_with_script()

edit::replace_line_with_script

Definition at line 1231 of file edit.tcl.

1231  proc replace_line_with_script {} {
1232 
1233  # Get the current text widget
1234  set txt [gui::current_txt]
1235 
1236  # Get the current line
1237  set cmd [$txt get "insert linestart" "insert lineend"]
1238 
1239  # Execute the line text
1240  catch { exec -ignorestderr {*}$cmd} rc
1241 
1242  # Replace the line with the given text
1243  $txt replace "insert linestart" "insert lineend" $rc
1244 
1245  }

§ save_selection()

edit::save_selection   txt from to overwrite fname  

Definition at line 917 of file edit.tcl.

917  proc save_selection {txt from to overwrite fname} {
918 
919  if {!$overwrite && [file exists $fname]} {
920  gui::set_info_message [::format "%s (%s)" [msgcat::mc "Filename already exists"] $fname]
921  return 0
922  } else {
923  if {[catch { open $fname w} rc]} {
924  gui::set_info_message [::format "%s %s" [msgcat::mc "Unable to write"] $fname]
925  return 0
926  } else {
927  puts $rc [$txt get $from $to]
928  close $rc
929  gui::set_info_message [::format "%s (%s)" [msgcat::mc "File successfully written"] $fname]
930  }
931  }
932 
933  return 1
934 
935  }

§ transform_bubble_down()

edit::transform_bubble_down   txtt  

Definition at line 838 of file edit.tcl.

838  proc transform_bubble_down {txtt} {
839 
840  # Create undo separator
841  $txtt edit separator
842 
843  # If lines are selected, move all selected lines down one line
844  if {[llength [set selected [$txtt tag ranges sel]]] > 0} {
845 
846  switch [set type [select::get_type $txtt]] {
847  none -
848  line {
849  foreach {end_range start_range} [lreverse $selected] {
850  set str [$txtt get "$end_range+1l linestart" "$end_range+2l linestart"]
851  $txtt delete "$end_range lineend" "$end_range+1l lineend"
852  $txtt insert "$start_range linestart" $str
853  }
854  }
855  sentence {
856  set startpos [get_index $txtt $type -dir prev -startpos [lindex $selected 0]]
857  set endpos [get_index $txtt $type -dir next -startpos "[lindex $selected end]+1 display chars"]
858  regexp {^(.*?)(\s*)$} [$txtt get $startpos [lindex $selected 0]] -> pstr pbetween
859  regexp {^(.*?)(\s*)$} [$txtt get [lindex $selected 0] [lindex $selected end]] -> cstr cbetween
860  regexp {^(.*?)(\s*)$} [$txtt get [lindex $selected end] $endpos] -> astr abetween
861  if {[newline_count $cbetween] >= 2} {
862  set index [$txtt index "[lindex $selected 0]+[string length $cstr]c"]
863  $txtt tag remove sel $index [lindex $selected end]
864  if {$astr eq ""} {
865  $txtt insert [lindex $selected end] $cstr sel
866  } else {
867  $txtt insert [lindex $selected end] "$cstr " sel
868  }
869  $txtt delete "[lindex $selected 0]-[string length $pbetween]c" $index
870  } elseif {[newline_count $abetween] >= 2} {
871  set index [$txtt index "[lindex $selected end]+[string length $astr]c"]
872  $txtt tag add sel $index $endpos
873  $txtt insert $index $cbetween {} $cstr sel
874  $txtt delete [lindex $selected 0] [lindex $selected end]
875  } elseif {$abetween eq ""} {
876  $txtt delete "[lindex $selected end]-[string length $cbetween]c" $endpos
877  $txtt insert [lindex $selected 0] $astr$cbetween
878  } else {
879  $txtt delete [lindex $selected end] $endpos
880  $txtt insert [lindex $selected 0] $astr$cbetween
881  }
882  }
883  paragraph {
884  set endpos [get_index $txtt $type -dir next -startpos "[lindex $selected end]+1 display chars"]
885  set str [string trimright [$txtt get [lindex $selected end] $endpos]]
886  regexp {(\s*)$} [$txtt get {*}$selected] -> between
887  $txtt delete [lindex $selected end] $endpos
888  $txtt insert [lindex $selected 0] $str$between
889  }
890  node {
891  if {[set range [select::node_next_sibling $txtt "[lindex $selected end]-1c"]] ne ""} {
892  set str [$txtt get {*}$range]
893  set between [$txtt get [lindex $selected end] [lindex $range 0]]
894  $txtt delete [lindex $selected end] [lindex $range end]
895  $txtt insert [lindex $selected 0] $str$between
896  }
897  }
898  }
899 
900  # Otherwise, move the current line down by one line
901  } else {
902  set str [$txtt get "insert+1l linestart" "insert+2l linestart"]
903  $txtt delete "insert lineend" "insert+1l lineend"
904  $txtt insert "insert linestart" $str
905  }
906 
907  # Create undo separator
908  $txtt edit separator
909 
910  }

§ transform_bubble_up()

edit::transform_bubble_up   txtt  

Definition at line 762 of file edit.tcl.

762  proc transform_bubble_up {txtt} {
763 
764  # Create undo separator
765  $txtt edit separator
766 
767  # If lines are selected, move all selected lines up one line
768  if {[llength [set selected [$txtt tag ranges sel]]] > 0} {
769 
770  switch [set type [select::get_type $txtt]] {
771  none -
772  line {
773  foreach {end_range start_range} [lreverse $selected] {
774  set str [$txtt get "$start_range-1l linestart" "$start_range linestart"]
775  $txtt delete "$start_range-1l linestart" "$start_range linestart"
776  if {[$txtt compare "$end_range linestart" == end]} {
777  set str "\n[string trimright $str]"
778  }
779  $txtt insert "$end_range linestart" $str
780  }
781  }
782  sentence {
783  set startpos [get_index $txtt $type -dir prev -startpos [lindex $selected 0]]
784  regexp {^(.*?)(\s*)$} [$txtt get $startpos [lindex $selected 0]] -> pstr pbetween
785  regexp {^(.*?)(\s*)$} [$txtt get [lindex $selected 0] [lindex $selected end]] -> cstr cbetween
786  if {$cbetween eq ""} {
787  set cbetween " "
788  }
789  if {[newline_count $pbetween] >= 2} {
790  set wo_ws [string trimright [set full [$txtt get [lindex $selected 0] [lindex $selected end]]]]
791  set eos [$txtt index "[lindex $selected 0]+[string length $wo_ws]c"]
792  $txtt delete $eos [lindex $selected end]
793  $txtt insert $eos $pbetween sel
794  $txtt replace "[lindex $selected 0]-[string length $pbetween]c" [lindex $selected 0] " "
795  } elseif {[newline_count $cbetween] >= 2} {
796  set index [$txtt index "[lindex $selected end]-[string length $cbetween]c"]
797  $txtt insert $index $pbetween$pstr
798  $txtt tag remove sel "$index+[string length $pbetween]c" [lindex $selected end]
799  $txtt delete $startpos [lindex $selected 0]
800  } else {
801  $txtt insert [lindex $selected end] $pstr$pbetween
802  $txtt delete $startpos [lindex $selected 0]
803  }
804  }
805  paragraph {
806  set startpos [get_index $txtt $type -dir prev -startpos [lindex $selected 0]]
807  regexp {^(.*)(\s*)$} [$txtt get $startpos [lindex $selected 0]] -> str between
808  $txtt insert [lindex $selected end] $between$str
809  $txtt delete $startpos [lindex $selected 0]
810  }
811  node {
812  if {[set range [select::node_prev_sibling $txtt [lindex $selected 0]]] ne ""} {
813  set str [$txtt get {*}$range]
814  set between [$txtt get [lindex $range 1] [lindex $selected 0]]
815  $txtt insert [lindex $selected end] $between$str
816  $txtt delete [lindex $range 0] [lindex $selected 0]
817  }
818  }
819  }
820 
821  # Otherwise, move the current line up by one line
822  } else {
823  set str [$txtt get "insert-1l linestart" "insert linestart"]
824  $txtt delete "insert-1l linestart" "insert linestart"
825  if {[$txtt compare "insert+1l linestart" == end]} {
826  set str "\n[string trimright $str]"
827  }
828  $txtt insert "insert+1l linestart" $str
829  }
830 
831  # Create undo separator
832  $txtt edit separator
833 
834  }

§ transform_join_lines()

edit::transform_join_lines   txtt ?num?  

Definition at line 682 of file edit.tcl.

682  proc transform_join_lines {txtt {num 1}} {
683 
684  # Specifies if at least one line was deleted in the join
685  set deleted 0
686 
687  # Create a separator
688  $txtt edit separator
689 
690  if {[llength [set selected [$txtt tag ranges sel]]] > 0} {
691 
692  # Clear the selection
693  $txtt tag remove sel 1.0 end
694 
695  set lastpos ""
696  foreach {endpos startpos} [lreverse $selected] {
697  set lines [$txtt count -lines $startpos $endpos]
698  for {set i 0} {$i < $lines} {incr i} {
699  set line [string trimleft [$txtt get "$startpos+1l linestart" "$startpos+1l lineend"]]
700  $txtt delete "$startpos lineend" "$startpos+1l lineend"
701  if {![string is space [$txtt get "$startpos lineend-1c"]]} {
702  set line " $line"
703  }
704  if {$line ne ""} {
705  $txtt insert "$startpos lineend" $line
706  }
707  }
708  set deleted [expr $deleted || ($lines > 0)]
709  if {$lastpos ne ""} {
710  set line [string trimleft [$txtt get "$lastpos linestart" "$lastpos lineend"]]
711  $txtt delete "$lastpos-1l lineend" "$lastpos lineend"
712  if {![string is space [$txtt get "$startpos lineend-1c"]]} {
713  set line " $line"
714  }
715  $txtt insert "$startpos lineend" $line
716  }
717  set lastpos $startpos
718  }
719 
720  set index [$txtt index "$startpos lineend-[string length $line]c"]
721 
722  } elseif {[$txtt compare "insert+1l" < end]} {
723 
724  for {set i 0} {$i < $num} {incr i} {
725  set line [string trimleft [$txtt get "insert+1l linestart" "insert+1l lineend"]]
726  $txtt delete "insert lineend" "insert+1l lineend"
727  if {![string is space [$txtt get "insert lineend-1c"]]} {
728  set line " $line"
729  }
730  if {$line ne ""} {
731  $txtt insert "insert lineend" $line
732  }
733  }
734 
735  set deleted [expr $num > 0]
736  set index [$txtt index "insert lineend-[string length $line]c"]
737 
738  }
739 
740  if {$deleted} {
741 
742  # Set the insertion cursor and make it viewable
743  ::tk::TextSetCursor $txtt $index
744 
745  # Create a separator
746  $txtt edit separator
747 
748  }
749 
750  }

§ transform_to_lower_case()

edit::transform_to_lower_case   txtt startpos endpos ?cursorpos?  

Definition at line 596 of file edit.tcl.

596  proc transform_to_lower_case {txtt startpos endpos {cursorpos insert}} {
597 
598  if {![transform_to_lower_case_selected $txtt]} {
599  convert_to_lower_case $txtt $startpos $endpos
600  ::tk::TextSetCursor $txtt $cursorpos
601  }
602 
603  }

§ transform_to_lower_case_selected()

edit::transform_to_lower_case_selected   txtt  

Definition at line 580 of file edit.tcl.

580  proc transform_to_lower_case_selected {txtt} {
581 
582  if {[llength [set ranges [$txtt tag ranges sel]]] > 0} {
583  foreach {endpos startpos} [lreverse $ranges] {
584  convert_to_lower_case $txtt $startpos $endpos
585  }
586  ::tk::TextSetCursor $txtt $startpos
587  return 1
588  }
589 
590  return 0
591 
592  }

§ transform_to_rot13()

edit::transform_to_rot13   txtt startpos endpos ?cursorpos?  

Definition at line 652 of file edit.tcl.

652  proc transform_to_rot13 {txtt startpos endpos {cursorpos insert}} {
653 
654  if {![transform_to_rot13_selected $txtt]} {
655  convert_to_rot13 $txtt $startpos $endpos
656  ::tk::TextSetCursor $txtt $cursorpos
657  }
658 
659  }

§ transform_to_rot13_selected()

edit::transform_to_rot13_selected   txtt  

Definition at line 636 of file edit.tcl.

636  proc transform_to_rot13_selected {txtt} {
637 
638  if {[llength [set ranges [$txtt tag ranges sel]]] > 0} {
639  foreach {endpos startpos} [lreverse $ranges] {
640  convert_to_rot13 $txtt $startpos $endpos
641  }
642  ::tk::TextSetCursor $txtt $startpos
643  return 1
644  }
645 
646  return 0
647 
648  }

§ transform_to_title_case()

edit::transform_to_title_case   txtt startpos endpos ?cursorpos?  

Definition at line 663 of file edit.tcl.

663  proc transform_to_title_case {txtt startpos endpos {cursorpos insert}} {
664 
665  if {[llength [set sel_ranges [$txtt tag ranges sel]]] > 0} {
666  foreach {endpos startpos} [lreverse $sel_ranges] {
667  convert_case_to_title $txtt [$txtt index "$startpos wordstart"] $endpos
668  }
669  ::tk::TextSetCursor $txtt $startpos
670  } else {
671  set str [$txtt get "insert wordstart" "insert wordend"]
672  convert_case_to_title $txtt [$txtt index "$startpos wordstart"] $endpos
673  ::tk::TextSetCursor $txtt $cursorpos
674  }
675 
676  }

§ transform_to_upper_case()

edit::transform_to_upper_case   txtt startpos endpos ?cursorpos?  

Definition at line 624 of file edit.tcl.

624  proc transform_to_upper_case {txtt startpos endpos {cursorpos insert}} {
625 
626  if {![transform_to_upper_case_selected $txtt]} {
627  convert_to_upper_case $txtt $startpos $endpos
628  ::tk::TextSetCursor $txtt $cursorpos
629  }
630 
631  }

§ transform_to_upper_case_selected()

edit::transform_to_upper_case_selected   txtt  

Definition at line 608 of file edit.tcl.

608  proc transform_to_upper_case_selected {txtt} {
609 
610  if {[llength [set ranges [$txtt tag ranges sel]]] > 0} {
611  foreach {endpos startpos} [lreverse $ranges] {
612  convert_to_upper_case $txtt $startpos $endpos
613  }
614  ::tk::TextSetCursor $txtt $startpos
615  return 1
616  }
617 
618  return 0
619 
620  }

§ transform_toggle_case()

edit::transform_toggle_case   txtt startpos endpos ?cursorpos?  

Definition at line 568 of file edit.tcl.

568  proc transform_toggle_case {txtt startpos endpos {cursorpos insert}} {
569 
570  if {![transform_toggle_case_selected $txtt]} {
571  convert_case_toggle $txtt $startpos $endpos
572  ::tk::TextSetCursor $txtt $cursorpos
573  }
574 
575  }

§ transform_toggle_case_selected()

edit::transform_toggle_case_selected   txtt  

Definition at line 552 of file edit.tcl.

552  proc transform_toggle_case_selected {txtt} {
553 
554  if {[llength [set ranges [$txtt tag ranges sel]]] > 0} {
555  foreach {endpos startpos} [lreverse $ranges] {
556  convert_case_toggle $txtt $startpos $endpos
557  }
558  ::tk::TextSetCursor $txtt $startpos
559  return 1
560  }
561 
562  return 0
563 
564  }

§ uncomment()

edit::uncomment

Definition at line 1027 of file edit.tcl.

1027  proc uncomment {} {
1028 
1029  # Get the current text widget
1031 
1032  }

§ uncomment_text()

edit::uncomment_text   txt  

Definition at line 992 of file edit.tcl.

992  proc uncomment_text {txt} {
993 
994  # Create a separator
995  $txt edit separator
996 
997  # Get the selection ranges
998  set selected [$txt tag ranges sel]
999 
1000  # Get the comment syntax
1001  lassign [syntax::get_comments $txt] icomment lcomments bcomments
1002 
1003  # Get the comment syntax to remove
1004  set comments [join [eval concat $lcomments $bcomments] |]
1005 
1006  # Strip out comment syntax
1007  foreach {endpos startpos} [lreverse $selected] {
1008  set linestart $startpos
1009  foreach line [split [$txt get $startpos $endpos] \n] {
1010  if {[regexp -indices -- "($comments)+?" $line -> com]} {
1011  set delstart [$txt index "$linestart+[lindex $com 0]c"]
1012  set delend [$txt index "$linestart+[expr [lindex $com 1] + 1]c"]
1013  $txt delete $delstart $delend
1014  }
1015  set linestart [$txt index "$linestart+1l linestart"]
1016  incr i
1017  }
1018  }
1019 
1020  # Create a separator
1021  $txt edit separator
1022 
1023  }

§ unformat()

edit::unformat   txtt  

Definition at line 2348 of file edit.tcl.

2348  proc unformat {txtt} {
2349 
2350  # Get the formatting information for the current text widget
2351  array set formatting [syntax::get_formatting [winfo parent $txtt]]
2352 
2353  # Get the range of lines to check
2354  if {[set ranges [$txtt tag ranges sel]] eq ""} {
2355  if {[multicursor::enabled $txtt]} {
2356  set last ""
2357  foreach {start end} [$txtt tag ranges mcursor] {
2358  if {($last eq "") || [$txtt compare "$start linestart" != "$last linestart"]} {
2359  lappend ranges [$txtt index "$start linestart"] [$txtt index "$start lineend"]
2360  set last $start
2361  }
2362  }
2363  } else {
2364  set ranges [list [$txtt index "insert linestart"] [$txtt index "insert lineend"]]
2365  }
2366  }
2367 
2368  # If we have at least one range to unformat, go for it
2369  if {[llength $ranges] > 0} {
2370 
2371  $txtt edit separator
2372 
2373  foreach {type chars} [array get formatting] {
2374  lassign $chars stype pattern
2375  set new_ranges [list]
2376  set metalen [string length [string map {\{REF\} {} \{TEXT\} {}} $pattern]]
2377  set pattern [string map {\{REF\} {.*?} \{TEXT\} {(.*?)} \{ \\\{ \} \\\} * \\* + \\+ \\ \\\\ \( \\\( \) \\\) \[ \\\[ \] \\\] \. \\\. \? \\\? ^ \\\^ \$ \\\$} $pattern]
2378  set pattern [regsub -all {\n\s*} $pattern {\s+}]
2379  if {$stype eq "line"} {
2380  set pattern "^$pattern\$"
2381  }
2382  foreach {end start} [lreverse $ranges] {
2383  set i 0
2384  foreach index [$txtt search -all -count lengths -regexp -- $pattern $start $end] {
2385  regexp $pattern [$txtt get $index "$index+[lindex $lengths $i]c"] -> str
2386  $txtt replace $index "$index+[lindex $lengths $i]c" $str
2387  incr i
2388  }
2389  lappend new_ranges [$txtt index "$end-[expr $metalen * $i]c"] $start
2390  }
2391  set ranges [lreverse $new_ranges]
2392  set new_ranges [list]
2393  }
2394 
2395  $txtt edit separator
2396 
2397  }
2398 
2399  }

§ unindent()

edit::unindent   txtt ?startpos? ?endpos?  

Definition at line 1220 of file edit.tcl.

1220  proc unindent {txtt {startpos "insert"} {endpos "insert"}} {
1221 
1222  if {![unindent_selected $txtt]} {
1223  do_unindent $txtt $startpos $endpos
1224  ::tk::TextSetCursor $txtt [get_index $txtt firstchar -startpos $startpos -num 0]
1225  }
1226 
1227  }

§ unindent_selected()

edit::unindent_selected   txtt  

Definition at line 1203 of file edit.tcl.

1203  proc unindent_selected {txtt} {
1204 
1205  if {[llength [set range [$txtt tag ranges sel]]] > 0} {
1206  foreach {endpos startpos} [lreverse $range] {
1207  do_unindent $txtt $startpos $endpos
1208  }
1209  ::tk::TextSetCursor $txtt [get_index $txtt firstchar -startpos $startpos -num 0]
1210  return 1
1211  }
1212 
1213  return 0
1214 
1215  }