{{{  comments
; some macros doing different actions dependend on the currently set mode.
}}}
{{{  description
; mode-number mode-tag mode-name
;      0
;      2      c-mode   C-Mode
;      3      p-mode   PASCAL-M
;      4      r-mode   ROFF-M
;      5      t-mode   TEX-Mode
;      6      o-mode   OCCAM-M
;      7      m-mode   MIRA-M
}}}
@if-using not(STANDARD)
  @use (STANDARD)
  {{{  libs
  {{{F fun/fillpara
  :::F fun/fillpara
  }}}
  {{{F fun/mt-fold
  :::F fun/mt-fold
  }}}
  {{{F fun/skippara
  :::F fun/skippara
  }}}
  {{{F fun/savetabs
  :::F fun/savetabs
  }}}
  }}}
  {{{  vars
  ( defvar
     ( start-up-x   ; cursor when calling the std-macro
       start-up-y
       c-mode       ; tags for different modes
       p-mode
       t-mode
       o-mode
       m-mode
       r-mode
       s-mode
       x_pos_1
       x_pos_3
     )
  )
  }}}
  {{{  standard-filter
  (deffun standard-filter (
    case
      (counter>0 c-mode (filter-buffer "cb newline-and-indent))
      (or(counter>0 p-mode,counter>0 o-mode,counter>0 m-mode)
        (message-exit "no_filter_given)
      )
    default
      ( fill-paragraph )
    esac
  ))
  }}}
  {{{  space
  (deffun space (if not(in-prompt) (wrap-word) else ("  )fi ))
  }}}
  {{{  standard-down
  {{{  occam-down
  (defmac occam-down (
    beginning-of-line
    set-counter start-up-x store-pos
    do (
      if test-end-fold (close-fold) fi
      next-line
      while test-fold-line (open-fold next-line)
      beginning-of-line
      set-counter start-up-y -(start-up-x store-pos)
    ) while and(not(test-bottom),or(not(counter>0 start-up-y),not(test-text)))
  ))
  }}}
  (deffun standard-down (
    case
      (counter>0 c-mode (
        {{{  search {
        do
          (forward-character search-forward "{ newline-and-indent)
        while not(test-text)
        }}}
      ))
      (counter>0 r-mode (forward-paragraph))
      (counter>0 t-mode (forward-paragraph))
      (counter>0 p-mode (
        forward-character
        search-forward "begin newline-and-indent
      ))
      (counter>0 o-mode (occam-down))
    esac
  ))
  }}}
  {{{  standard-up
  {{{  occam-up
  (defmac occam-up (
    beginning-of-line
    backward-character
    set-counter start-up-x store-pos
    do (
      if test-begin-fold (close-fold) fi
      previous-line
      while test-fold-line (
        open-fold
        mtool-bot
        previous-line
      )
      goto-counter start-up-x
    ) while and(not(test-top),or(test-char " ,not(test-text)))
  ))
  }}}
  (deffun standard-up (
    case
      (counter>0 c-mode (
        {{{  find previous {
        do
          (search-reverse "{ newline-and-indent)
        while not(or(test-text,test-top))
        if test-top (standard-down) fi
        }}}
      ))
      (counter>0 r-mode (backward-paragraph))
      (counter>0 t-mode (backward-paragraph))
      (counter>0 p-mode (
        search-reverse "begin newline-and-indent
      ))
      (counter>0 o-mode (occam-up))
    esac
  ))
  }}}
  {{{  standard-save
  (deffun standard-save (
    case
      {{{   script -> pipe through unexpand
      (and(counter>0 s-mode,test-file-changed,counter-0 set-enter)
        (save-file-with-leading-tabs))
      }}}
    default
      (save-file)
    esac
  ))
  }}}
  {{{  c-mode-stuff
  {{{  parens
  (deffun parens
  (
    "(
    if and(not(in-prompt),or(counter>0 p-mode,counter>0 c-mode)) (
      ")
      backward-character
    ) fi
  ))
  }}}
  {{{  brackets
  (deffun brackets
  (
    "[
    if and(not(in-prompt),or(counter>0 p-mode,counter>0 c-mode)) (
      "]
      backward-character
    ) fi
  ))
  }}}
  {{{  curly brackets
  (deffun curly-brackets
  (
    case
      (in-prompt ())
      (not(test-text) ())
      {{{  c-mode
      (c-mode (
        set-counter x_pos_1 store-pos
        beginning-of-line
        if test-char "  (
          goto-counter x_pos_1
        ) else (
          set-counter x_pos_1 store-pos
          if test-char "{ (set-counter x_pos_1 +(x_pos_1 2)) fi
          end-of-line
          newline-and-indent
          goto-counter x_pos_1
          "  ;
        ) fi
        "{ newline-and-indent "} previous-line "  ;
        return-from-macro
      ))
      }}}
      {{{  p-mode
      (p-mode (
        set-counter x_pos_1 store-pos
        beginning-of-line
        if not(test-char " ) (
          set-counter x_pos_1 store-pos end-of-line "  ;
        ) else (
          goto-counter x_pos_1
        ) fi
        "begin
        newline-and-indent
        newline-and-indent
        "end
        previous-line
        backward-character
        return-from-macro
      ))
      }}}
    esac
    "{
  ))
  }}}
  {{{  doublequotes
  (deffun doublequotes
  (
    ""
    if and(not(in-prompt),or(counter>0 p-mode,counter>0 c-mode)) (
      ""
      backward-character
    ) fi
  ))
  }}}
  {{{  singlequotes
  (deffun singlequotes
  (
    "'
    if and(not(in-prompt),or(counter>0 p-mode,counter>0 c-mode)) (
      "'
      backward-character
    ) fi
  ))
  }}}
  {{{  semicolon
  (deffun semicolon (
    if and(not(in-prompt),test-text,or(counter>0 p-mode,counter>0 c-mode)) (
      {{{  language ;
      {{{  maybe put ; at correct position
      set-counter x_pos_1 store-pos
      beginning-of-line
      if test-char " (
        goto-counter x_pos_1
        ";
      ) else (
        end-of-line
        backward-character
        if not(test-char ";) ( forward-character "; ) fi
      ) fi
      }}}
      {{{  where must next line begin
      beginning-of-line
      set-counter x_pos_1 store-pos
      if and(c-mode,test-char "{) ( set-counter x_pos_1 +(x_pos_1 2) ) fi
      }}}
      next-line
      beginning-of-line
      if test-char "  (
        {{{  empty line, move to position
        goto-counter x_pos_1
        }}}
      ) else (
        {{{  maybe generate new line
        set-counter x_pos_3 x_pos_1
        set-counter x_pos_1 -(x_pos_1 store-pos)
        if or(not(test-text),counter>0 x_pos_1) (
          previous-line
          end-of-line
          newline-and-indent
          goto-counter x_pos_3
        ) fi
        }}}
      ) fi
      }}}
    ) else (
      ";
    ) fi
  ))
  }}}
  }}}
@fi
