TKE  3.6
Advanced code editor for programmers
emmet Namespace Reference

Functions

 load
 
 get_snippet_text_pos
 
 expand_abbreviation
 
 edit_abbreviations
 
 load_custom_aliases args
 
 update_alias type curr_alias new_alias value
 
 lookup_alias_helper type alias
 
 lookup_node_alias alias
 
 lookup_abbr_alias alias
 
 get_aliases
 
 get_tag txt args
 
 inside_tag txt args
 
 get_node_range_within txt args
 
 get_node_range txt args
 
 get_outer node_range
 
 get_inner node_range
 
 wrap_with_abbreviation args
 
 go_to_matching_pair
 
 balance_outward
 
 balance_inward
 
 get_tag_attributes txt tag_info
 
 get_blank_line txt dir startpos endpos
 
 go_to_edit_point dir
 
 select_html_attr_value txt dir selected attr_value attr_value_start
 
 select_html_item txt dir
 
 select_item dir
 
 toggle_html_comment txt
 
 toggle_comment
 
 split_join_tag
 
 remove_tag
 
 merge_lines
 
 update_html_image_size txt
 
 update_image_size
 
 change_number amount
 
 evaluate_math_expression
 
 replace_data_url txt startpos endpos url args
 
 encode_decode_html_image_to_data_url txt args
 
 encode_decode_image_to_data_url args
 
 view_reference
 
 get_share_items dir
 
 share_changed dir
 

Function Documentation

§ balance_inward()

emmet::balance_inward

Definition at line 570 of file emmet.tcl.

570  proc balance_inward {} {
571 
572  # Get the current text widget
573  set txt [gui::current_txt]
574 
575  # If we already have a selection, perform the inward balance
576  if {[llength [$txt tag ranges sel]] == 2} {
577  if {([inside_tag $txt] eq "") || ([set tag_range [get_inner [get_node_range $txt]]] eq "")} {
578  if {([set retval [get_tag $txt -dir next -type 100]] ne "") && ([lindex $retval 4] eq "")} {
579  ::tk::TextSetCursor $txt [lindex $retval 0]
580  if {[set tag_range [get_outer [get_node_range $txt]]] eq ""} {
581  return
582  }
583  } else {
584  return
585  }
586  }
587 
588  # Set the cursor and the selection
589  ::tk::TextSetCursor $txt [lindex $tag_range 0]
590  $txt tag add sel {*}$tag_range
591 
592  # Otherwise, perform an outward balance to make the selection
593  } else {
594 
596 
597  }
598 
599  }

§ balance_outward()

emmet::balance_outward

Definition at line 529 of file emmet.tcl.

529  proc balance_outward {} {
530 
531  variable data
532 
533  array set other $data(other_map)
534  array set dir $data(dir_map)
535  array set index $data(index_map)
536 
537  # Get the current text widget
538  set txt [gui::current_txt]
539 
540  # Adjust the insertion cursor if we are on a starting tag and there
541  # is a selection.
542  if {[$txt tag ranges sel] ne ""} {
543  $txt mark set insert "insert-1c"
544  }
545 
546  # If the insertion cursor is on a tag, get the outer node range
547  if {[set node_range [get_node_range $txt]] eq ""} {
548  $txt mark set insert "insert+1c"
549  return
550  }
551 
552  # Set the cursor at the beginning of the range
553  if {[$txt compare [lindex $node_range 1] <= insert] && [$txt compare insert < [lindex $node_range 2]]} {
554  set node_range [get_inner $node_range]
555  } else {
556  set node_range [get_outer $node_range]
557  }
558 
559  # Set the cursor position
560  ::tk::TextSetCursor $txt [lindex $node_range 0]
561 
562  # Select the current range
563  $txt tag add sel {*}$node_range
564 
565  }

§ change_number()

emmet::change_number   amount  

Definition at line 1174 of file emmet.tcl.

1174  proc change_number {amount} {
1175 
1176  set txt [gui::current_txt]
1177 
1178  # Get the range of the number
1179  if {[$txt get insert] eq "-"} {
1180  set num_start "insert"
1181  set num_end [edit::get_index $txt.t numberend -startpos "insert+1c" -adjust "+1c"]
1182  if {[$txt compare $num_end == "insert+1c"]} {
1183  return
1184  }
1185  } else {
1186  set num_start [edit::get_index $txt.t numberstart]
1187  set num_end [edit::get_index $txt.t numberend -adjust "+1c"]
1188  if {[$txt compare $num_start == $num_end] || [$txt compare insert == $num_end]} {
1189  return
1190  }
1191  if {([$txt get "$num_start-1c"] eq "-") && ![$txt is escaped "$num_start-1c"]} {
1192  set num_start "$num_start-1c"
1193  }
1194  }
1195 
1196  # Get the number and only continue on if the value is not a hexidecimal
1197  if {[string range [set number [$txt get $num_start $num_end]] 0 1] ne "0x"} {
1198 
1199  # Get the decimal portions of the text number and the increment/decrement
1200  # amount
1201  set number_len [string length [lindex [split $number .] 1]]
1202  set amount_len [string length [lindex [split $amount .] 1]]
1203  set number [expr $number + $amount]
1204 
1205  # Figure out the numerical formatting
1206  if {($number_len != 0) || ($amount_len != 0)} {
1207  if {$number_len < $amount_len} {
1208  set number [format "%.${amount_len}f" $number]
1209  if {[lindex [split $number .] 1] eq "0"} {
1210  set number [expr int( $number )]
1211  }
1212  } else {
1213  set number [format "%.${number_len}f" $number]
1214  if {[lindex [split $number .] 1] eq "0"} {
1215  set number [expr int( $number )]
1216  }
1217  }
1218  }
1219 
1220  # Get the insertion cursor position
1221  set cursor [$txt index insert]
1222 
1223  # Insert the number
1224  $txt replace $num_start $num_end $number
1225 
1226  # Set the cursor
1227  ::tk::TextSetCursor $txt.t $cursor
1228 
1229  # Create an undo separator
1230  $txt edit separator
1231 
1232  }
1233 
1234  }

§ edit_abbreviations()

emmet::edit_abbreviations

Definition at line 145 of file emmet.tcl.

145  proc edit_abbreviations {} {
146 
147  pref_ui::create "" "" emmet "Node Aliases"
148 
149  }

§ encode_decode_html_image_to_data_url()

emmet::encode_decode_html_image_to_data_url   txt args  

Definition at line 1321 of file emmet.tcl.

1321  proc encode_decode_html_image_to_data_url {txt args} {
1322 
1323  if {([set retval [inside_tag $txt -allow010 1]] eq "") || [string match "001" [lindex $retval 3]] || ([lindex $retval 2] ne "img")} {
1324  return
1325  }
1326 
1327  # Find the URL in the current img tag
1328  set url ""
1329  foreach {attr_name attr_name_start attr_value attr_value_start} [get_tag_attributes $txt $retval] {
1330  if {($attr_name eq "src") && \
1331  [$txt compare $attr_value_start <= insert] && \
1332  [$txt compare insert <= "$attr_value_start+[string length $attr_value]c"]} {
1333  set url $attr_value
1334  set startpos $attr_value_start
1335  set endpos [$txt index "$attr_value_start+[string length $attr_value]c"]
1336  break
1337  }
1338  }
1339 
1340  if {$url eq ""} {
1341  return
1342  }
1343 
1344  # Perform the replacement
1345  replace_data_url $txt $startpos $endpos $url {*}$args
1346 
1347  }

§ encode_decode_image_to_data_url()

emmet::encode_decode_image_to_data_url   args  

Definition at line 1351 of file emmet.tcl.

1351  proc encode_decode_image_to_data_url {args} {
1352 
1353  # Get the current text widget
1354  set txt [gui::current_txt]
1355 
1356  # Get the language of the current insertion cursor
1357  if {[set lang [ctext::getLang $txt insert]] eq ""} {
1358  set lang [syntax::get_language $txt]
1359  }
1360 
1361  if {$lang eq "CSS"} {
1363  } else {
1365  }
1366 
1367  }

§ evaluate_math_expression()

emmet::evaluate_math_expression

Definition at line 1238 of file emmet.tcl.

1238  proc evaluate_math_expression {} {
1239 
1240  set txt [gui::current_txt]
1241  set pre_match ""
1242  set post_match ""
1243 
1244  regexp {(\S+)$} [$txt get "insert linestart" insert] pre_match
1245  regexp {^(\S+)} [$txt get insert "insert lineend"] post_match
1246 
1247  if {[set expression "$pre_match$post_match"] ne ""} {
1248 
1249  # Attempt to evaluate the expression
1250  if {![catch { expr $expression} rc]} {
1251  set startpos [$txt index "insert-[string length $pre_match]c"]
1252  set endpos [$txt index "insert+[string length $post_match]c"]
1253  $txt replace $startpos $endpos $rc
1254  ::tk::TextSetCursor $txt $startpos
1255  $txt edit separator
1256  }
1257 
1258  }
1259 
1260  }

§ expand_abbreviation()

emmet::expand_abbreviation

Definition at line 110 of file emmet.tcl.

110  proc expand_abbreviation {} {
111 
112  set txt [gui::current_txt]
113 
114  # Get the language of the current insertion cursor
115  if {[set lang [ctext::getLang $txt insert]] eq ""} {
116  set lang [syntax::get_language $txt]
117  }
118 
119  # If the current language is CSS, translate the abbreviation as such
120  if {$lang eq "CSS"} {
121 
122  # Get the abbreviation text, translate it and insert it back into the text
123  if {[regexp {(\S+)$} [$txt get "insert linestart" insert] -> abbr]} {
124  if {![catch { emmet_css::parse $abbr} str]} {
125  snippets::insert_snippet_into_current $str -delrange [list "insert-[string length $abbr]c" insert] -separator 0
126  }
127  }
128 
129  } else {
130 
131  # Find the snippet text
132  lassign [get_snippet_text_pos] str startpos endpos prespace
133 
134  # Parse the snippet and if no error, insert the resulting string
135  if {![catch { ::parse_emmet $str $prespace} str]} {
136  snippets::insert_snippet_into_current $str -delrange [list $startpos $endpos] -separator 0
137  }
138 
139  }
140 
141  }

§ get_aliases()

emmet::get_aliases

Definition at line 235 of file emmet.tcl.

235  proc get_aliases {} {
236 
237  variable customizations
238 
239  return [array get customizations]
240 
241  }

§ get_blank_line()

emmet::get_blank_line   txt dir startpos endpos  

Definition at line 636 of file emmet.tcl.

636  proc get_blank_line {txt dir startpos endpos} {
637 
638  if {$dir eq "next"} {
639  if {[$txt compare $startpos >= "$startpos lineend-1 display chars"]} {
640  set startpos [$txt index "$startpos+1 display lines linestart"]
641  }
642  while {[$txt compare $startpos < $endpos]} {
643  if {([string trim [$txt get "$startpos linestart" "$startpos lineend"]] eq "") && \
644  ([$txt compare "$startpos linestart" != "$startpos lineend"])} {
645  return $startpos
646  }
647  set startpos [$txt index "$startpos+1 display lines"]
648  }
649  } else {
650  set startpos [$txt index "$startpos-1 display lines linestart"]
651  while {[$txt compare $startpos > $endpos]} {
652  if {([string trim [$txt get "$startpos linestart" "$startpos lineend"]] eq "") && \
653  ([$txt compare "$startpos linestart" != "$startpos lineend"])} {
654  return $startpos
655  }
656  set startpos [$txt index "$startpos-1 display lines"]
657  }
658  }
659 
660  return ""
661 
662  }

§ get_inner()

emmet::get_inner   node_range  

Definition at line 449 of file emmet.tcl.

449  proc get_inner {node_range} {
450 
451  if {$node_range ne ""} {
452  return [lrange $node_range 1 2]
453  }
454 
455  return ""
456 
457  }

§ get_node_range()

emmet::get_node_range   txt args  

Definition at line 393 of file emmet.tcl.

393  proc get_node_range {txt args} {
394 
395  variable data
396 
397  array set opts {
398  -startpos insert
399  }
400  array set opts $args
401 
402  array set other $data(other_map)
403  array set dir $data(dir_map)
404  array set index $data(index_map)
405 
406  # Check to see if the starting position is within a tag and if it is
407  # not, find the tags surrounding the starting position.
408  if {[set itag [inside_tag $txt -startpos $opts(-startpos) -allow010 1]] eq ""} {
409  return [get_node_range_within $txt -startpos $opts(-startpos)]
410  } elseif {[lindex $itag 3] eq "010"} {
411  return ""
412  }
413 
414  lassign $itag start end name type
415 
416  # If we are on a starting tag, look for the ending tag
417  set retval [list $start $end]
418  set others 0
419  while {1} {
420  if {[set retval [get_tag $txt -dir $dir($type) -name $name -type $other($type) -start [lindex $retval $index($type)]]] eq ""} {
421  return ""
422  }
423  if {[incr others [llength [lsearch -all [lindex $retval 4] $name,$type]]] == 0} {
424  switch $type {
425  "100" { return [list $start $end {*}[lrange $retval 0 1]]}
426  "001" { return [list {*}[lrange $retval 0 1] $start $end]}
427  default { return -code error "Error finding node range"}
428  }
429  }
430  incr others -1
431  }
432 
433  }

§ get_node_range_within()

emmet::get_node_range_within   txt args  

Definition at line 351 of file emmet.tcl.

351  proc get_node_range_within {txt args} {
352 
353  array set opts {
354  -startpos insert
355  }
356  array set opts $args
357 
358  # Find the beginning tag that we are currently inside of
359  set retval [list $opts(-startpos)]
360  set count 0
361 
362  while {1} {
363  if {[set retval [get_tag $txt -dir prev -type 100 -start [lindex $retval 0]]] eq ""} {
364  return ""
365  }
366  if {[incr count [expr [llength [lsearch -all [lindex $retval 4] *,100]] - [llength [lsearch -all [lindex $retval 4] *,001]]]] == 0} {
367  set start_range [lrange $retval 0 1]
368  set range_name [lindex $retval 2]
369  break
370  }
371  incr count
372  }
373 
374  # Find the ending tag based on the beginning tag
375  set retval [list {} $opts(-startpos)]
376  set count 0
377 
378  while {1} {
379  if {[set retval [get_tag $txt -dir next -type 001 -name $range_name -start [lindex $retval 1]]] eq ""} {
380  return ""
381  }
382  if {[incr count [llength [lsearch -all [lindex $retval 4] $range_name,100]]] == 0} {
383  return [list {*}$start_range {*}[lrange $retval 0 1]]
384  }
385  incr count -1
386  }
387 
388  }

§ get_outer()

emmet::get_outer   node_range  

Definition at line 437 of file emmet.tcl.

437  proc get_outer {node_range} {
438 
439  if {$node_range ne ""} {
440  return [list [lindex $node_range 0] [lindex $node_range 3]]
441  }
442 
443  return ""
444 
445  }

§ get_share_items()

emmet::get_share_items   dir  

Definition at line 1380 of file emmet.tcl.

1380  proc get_share_items {dir} {
1381 
1382  return [list emmet.tkedat]
1383 
1384  }

§ get_snippet_text_pos()

emmet::get_snippet_text_pos

Definition at line 66 of file emmet.tcl.

66  proc get_snippet_text_pos {} {
67 
68  variable data
69 
70  # Get the current text widget
71  set txt [gui::current_txt]
72 
73  # Get the current line and column numbers
74  lassign [split [$txt index insert] .] line endcol
75 
76  # Get the current line
77  set str [$txt get "insert linestart" insert]
78 
79  # Get the prespace of the current line
80  regexp {^([ \t]*)} $str -> prespace
81 
82  # If we have a tag, ignore all text prior to it
83  set startcol [expr {[regexp $data(tag) $str match] ? [string length $match] : 0}]
84 
85  # Gather the positions of any square or curly brackets in the left-over area
86  foreach key [list brackets space] {
87  set pos($key) [list]
88  set col $startcol
89  while {[regexp -start $col -- $data($key) $str match pre]} {
90  lappend pos($key) [expr $col + [string length $pre]] [expr $col + [string length $match]]
91  set col [lindex $pos($key) end]
92  }
93  }
94 
95  # See if there is a space which does not exist within a square or curly brace
96  foreach {endpos startpos} [lreverse $pos(space)] {
97  if {[expr [lsearch [lsort -integer [concat $pos(brackets) $endpos]] $endpos] % 2] == 0} {
98  return [list [string range $str $endpos end] $line.$endpos $line.$endcol $prespace]
99  }
100  }
101 
102  return [list [string range $str $startcol end] $line.$startcol $line.$endcol $prespace]
103 
104  }

§ get_tag()

emmet::get_tag   txt args  

Definition at line 256 of file emmet.tcl.

256  proc get_tag {txt args} {
257 
258  array set opts {
259  -dir "next"
260  -type "*"
261  -name "*"
262  -start "insert"
263  }
264  array set opts $args
265 
266  # Initialize counts
267  set missed [list]
268 
269  # Get the tag
270  if {$opts(-dir) eq "prev"} {
271  if {[set start [lindex [$txt syntax prevrange angledL $opts(-start)] 0]] eq ""} {
272  return ""
273  } elseif {[set end [lindex [$txt syntax nextrange angledR $start] 1]] eq ""} {
274  return ""
275  }
276  } else {
277  if {[set end [lindex [$txt syntax nextrange angledR $opts(-start)] 1]] eq ""} {
278  return ""
279  } elseif {[set start [lindex [$txt syntax prevrange angledL $end] 0]] eq ""} {
280  return ""
281  }
282  }
283 
284  while {1} {
285 
286  # Get the tag elements
287  if {[$txt get "$start+1c"] eq "/"} {
288  set found_type "001"
289  set found_name [regexp -inline -- {[a-zA-Z0-9_:-]+} [$txt get "$start+2c" "$end-1c"]]
290  } else {
291  if {[$txt get "$end-2c"] eq "/"} {
292  set found_type "010"
293  set found_name [regexp -inline -- {[a-zA-Z0-9_:-]+} [$txt get "$start+1c" "$end-2c"]]
294  } else {
295  set found_type "100"
296  set found_name [regexp -inline -- {[a-zA-Z0-9_:-]+} [$txt get "$start+1c" "$end-1c"]]
297  }
298  }
299 
300  # If we have found what we are looking for, return now
301  if {[string match $opts(-type) $found_type] && [string match $opts(-name) $found_name]} {
302  return [list $start $end $found_name $found_type $missed]
303  }
304 
305  # Update counts
306  lappend missed "$found_name,$found_type"
307 
308  # Otherwise, get the next tag
309  if {$opts(-dir) eq "prev"} {
310  if {[set end [lindex [$txt syntax prevrange angledR $start] 1]] eq ""} {
311  return ""
312  } elseif {[set start [lindex [$txt syntax prevrange angledL $end] 0]] eq ""} {
313  return ""
314  }
315  } else {
316  if {[set start [lindex [$txt syntax nextrange angledL $end] 0]] eq ""} {
317  return ""
318  } elseif {[set end [lindex [$txt syntax nextrange angledR $start] 1]] eq ""} {
319  return ""
320  }
321  }
322 
323  }
324 
325  }

§ get_tag_attributes()

emmet::get_tag_attributes   txt tag_info  

Definition at line 608 of file emmet.tcl.

608  proc get_tag_attributes {txt tag_info} {
609 
610  lassign $tag_info start end name type
611 
612  # Attributes cannot exist in ending attributes, so just return
613  if {$type eq "001"} {
614  return [list]
615  }
616 
617  # Get the attribute contents after the tag name
618  set start [$txt index "$start+[expr [string length $name] + 1]c"]
619  set contents [$txt get $start "$end-1c"]
620 
621  set attrs [list]
622  while {[regexp {^(\s*)(\w+)="(.*?)"(.*)$} $contents -> prespace attr_name attr_value contents]} {
623  set attr_name_start [$txt index "$start+[string length $prespace]c"]
624  set attr_val_start [$txt index "$attr_name_start+[expr [string length $attr_name] + 2]c"]
625  lappend attrs $attr_name $attr_name_start $attr_value $attr_val_start
626  set start [$txt index "$attr_val_start+[expr [string length $attr_value] + 1]c"]
627  }
628 
629  return $attrs
630 
631  }

§ go_to_edit_point()

emmet::go_to_edit_point   dir  

Definition at line 666 of file emmet.tcl.

666  proc go_to_edit_point {dir} {
667 
668  # Get the current text widget
669  set txt [gui::current_txt]
670 
671  # If we are inside a tag, look for an empty attribute
672  if {[set retval [inside_tag $txt]] eq ""} {
673  if {[set retval [get_tag $txt -dir $dir]] eq ""} {
674  return
675  } else {
676  set endpos [expr {($dir eq "next") ? [lindex $retval 0] : [lindex $retval 1]}]
677  if {[set index [get_blank_line $txt $dir insert $endpos]] ne ""} {
678  ::tk::TextSetCursor $txt "$index lineend"
679  vim::adjust_insert $txt.t
680  return
681  }
682  }
683  }
684 
685  # Look for an empty attribute
686  if {$dir eq "next"} {
687 
688  while {1} {
689  foreach {attr_name attr_name_start attr_value attr_value_start} [get_tag_attributes $txt $retval] {
690  if {($attr_value eq "") && [$txt compare $attr_value_start > insert]} {
691  ::tk::TextSetCursor $txt $attr_value_start
692  return
693  }
694  }
695  if {[set next_tag [get_tag $txt -dir next -start [lindex $retval 1]]] ne ""} {
696  if {[$txt compare [lindex $retval 1] == [lindex $next_tag 0]]} {
697  ::tk::TextSetCursor $txt [lindex $next_tag 0]
698  return
699  } elseif {[set index [get_blank_line $txt next [lindex $retval 1] [lindex $next_tag 0]]] ne ""} {
700  ::tk::TextSetCursor $txt "$index lineend"
701  vim::adjust_insert $txt.t
702  return
703  } else {
704  set retval $next_tag
705  }
706  } else {
707  return
708  }
709  }
710 
711  } else {
712 
713  while {1} {
714  foreach {attr_value_start attr_value attr_name_start attr_name} [lreverse [get_tag_attributes $txt $retval]] {
715  if {($attr_value eq "") && [$txt compare $attr_value_start < insert]} {
716  ::tk::TextSetCursor $txt $attr_value_start
717  return
718  }
719  }
720  if {[set prev_tag [get_tag $txt -dir prev -start [lindex $retval 0]]] ne ""} {
721  if {[$txt compare [lindex $prev_tag 1] == [lindex $retval 0]] && \
722  [$txt compare insert != [lindex $retval 0]]} {
723  ::tk::TextSetCursor $txt [lindex $retval 0]
724  return
725  } elseif {[set index [get_blank_line $txt prev [lindex $retval 0] [lindex $prev_tag 1]]] ne ""} {
726  ::tk::TextSetCursor $txt "$index lineend"
727  vim::adjust_insert $txt.t
728  return
729  } else {
730  set retval $prev_tag
731  }
732  } else {
733  return
734  }
735  }
736 
737  }
738 
739  }

§ go_to_matching_pair()

emmet::go_to_matching_pair

Definition at line 493 of file emmet.tcl.

493  proc go_to_matching_pair {} {
494 
495  variable data
496 
497  array set other $data(other_map)
498  array set dir $data(dir_map)
499  array set index $data(index_map)
500 
501  # Get the current text widget
502  set txt [gui::current_txt]
503 
504  # Get the tag that we are inside of
505  if {[set itag [inside_tag $txt]] eq ""} {
506  return
507  }
508 
509  lassign $itag start end name type
510 
511  # If we are on a starting tag, look for the ending tag
512  set retval [list $start $end]
513  set others 0
514  while {1} {
515  if {[set retval [get_tag $txt -dir $dir($type) -name $name -type $other($type) -start [lindex $retval $index($type)]]] eq ""} {
516  return
517  }
518  if {[incr others [llength [lsearch -all [lindex $retval 4] $name,$type]]] == 0} {
519  ::tk::TextSetCursor $txt [lindex $retval 0]
520  return
521  }
522  incr others -1
523  }
524 
525  }

§ inside_tag()

emmet::inside_tag   txt args  

Definition at line 330 of file emmet.tcl.

330  proc inside_tag {txt args} {
331 
332  array set opts {
333  -startpos insert
334  -allow010 0
335  }
336  array set opts $args
337 
338  set retval [get_tag $txt -dir prev -start "$opts(-startpos)+1c"]
339 
340  if {($retval ne "") && [$txt compare $opts(-startpos) < [lindex $retval 1]] && (([lindex $retval 3] ne "010") || $opts(-allow010))} {
341  return $retval
342  }
343 
344  return ""
345 
346  }

§ load()

emmet::load

Definition at line 48 of file emmet.tcl.

48  proc load {} {
49 
50  variable custom_file
51 
52  # Copy the Emmet customization file from the TKE installation directory to the
53  # user's home directory.
54  if {![file exists $custom_file]} {
55  file copy [file join $::tke_dir data emmet.tkedat] $custom_file
56  }
57 
58  # Load the user's custom alias file
60 
61  }

§ load_custom_aliases()

emmet::load_custom_aliases   args  

Definition at line 153 of file emmet.tcl.

153  proc load_custom_aliases {args} {
154 
155  variable custom_file
156  variable customizations
157 
158  # Read in the emmet customizations
159  if {![catch { tkedat::read $custom_file 1} rc]} {
160 
161  array unset customizations
162 
163  # Save the customization information
164  array set customizations $rc
165 
166  }
167 
168  }

§ lookup_abbr_alias()

emmet::lookup_abbr_alias   alias  

Definition at line 227 of file emmet.tcl.

227  proc lookup_abbr_alias {alias} {
228 
229  return [lookup_alias_helper abbreviation_aliases $alias]
230 
231  }

§ lookup_alias_helper()

emmet::lookup_alias_helper   type alias  

Definition at line 200 of file emmet.tcl.

200  proc lookup_alias_helper {type alias} {
201 
202  variable customizations
203 
204  if {[info exists customizations($type)]} {
205  array set aliases $customizations($type)
206  if {[info exists aliases($alias)]} {
207  return $aliases($alias)
208  }
209  }
210 
211  return ""
212 
213  }

§ lookup_node_alias()

emmet::lookup_node_alias   alias  

Definition at line 218 of file emmet.tcl.

218  proc lookup_node_alias {alias} {
219 
220  return [lookup_alias_helper node_aliases $alias]
221 
222  }

§ merge_lines()

emmet::merge_lines

Definition at line 1061 of file emmet.tcl.

1061  proc merge_lines {} {
1062 
1063  set txt [gui::current_txt]
1064 
1065  if {[set range [get_node_range $txt]] ne ""} {
1066 
1067  lassign $range startpos dummy1 dummy2 endpos
1068 
1069  # Get the number of lines to join
1070  set lines [$txt count -lines $startpos $endpos]
1071 
1072  for {set i 0} {$i < $lines} {incr i} {
1073  set line [string trimleft [$txt get "$startpos+1l linestart" "$startpos+1l lineend"]]
1074  $txt delete "$startpos lineend" "$startpos+1l lineend"
1075  if {$line ne ""} {
1076  $txt insert "$startpos lineend" $line
1077  }
1078  }
1079 
1080  }
1081 
1082  }

§ remove_tag()

emmet::remove_tag

Definition at line 994 of file emmet.tcl.

994  proc remove_tag {} {
995 
996  set txt [gui::current_txt]
997 
998  # If the cursor is within a node range, delete the start/end tags
999  # and adjust indentation if necessary.
1000  if {[set retval [get_node_range $txt]] ne ""} {
1001 
1002  # If the start and end tags are on the same line and the tag is the only
1003  # tag on the line.
1004  if {[$txt compare "[lindex $retval 0] linestart" == "[lindex $retval 3] linestart"] && \
1005  ([string trim [$txt get [lindex $retval 1] [lindex $retval 2]]] eq "") && \
1006  ([string trim [$txt get "[lindex $retval 0] linestart" [lindex $retval 0]]] eq "") && \
1007  ([string trim [$txt get [lindex $retval 3] "[lindex $retval 3] lineend"]] eq "")} {
1008 
1009  $txt delete "[lindex $retval 0] linestart" "[lindex $retval 3]+1l linestart"
1010 
1011  } else {
1012 
1013  # Adjust the starting tag range
1014  if {([string trim [$txt get "[lindex $retval 0] linestart" [lindex $retval 0]]] eq "") && \
1015  ([string trim [$txt get [lindex $retval 1] "[lindex $retval 1] lineend"]] eq "")} {
1016  lset retval 0 [$txt index "[lindex $retval 0] linestart"]
1017  lset retval 1 [$txt index "[lindex $retval 1]+1l linestart"]
1018  }
1019 
1020  # Adjust the ending tag range
1021  if {([string trim [$txt get "[lindex $retval 2] linestart" [lindex $retval 2]]] eq "") && \
1022  ([string trim [$txt get [lindex $retval 3] "[lindex $retval 3] lineend"]] eq "")} {
1023  lset retval 2 [$txt index "[lindex $retval 2] linestart"]
1024  lset retval 3 [$txt index "[lindex $retval 3]+1l linestart"]
1025  }
1026 
1027  # These are the number of characters that will be removed from the start
1028  set count [$txt count -lines {*}[lrange $retval 1 2]]
1029 
1030  # Delete the tags
1031  $txt delete {*}[lrange $retval 2 3]
1032  $txt delete {*}[lrange $retval 0 1]
1033 
1034  # Just use the indentation algorithm
1035  indent::format_text $txt.t [lindex $retval 0] "[lindex $retval 0]+${count}l linestart" 0
1036 
1037  }
1038 
1039  # Add a separator
1040  $txt edit separator
1041 
1042  } elseif {[set retval [inside_tag $txt -allow010 1]] ne ""} {
1043 
1044  # Delete the tag
1045  if {([string trim [$txt get "[lindex $retval 0] linestart" [lindex $retval 0]]] eq "") && \
1046  ([string trim [$txt get [lindex $retval 1] "[lindex $retval 1] lineend"]] eq "")} {
1047  $txt delete "[lindex $retval 0] linestart" "[lindex $retval 1]+1l linestart"
1048  } else {
1049  $txt delete {*}[lrange $retval 0 1]
1050  }
1051 
1052  # Add a separator
1053  $txt edit separator
1054 
1055  }
1056 
1057  }

§ replace_data_url()

emmet::replace_data_url   txt startpos endpos url args  

Definition at line 1264 of file emmet.tcl.

1264  proc replace_data_url {txt startpos endpos url args} {
1265 
1266  array set opts {
1267  -test ""
1268  }
1269  array set opts $args
1270 
1271  # If we have base64 data, decode and save the information to a file
1272  if {[regexp {^data:image/(gif|png|jpg);base64,(.*)$} $url -> ext data]} {
1273  set fname $opts(-test)
1274  if {($fname ne "") || [set fname [tk_getSaveFile -parent . -defaultextension .$ext -title [msgcat::mc "Select File to Save"]]] ne ""} {
1275  if {![catch { open $fname w} rc]} {
1276  fconfigure $rc -encoding binary
1277  puts $rc [base64::decode $data]
1278  close $rc
1279  $txt replace $startpos $endpos [utils::relative_to $fname [pwd]]
1280  $txt edit separator
1281  }
1282  }
1283  return
1284  }
1285 
1286  # If the filename is a supported image type, convert the file to base64
1287  # and insert them.
1288  set type ""
1289  switch [file extension $url] {
1290  .gif { set type "image/gif"}
1291  .png { set type "image/png"}
1292  .jpg { set type "image/jpg"}
1293  .jpeg { set type "image/jpg"}
1294  }
1295 
1296  # Get the filename to handle from the parsed URL
1297  set delete 1
1298  if {[file exists $url]} {
1299  set fname $url
1300  set delete 0
1301  } elseif {[set fname [utils::download_url $url]] eq ""} {
1302  return
1303  }
1304 
1305  # Output the base64 output
1306  if {($type ne "") && ![catch { open $fname r} rc]} {
1307  fconfigure $rc -translation binary
1308  set data [read $rc]
1309  close $rc
1310  if {$delete} {
1311  file delete -force $fname
1312  }
1313  $txt replace $startpos $endpos "data:$type;base64,[base64::encode -maxlen 0 $data]"
1314  $txt edit separator
1315  }
1316 
1317  }

§ select_html_attr_value()

emmet::select_html_attr_value   txt dir selected attr_value attr_value_start  

Definition at line 743 of file emmet.tcl.

743  proc select_html_attr_value {txt dir selected attr_value attr_value_start} {
744 
745  if {$attr_value eq ""} {
746  return 0
747  }
748 
749  set select 0
750  set pattern [expr {($dir eq "next") ? {^\s*(\S+)} : {(\S+)\s*$}}]
751  set attr_value_end [$txt index "$attr_value_start+[string length $attr_value]c"]
752 
753  if {((($dir eq "next") && ($selected eq [list $attr_value_start $attr_value_end])) || \
754  (($dir eq "prev") && ($selected ne "") && [$txt compare [lindex $selected 0] > $attr_value_end])) && [regexp {\s} $attr_value]} {
755  set select 1
756  }
757 
758  while {[regexp -indices $pattern $attr_value -> match]} {
759  set value_start [$txt index "$attr_value_start+[lindex $match 0]c"]
760  set value_end [$txt index "$attr_value_start+[expr [lindex $match 1] + 1]c"]
761  if {$select} {
762  ::tk::TextSetCursor $txt $value_end
763  $txt tag add sel $value_start $value_end
764  return 1
765  } elseif {$selected eq [list $value_start $value_end]} {
766  set select 1
767  }
768  if {$dir eq "next"} {
769  set attr_value [string range $attr_value [expr [lindex $match 1] + 1] end]
770  set attr_value_start [$txt index "$attr_value_start+[expr [lindex $match 1] + 1]c"]
771  } else {
772  set attr_value [string range $attr_value 0 [expr [lindex $match 0] - 1]]
773  }
774  }
775 
776  if {$select} {
777  return 0
778  } else {
779  ::tk::TextSetCursor $txt $attr_value_end
780  $txt tag add sel $attr_value_start $attr_value_end
781  return 1
782  }
783 
784  }

§ select_html_item()

emmet::select_html_item   txt dir  

Definition at line 788 of file emmet.tcl.

788  proc select_html_item {txt dir} {
789 
790  set startpos "insert"
791 
792  # If the cursor is not within a start tag, go find the next start tag
793  if {([set retval [inside_tag $txt -allow010 1]] eq "") || [string match "001" [lindex $retval 3]]} {
794  set retval [get_tag $txt -dir $dir -type "??0"]
795  }
796 
797  # Get the currently selected text
798  if {[llength [set selected [$txt tag ranges sel]]] != 2} {
799  set selected ""
800  }
801 
802  if {$dir eq "next"} {
803 
804  while {$retval ne ""} {
805 
806  # Figure out the index of the end of the name
807  set end_name "[lindex $retval 0]+[expr [string length [lindex $retval 2]] + 1]c"
808 
809  # Select the tag name if it is the next item
810  if {[$txt compare $startpos < $end_name]} {
811  ::tk::TextSetCursor $txt $end_name
812  $txt tag add sel "[lindex $retval 0]+1c" $end_name
813  return
814 
815  # Otherwise, check the attributes within the tag for selectable items
816  } else {
817  foreach {attr_name attr_name_start attr_value attr_value_start} [get_tag_attributes $txt $retval] {
818  set attr_end [$txt index "$attr_value_start+[expr [string length $attr_value] + 1]c"]
819  if {[$txt compare $startpos > $attr_end]} {
820  continue
821  }
822  if {[$txt compare $startpos < $attr_value_start]} {
823  ::tk::TextSetCursor $txt $attr_end
824  $txt tag add sel $attr_name_start $attr_end
825  return
826  } elseif {(($selected eq [list $attr_name_start $attr_end]) && ($attr_value ne "")) || ($selected eq "")} {
827  ::tk::TextSetCursor $txt "$attr_end-1c"
828  $txt tag add sel $attr_value_start "$attr_end-1c"
829  return
830  } elseif {[select_html_attr_value $txt $dir $selected $attr_value $attr_value_start]} {
831  return
832  }
833  }
834  }
835 
836  # Get the next tag
837  set retval [get_tag $txt -dir $dir -type "??0" -start [lindex $retval 1]]
838 
839  }
840 
841  } else {
842 
843  while {$retval ne ""} {
844 
845  set attr_name_start ""
846 
847  foreach {attr_value_start attr_value attr_name_start attr_name} [lreverse [get_tag_attributes $txt $retval]] {
848  set attr_end [$txt index "$attr_value_start+[expr [string length $attr_value] + 1]c"]
849  if {($selected eq [list $attr_name_start $attr_end]) || [$txt compare $startpos < $attr_name_start]} {
850  continue
851  }
852  if {($selected eq [list $attr_value_start [$txt index $attr_end-1c]]) || \
853  (($attr_value eq "") && [$txt compare $startpos > $attr_name_start])} {
854  ::tk::TextSetCursor $txt $attr_end
855  $txt tag add sel $attr_name_start $attr_end
856  return
857  } elseif {[select_html_attr_value $txt $dir $selected $attr_value $attr_value_start]} {
858  return
859  } elseif {[$txt compare $startpos > $attr_value_start] && ($attr_value ne "")} {
860  ::tk::TextSetCursor $txt "$attr_end-1c"
861  $txt tag add sel $attr_value_start "$attr_end-1c"
862  return
863  }
864  }
865 
866  set start_name [$txt index "[lindex $retval 0]+1c"]
867  set end_name [$txt index "[lindex $retval 0]+[expr [string length [lindex $retval 2]] + 1]c"]
868 
869  # Highlight the tag name if the first full attribute is highlighted or
870  # if nothing was highlighted but the cursor is after the beginning of
871  # the tag name
872  if {(($selected ne [list $start_name $end_name]) && [$txt compare $startpos > [lindex $retval 0]]) || \
873  (($attr_name_start ne "") && ($selected eq [list $attr_name_start $attr_end]))} {
874  ::tk::TextSetCursor $txt $end_name
875  $txt tag add sel $start_name $end_name
876  return
877  }
878 
879  # Get the previous tag
880  set retval [get_tag $txt -dir $dir -type "??0" -start [lindex $retval 0]]
881 
882  }
883 
884  }
885 
886  }

§ select_item()

emmet::select_item   dir  

Definition at line 890 of file emmet.tcl.

890  proc select_item {dir} {
891 
892  # Get the current text widget
893  set txt [gui::current_txt]
894 
895  # Get the language of the current insertion cursor
896  if {[set lang [ctext::getLang $txt insert]] eq ""} {
897  set lang [syntax::get_language $txt]
898  }
899 
900  if {$lang eq "CSS"} {
901  emmet_css::select_item $txt $dir
902  } else {
903  select_html_item $txt $dir
904  }
905 
906  }

§ share_changed()

emmet::share_changed   dir  

Definition at line 1388 of file emmet.tcl.

1388  proc share_changed {dir} {
1389 
1390  variable custom_file
1391 
1392  set custom_file [file join $dir emmet.tkedat]
1393 
1394  }

§ split_join_tag()

emmet::split_join_tag

Definition at line 971 of file emmet.tcl.

971  proc split_join_tag {} {
972 
973  set txt [gui::current_txt]
974 
975  # If the cursor is within a node range, join the range
976  if {[set retval [get_node_range $txt]] ne ""} {
977 
978  $txt delete [lindex $retval 1] [lindex $retval 3]
979  $txt insert "[lindex $retval 1]-1c" " /"
980 
981  # Otherwise, split the tag
982  } elseif {[set retval [inside_tag $txt -allow010 1]] ne ""} {
983 
984  set index [$txt search -regexp -- {\s*/>$} [lindex $retval 0] [lindex $retval 1]]
985  $txt replace $index [lindex $retval 1] "></[lindex $retval 2]>"
986 
987  }
988 
989  }

§ toggle_comment()

emmet::toggle_comment

Definition at line 951 of file emmet.tcl.

951  proc toggle_comment {} {
952 
953  # Get the current text widget
954  set txt [gui::current_txt]
955 
956  # Get the language of the current insertion cursor
957  if {[set lang [ctext::getLang $txt insert]] eq ""} {
958  set lang [syntax::get_language $txt]
959  }
960 
961  if {$lang eq "CSS"} {
963  } else {
965  }
966 
967  }

§ toggle_html_comment()

emmet::toggle_html_comment   txt  

Definition at line 910 of file emmet.tcl.

910  proc toggle_html_comment {txt} {
911 
912  if {[$txt is incomment insert]} {
913 
914  if {([set comment_end [lassign [$txt syntax prevrange comstr1c0 insert] comment_start]] eq "") || \
915  [$txt compare insert > $comment_end]} {
916  lassign [$txt syntax prevrange comstr1c1 insert] comment_start comment_end
917  }
918 
919  set i 0
920  foreach index [$txt search -backwards -all -count lengths -regexp -- {<!--\s*|\s*-->} $comment_end $comment_start] {
921  $txt delete $index "$index+[lindex $lengths $i]c"
922  incr i
923  }
924 
925  } else {
926 
927  if {[set node_range [get_node_range $txt]] ne ""} {
928  lassign [get_outer $node_range] comment_start comment_end
929  } elseif {[set retval [inside_tag $txt -allow010 1]] ne ""} {
930  lassign $retval comment_start comment_end
931  } else {
932  return
933  }
934 
935  # Remove any comments found within range that we are going to comment
936  set i 0
937  foreach index [$txt search -backwards -all -count lengths -regexp -- {<!--\s*|\s*-->} $comment_end $comment_start] {
938  $txt delete $index "$index+[lindex $lengths $i]c"
939  incr i
940  }
941 
942  $txt insert $comment_end " -->"
943  $txt insert $comment_start "<!-- "
944 
945  }
946 
947  }

§ update_alias()

emmet::update_alias   type curr_alias new_alias value  

Definition at line 172 of file emmet.tcl.

172  proc update_alias {type curr_alias new_alias value} {
173 
174  variable customizations
175  variable custom_file
176 
177  # Get the affected aliases and store it in an array
178  array set aliases $customizations($type)
179 
180  # Remove the old alias information if the curr_alias value does not match the new_alias value
181  if {$curr_alias ne $new_alias} {
182  catch { unset aliases($curr_alias)}
183  }
184 
185  if {$new_alias ne ""} {
186  set aliases($new_alias) $value
187  }
188 
189  # Store the aliases list back into the customization array
190  set customizations($type) [array get aliases]
191 
192  # Write the customization value to file
193  catch { tkedat::write $custom_file [array get customizations] 1 [list node_aliases array abbreviation_aliases array]}
194 
195  }

§ update_html_image_size()

emmet::update_html_image_size   txt  

Definition at line 1087 of file emmet.tcl.

1087  proc update_html_image_size {txt} {
1088 
1089  if {([set retval [inside_tag $txt -allow010 1]] ne "") && ([lindex $retval 2] eq "img") && [string match "??0" [lindex $retval 3]]} {
1090 
1091  set width ""
1092  set height ""
1093  set src_end ""
1094  set width_start ""
1095  set width_end ""
1096  set hstart ""
1097  set height_start ""
1098  set height_end ""
1099 
1100  foreach {attr_name attr_name_start attr_value attr_value_start} [get_tag_attributes $txt $retval] {
1101  switch $attr_name {
1102  "src" {
1103  if {![catch { exec php [file join $::tke_dir lib image_size.php] $attr_value} rc]} {
1104  lassign $rc width height
1105  if {![string is integer $width]} {
1106  set width ""
1107  }
1108  }
1109  set src_end [$txt index "$attr_value_start+[expr [string length $attr_value] + 1]c"]
1110  }
1111  "width" {
1112  set width_start $attr_value_start
1113  set width_end [$txt index "$attr_value_start+[string length $attr_value]c"]
1114  }
1115  "height" {
1116  set hstart $attr_name_start
1117  set height_start $attr_value_start
1118  set height_end [$txt index "$attr_value_start+[string length $attr_value]c"]
1119  }
1120  }
1121  }
1122 
1123  if {$width ne ""} {
1124  if {$width_start ne ""} {
1125  if {$height_start ne ""} {
1126  if {[$txt compare $width_start < $height_start]} {
1127  $txt replace $height_start $height_end $height
1128  $txt replace $width_start $width_end $width
1129  } else {
1130  $txt replace $width_start $width_end $width
1131  $txt replace $height_start $height_end $height
1132  }
1133  } else {
1134  $txt insert "$width_end+1c" " height=\"$height\""
1135  $txt replace $width_start $width_end $width
1136  }
1137  } else {
1138  if {$height_start ne ""} {
1139  $txt replace $height_start $height_end $height
1140  $txt insert $hstart "width=\"$width\" "
1141  } else {
1142  $txt insert $src_end " width=\"$width\" height=\"$height\""
1143  }
1144  }
1145  }
1146 
1147  }
1148 
1149  }

§ update_image_size()

emmet::update_image_size

Definition at line 1153 of file emmet.tcl.

1153  proc update_image_size {} {
1154 
1155  # Get the current text widget
1156  set txt [gui::current_txt]
1157 
1158  # Get the language of the current insertion cursor
1159  if {[set lang [ctext::getLang $txt insert]] eq ""} {
1160  set lang [syntax::get_language $txt]
1161  }
1162 
1163  if {$lang eq "CSS"} {
1165  } else {
1167  }
1168 
1169  }

§ view_reference()

emmet::view_reference

Definition at line 1371 of file emmet.tcl.

1371  proc view_reference {} {
1372 
1373  utils::open_file_externally "https://docs.emmet.io" 1
1374 
1375  }

§ wrap_with_abbreviation()

emmet::wrap_with_abbreviation   args  

Definition at line 461 of file emmet.tcl.

461  proc wrap_with_abbreviation {args} {
462 
463  array set opts {
464  -test ""
465  }
466  array set opts $args
467 
468  set abbr $opts(-test)
469 
470  # Get the abbreviation from the user
471  if {($abbr ne "") || [gui::get_user_response [format "%s:" [msgcat::mc "Abbreviation"]] abbr]} {
472 
473  # Get the current text widget
474  set txt [gui::current_txt]
475 
476  # Get the node to surround
477  if {[llength [set range [$txt tag ranges sel]]] != 2} {
478  set range [get_outer [get_node_range $txt]]
479  }
480 
481  # Parse the snippet and if no error, insert the resulting string
482  if {![catch { ::parse_emmet $abbr "" [$txt get {*}$range]} str]} {
483  snippets::insert_snippet_into_current $str -delrange $range -separator 0
484  }
485 
486  }
487 
488  }