{{{  comments
; This macro simulates tab-keys (using spaces to go to next position!)
; you can define 4 tab-width in the following way:
;   tab-width  /tab-count:   the first tab-count jumps use tab-width
;   tab-width-1/tab-count-1: the next tab-count-1 jumps use tab-width-1
;   tab-width-2/tab-count-2: the next tab-count-2 jumps use tab-width-2
;   tab-width-3:             this is the width for all following jumps
; negative values for counts have the effect, that the corresponding
; width-values are use for all following jumps.
;
; for example:
;
;* the startup-values are:
;    tab-width 1
;    tab-count -1
;  these values let tab have the same effect as space
;
;* given the values:
;    tab-width=2     tab-count=1
;    tab-width-1=3   tab-count-1=2
;    tab-width-2=4   tab-count-2=2
;    tab-width-3=5
;
;  the resulting tab-positions are:
;
;  a b  c  d   e   f    g    h    i    j    k    l    m
;  ^ ^  ^  ^   ^   ^    ^    ^    ^    ^    ^    ^    ^
;  | |  |  |   |   |    all following jumps use tab-width-3
;  | |  |  |   |   |
;  | |  |  |   tab-width-2-jumps
;  | |  |  |
;  | |  tab-width-1-jumps
;  | |
;  | tab-width-jump
;  |
;  first character in line
}}}
@if-using not(TAB)
  @use (TAB)
  {{{  vars
  ( defvar
     ( tab-width          ; first tab-step
       tab-count          ; number of usages for ^, <0 -> always
       tab-width-1        ; second tab-step
       tab-count-1        ; number of usages of step 2
       tab-width-2        ; third tab-step
       tab-count-2        ; number of usages of step 3
       tab-width-3        ; last tab-step
       tab-missing-spaces ; help-counter
     )
  )
  }}}
  {{{  go_to_next_tab
  (deffun go_to_next_tab (
    {{{  maybe initialise the counter for tab-width
    if not(counter>0 tab-width) (
      set-counter tab-width 1
      set-counter tab-count -1
    ) fi
    }}}
    {{{  tab-missing-spaces = #missing `` ''
    set-counter tab-missing-spaces -(1 +(store-pos set-space-enter))
    local (tab-count tab-count-1 tab-count-2) (
      do (
        case
          ( tab-count
             ( set-counter tab-missing-spaces +(tab-missing-spaces tab-width  )
               set-counter tab-count  +(tab-count   -1)
             )
          )
          ( tab-count-1
             ( set-counter tab-missing-spaces +(tab-missing-spaces tab-width-1)
               set-counter tab-count-1 +(tab-count-1 -1)
             )
          )
          ( tab-count-2
             ( set-counter tab-missing-spaces +(tab-missing-spaces tab-width-2)
               set-counter tab-count-2 +(tab-count-2 -1)
             )
          )
        default
          (set-counter tab-missing-spaces +(tab-missing-spaces tab-width-3))
        esac
      ) while not(counter>0 tab-missing-spaces)
    )
    }}}
    {{{  insert the spaces
    do
     ( "  ;
       set-counter tab-missing-spaces +(tab-missing-spaces -1)
     )
    while counter>0 tab-missing-spaces
    }}}
  ))
  }}}
  {{{  define-tab
  (deffun define-tab (
    prompt-counter tab-width (M_TABSIZE "  "? )
    set-counter tab-count -1
    if not(counter>0 tab-width) ( set-counter tab-width 1 ) fi
  ))
  }}}
  {{{  undeclare
  ( undeclare ( tab-missing-spaces ) )
  }}}
@fi
