hl_alm.tcl
README.md

hl_alm.tcl

  • hl_alm.tcl
    • init hl_alm::init : Initializes highlighting .alm text (alited's macro). w - the text font - the text's font szfont - the font's size args - highlighting colors
    • line hl_alm::line : Highlights a line of .alm text (alited's macro). w - the text pos - position in the line prevQtd - mode of processing a current line (0, 1, -1)
  • EOF

alited's addons

The alited/lib/addon directory's scripts highlight various types of files:

  • hl_alm.tcl - .alm files (macros)
  • hl_em.tcl - .em files (e_menu's menus)
  • hl_html.tcl - .html files
  • hl_ini.tcl - .ini files
  • hl_md.tcl - .md files
  • hl_wiki.tcl - .wiki files (for wiki.tcl-lang.org)
  • The alited's main files are contained in alited/src directory.

    hl_alm.tcl
    #! /usr/bin/env tclsh
    ###########################################################
    # Name:    hl_alm.tcl
    # Author:  Alex Plotnikov  (aplsimple@gmail.com)
    # Date:    Mar 11, 2023
    # Brief:   Handles highlighting .alm files (alited macros).
    # License: MIT.
    ###########################################################
    
    namespace eval hl_alm {}
    #_______________________
    
    proc hl_alm::init {w font szfont args} {
      # Initializes highlighting .alm text (alited's macro).
      #   w - the text
      #   font - the text's font
      #   szfont - the font's size
      #   args - highlighting colors
    
      lassign $args clrCOM clrCOMTK clrSTR clrVAR clrCMN clrPROC clrOPT
      dict set font -size $szfont
      dict set font -weight bold;
      $w tag config almKEY -font $font -foreground $clrCOM
      dict set font -weight normal
      $w tag config almPATH -font $font -foreground $clrVAR
      $w tag config almARG -font $font -foreground $clrOPT
      dict set font -slant italic
      $w tag config almCMNT -font $font -foreground $clrCMN
      foreach t {KEY CMNT} {after idle $w tag raise alm$t}
      return [namespace current]::line
    }
    #_______________________
    
    proc hl_alm::line {w {pos ""} {prevQtd 0}} {
      # Highlights a line of .alm text (alited's macro).
      #   w - the text
      #   pos - position in the line
      #   prevQtd - mode of processing a current line (0, 1, -1)
    
      if {$pos eq {}} {set pos [$w index insert]}
      set il [expr {int($pos)}]
      set line [$w get $il.0 $il.end]
      if {[string trim $line] eq {}} {return yes}
      foreach t {KEY PATH ARG CMNT} {$w tag remove alm$t $il.0 $il.end}
      if {[regexp "^\s*#" $line]} {
        $w tag add almCMNT $il.0 $il.end
        return yes
      }
      lassign [regexp -inline {^\s*[^\s]+} $line] lre
      if {$lre ne {}} {
        set p1 [string length $lre]
        $w tag add almKEY $il.0 $il.$p1
      }
      set path [regexp -inline -all -indices {\s{1}[.]{1}[^\s]+} $line]
      foreach l2 $path {
        lassign $l2 p1 p2
        if {$p1<$p2} {
          $w tag add almPATH $il.$p1 $il.[incr p2]
        }
      }
      set key [regexp -inline -all -indices {\s%.=} $line]
      foreach l2 $key {
        lassign $l2 p1 p2
        if {$p1<$p2} {
          $w tag add almARG $il.$p1 $il.[incr p2]
        }
      }
      return yes
    }
    
    # ________________________ EOF _________________________ #
    
    
    hl_alm.tcl