{{{  Comments for this keybinding
; These keybindings are my variant of the mtool-sun-installation for  the
; Origami folding editor.
;
; It works in general like the mtool-system, but the  special  codes  for
; find/replace/attach  are  different.   Also   there   are   some  other
; differences, which are nessessary to use the new commands.
;
; The alias-fold includes the binding of the Rx-Keys, so that you can use
; $Rx to bind them to functions. Every function key should be defined  in
; this way, because escape sequences are hard to read if you want to  get
; user-help from the binding-file.
;
; Wolfgang Stumvoll
}}}
(defusermacros 10)
{{{  I call these bindings MTool
(defbinding MTool-Sun)
}}}
{{{  Alias for SUN-Keyboard (sunview and console)
; The following aliases describe the sunview-standard-keymapping for
; the Rxx-Keys and the Ins-Key.
{{{  Rxx
(alias R1  ($esc  "[ "2 "0 "8 "z))
(alias R2  ($esc "[ "2 "0 "9 "z))
(alias R3  ($esc "[ "2 "1 "0 "z))
(alias R4  ($esc "[ "2 "1 "1 "z))
(alias R5  ($esc "[ "2 "1 "2 "z))
(alias R6  ($esc "[ "2 "1 "3 "z))
(alias R7  ($esc "[ "2 "1 "4 "z))
(alias R8  ($esc "[ "A))
(alias R9  ($esc "[ "2 "1 "6 "z))
(alias R10 ($esc "[ "D))
(alias R11 ($esc "[ "2 "1 "8 "z))
(alias R12 ($esc "[ "C))
(alias R13 ($esc "[ "2 "2 "0 "z))
(alias R14 ($esc "[ "B))
(alias R15 ($esc "[ "2 "2 "2 "z))
}}}
(alias Ins ($esc "[ "2 "4 "7 "z))
}}}
{{{  definition of backspace,rubout
(alias rubout (C-?))
(alias backspace (C-H))
}}}
{{{  marktypes
{{{  pascal
(defmark pascal ( ("< "< "<)
                  (". ". ".)
                  (": ": ":)
                  ("> "> ">)
                )
)
}}}
{{{  script
(defmark script  ( ("# "# "@)
                   (". ". ".)
                   ("# "# ":)
                   ("# "# "$)
                 )
)
}}}
}}}
{{{  OCL-macros
@lib exit
@lib delchar
@if-using (MOUSY)
   @lib go-mouse
   {{{  go-mouse
   ( deffun go-mouse
      ( if in-prompt
         ( newline-and-indent )
        else
         ( go-mouse-position )
        fi
      )
   )
   }}}
   {{{  go-and-open-mouse
   ( deffun go-and-open-mouse
      ( if in-prompt
         ( newline-and-indent )
        else
         ( go-mouse-position
           case
            ( test-fold-line ( open-fold ) )
            ( test-filed ( enter-fold ) )
           esac
         )
        fi
      )
   )
   }}}
   {{{  go-and-close-mouse
   ( deffun go-and-close-mouse
      ( if in-prompt
         ( newline-and-indent )
        else
         ( go-mouse-position
           close-fold
           if last-message M_TOP ( exit-fold ) fi
         )
        fi
      )
   )
   }}}
@fi
@lib trans-char
@lib wordmacs
@lib mt-fold
{{{  real-enter
(deffun enter-fold- (
  if test-text ( message-exit ( "[ M_NO_SIMPLE_FOLD "] ) ) fi
  enter-fold
))
}}}
@lib delspaces
{{{  @lib tab
{{{  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 (
    if in-prompt ( return-from-macro ) fi
    {{{  maybe initialise the counter for tab-width
    if <=(tab-width 0) ( set tab-width 0 ) fi
    }}}
    if =(tab-width 0)
     ( insert-ascii 9 return-from-macro )
    fi
    {{{  tab-missing-spaces = #missing `` ''
    set tab-missing-spaces -(1 +(store-pos set-space-enter))
    local (tab-count tab-count-1 tab-count-2) (
      do (
        case
          ( tab-count
             ( set tab-missing-spaces +(tab-missing-spaces tab-width  )
               set tab-count  +(tab-count   -1)
             )
          )
          ( tab-count-1
             ( set tab-missing-spaces +(tab-missing-spaces tab-width-1)
               set tab-count-1 +(tab-count-1 -1)
             )
          )
          ( tab-count-2
             ( set tab-missing-spaces +(tab-missing-spaces tab-width-2)
               set tab-count-2 +(tab-count-2 -1)
             )
          )
        default
          (set tab-missing-spaces +(tab-missing-spaces tab-width-3))
        esac
      ) while <=(tab-missing-spaces 0)
    )
    }}}
    {{{  insert the spaces
    do
     ( "  ;
       set tab-missing-spaces +(tab-missing-spaces -1)
     )
    while <>(tab-missing-spaces 0)
    }}}
  ))
  }}}
  {{{  define-tab
  (deffun define-tab (
    if in-prompt ( return-from-macro ) fi
    prompt-counter tab-width ("Tab "  "size "  "? )
    set tab-count -1
  ))
  }}}
  {{{  undeclare
  ( undeclare ( tab-missing-spaces ) )
  }}}
@fi
}}}
@lib append
@lib go-match
@lib np-file
}}}
{{{  folding
(keybind toggle-attach-file-to-fold ($esc "a "t))
(keybind create-fold               ($R15))
(keybind create-fold               ($esc "c "r))
(keybind auto-header               ($esc "f "h))
(keybind describe-fold             ($esc "f "?))
(keybind enter-fold-               ($R13 $R4))
(keybind enter-fold-               ($esc "e "n))
(keybind enter-fold-               (M-C-O))
(keybind exit-fold                 ($R13 $R6))
(keybind exit-fold                 ($esc "e "x))
(keybind exit-fold                 (M-C-C))
(keybind close-fold                ($R6))
(keybind close-fold                ($esc "c "l))
(keybind close-fold                (C-C))
(keybind toggle-file-fold          ($R13 $R11))
(keybind toggle-file-fold          ($esc "f "f))
(keybind open-fold                 ($esc "o "p))
(keybind open-fold                 ($R4))
(keybind open-fold                 (C-O))
(keybind unfold-fold               ($esc "r "e))
(keybind unfold-fold               ($R13 $R15))
}}}
{{{  moving around
(keybind end-of-fold               ($R3))
(keybind end-of-fold               ($esc "b "O))
(keybind next-line                 ($R14))
(keybind next-line                 ($esc "d "n))
(keybind next-line                 (C-N))
(keybind end-of-line               ($R9))
(keybind end-of-line               ($esc "e "l))
(keybind goto-line                 ($esc "g "o))
(keybind goto-line                 ($R13 "g))
(keybind backward-character        ($esc "l "e))
(keybind backward-character        ($R10))
(keybind backward-character        (C-B))
(keybind next-page                 ($esc "p "d))
(keybind next-page                 ($R13 $R3))
(keybind previous-page             ($esc "p "u))
(keybind previous-page             ($R13 $R1))
(keybind forward-character         ($esc "r "i))
(keybind forward-character         ($R12))
(keybind forward-character         (C-F))
(keybind beginning-of-line         ($R7))
(keybind beginning-of-line         ($esc "s "l))
(keybind beginning-of-fold         ($esc "s "F))
(keybind beginning-of-fold         ($R1))
(keybind previous-line             ($esc "u "p))
(keybind previous-line             ($R8))
(keybind previous-line             (C-P))
(keybind backward-word             ($esc "l "w))
(keybind backward-word             ($R13 $R10))
(keybind forward-word              ($esc "r "w))
(keybind forward-word              ($R13 $R12))
(keybind mtool-top                 ($esc "s "f))
(keybind mtool-top                 ($R13 $R8))
(keybind mtool-bot                 ($esc "b "o))
(keybind mtool-bot                 ($R13 $R14))
(keybind goto-matching-fence       ($esc "]))
}}}
{{{  editing
(keybind double-line               ($R13 $R5))
(keybind double-line               ($esc "c "o))
(keybind copy-to-kill-buffer       ($R5))
(keybind copy-to-kill-buffer       ($esc "c "p))
(keybind move-line                 ($esc "m "o))
(keybind move-line                 ($R13 $R2))
(keybind kill-line                 ($esc "p "i))
(keybind kill-line                 ($R2))
(keybind insert-folded-kill-buffer ($esc "p "p))
(keybind insert-folded-kill-buffer ($R11))
(keybind newline-and-indent        (C-M))
(keybind case-word-capitalize      (C-W))
(keybind case-word-lower           (C-L))
(keybind case-word-upper           (C-U))
(keybind go_to_next_tab            (C-I))
(keybind transpose-characters      (C-T))
}}}
{{{  macros
(keybind save-keyboard-macro       ($esc "d "f))
(keybind define-macro              ($esc "d "m))
(keybind define-macro              ($R13 "d "m))
(keybind execute-macro             ($esc "c "m))
(keybind execute-macro             ($R13 "m))
(keybind execute-number-macro 1    ($esc "m "1))
(keybind execute-number-macro 2    ($esc "m "2))
(keybind execute-number-macro 3    ($esc "m "3))
(keybind execute-number-macro 4    ($esc "m "4))
(keybind execute-number-macro 5    ($esc "m "5))
(keybind execute-number-macro 6    ($esc "m "6))
(keybind execute-number-macro 7    ($esc "m "7))
(keybind execute-number-macro 8    ($esc "m "8))
(keybind execute-number-macro 9    ($esc "m "9))
}}}
{{{  deletes
(keybind delete-previous-character (C-H))
(keybind delete-character          (C-?))
(keybind delete-line               ($R13 $R9))
(keybind delete-line               ($esc "d "l))
(keybind delete-to-end-of-line     ($esc "d "e))
(keybind undo-delete-character     ($esc "u "c))
(keybind undo-delete-line          ($esc "u "l))
(keybind delspaces                 ($esc C-?))
(keybind append-to-previous-line   ($esc C-H))
}}}
{{{  finds
(keybind search-forward            ($esc "f "i))
(keybind search-reverse            ($esc "f "r))
(keybind incremental-search-forward($esc "i "s))
(keybind incremental-search-forward($R13 "f))
(keybind query-replace-string      ($esc "r "p))
(keybind query-replace-string      ($R13 "r))
}}}
{{{  specials
(keybind help                      ($esc "h "e))
(keybind help                      ($R13 "h))
(keybind redraw-display            ($esc $esc))
(keybind redraw-display            ($R13 $R13))
(keybind abort                     (C-\))
(keybind describe-bindings         ($R13 "?))
(keybind describe-bindings         ($esc "h "b))
(keybind quote-character           (C-Q))
}}}
{{{  shells/filter
(keybind save-and-exit-origami     ($esc "f "n))
(keybind shell                     ($esc "s "h))
(keybind exit-origami              ($esc "q "u))
(keybind exit-origami              ($R13 "q))
(keybind filter-buffer             ($esc "f "b))
(keybind pipe-from-command         ($esc "< "p))
(keybind pipe-to-command           ($esc "> "p))
(keybind shell-command             ($esc "s "c))
(keybind suspend-origami           (C-S))
}}}
{{{  files
(keybind insert-file               ($esc "i "n))
(keybind insert-file               ($R13 "i))
(keybind read-file                 ($esc "o "f))
(keybind read-file                 ($R13 "o))
(keybind save-file                 ($esc "s "a))
(keybind save-file                 ($R13 "s))
(keybind next-file                 ($esc "n "f))
(keybind previous-file             ($esc "p "f))
(keybind write-file                ($esc "w "f))
(keybind write-file                ($R13 "w))
}}}
{{{  modes
(keybind set-language              ($esc "l "a))
(keybind set-language              ($R13 "l))
(keybind add-mode-autosave         ($esc "+ "a))
(keybind add-mode-echo             ($esc "+ "e))
(keybind add-mode-overwrite        ($esc "+ "o))
(keybind add-mode-overwrite        ($R13 $Ins))
(keybind add-mode-view             ($esc "+ "v))
(keybind delete-mode-autosave      ($esc "- "a))
(keybind delete-mode-echo          ($esc "- "e))
(keybind delete-mode-overwrite     ($esc "- "o))
(keybind delete-mode-overwrite     ($Ins))
(keybind delete-mode-view          ($esc "- "v))
(keybind define-tab                ($esc C-I))
}}}
{{{  arguments
(keybind set-argument-0            ($esc "0))
(keybind set-argument-0            ($R13 "0))
(keybind set-argument-1            ($esc "1))
(keybind set-argument-1            ($R13 "1))
(keybind set-argument-2            ($esc "2))
(keybind set-argument-2            ($R13 "2))
(keybind set-argument-3            ($esc "3))
(keybind set-argument-3            ($R13 "3))
(keybind set-argument-4            ($esc "4))
(keybind set-argument-4            ($R13 "4))
(keybind set-argument-5            ($esc "5))
(keybind set-argument-5            ($R13 "5))
(keybind set-argument-6            ($esc "6))
(keybind set-argument-6            ($R13 "6))
(keybind set-argument-7            ($esc "7))
(keybind set-argument-7            ($R13 "7))
(keybind set-argument-8            ($esc "8))
(keybind set-argument-8            ($R13 "8))
(keybind set-argument-9            ($esc "9))
(keybind set-argument-9            ($R13 "9))
}}}
{{{  mouse
@if-using (MOUSY)
   ( mouse-buttons
        go-mouse
        go-and-open-mouse
        go-and-close-mouse
   )
@fi
}}}
