;- == to do

@if-using(not-used)
{{{  fun/xxx
{{{F fun\standard
:::F E:\TC\ORIGAMI\BINDINGS\fun\standard
}}}
{{{F fun\startup
:::F E:\TC\ORIGAMI\BINDINGS\fun\startup
}}}
{{{F fun\wordmacs
:::F E:\TC\ORIGAMI\BINDINGS\fun\wordmacs
}}}
{{{F fun\savetabs
:::F E:\TC\ORIGAMI\BINDINGS\fun\savetabs
}}}
{{{F fun\append
:::F E:\TC\ORIGAMI\BINDINGS\fun\append
}}}
{{{F fun\maze-mac
:::F E:\TC\ORIGAMI\BINDINGS\fun\maze-mac
}}}
}}}
@fi
{{{  notes about this binding
; This is my personal ST keybinding.  Many keys behave like they do in other
; ST programs.  Some of the keybindings for functions which do not exist in
; other editors are taken from or are similar to the emacs-like keybinding
; while other functions have completely different keys assigned to them.
;
; This keybinding includes some of the macros, as far as they can be used on
; the ST:
;   towers-of-hanoi            = ESC h a n o i
;   fill-paragraph             = ESC f p
;     set-fill-column          = ESC s c
;   goto-matching-fence        = ESC (   or   ESC )
;   lookup                     = ESC l u   (shell required)
;   put-pick-and-copy-pick     = CTRL-V (used as standard paste function)
;   Tab                        = TAB
;   set tabwidth               = ESC TAB
;   top of current fold        = ESC UP
;   bottom of current fold     = ESC DOWN
;   compile current keybinding = ESC m k
;
; I have also included the UN*X-Version of the mode/automacros. At  least
; C- , Pascal- and TeX-Mode will be useful. If you have  any  good  ideas
; what mode-specific functions might be implemented, tell me ...
;
; This keybinding can be used on a unix  system  with  X11/xterm,  too  -
; simply use the -Uxterm option when running keybind.
;
; Michael Schwingen
; michaels@messua.informatik.rwth-aachen.de
}}}

{{{  conditional compilation for different terminals & features
; you can define the following symbols by using the -Uxxx option of keybind:
;
; c_mode   to activate the c-mode-macros
; xterm    to generate keybindings for a xterm terminal rather than a ST

{{{  default: use ST binding if nothing else specified
@if-using not(xterm)
@use(st-keyb)
@use(mouse)
@use(towers)
@use(maze)
;@write( "generating " "default " "ST " "bindings. )
@fi
}}}
@if-using(st-keyb)
{{{  this is a real ST
  (defbinding Origami-ST)
}}}
{{{  aliases for special ST keys (cursor etc.)
  {{{  DEL, RETURN, HELP, ...
  (alias ESC ($esc))
  (alias DEL ($rubout))
  (alias RETURN ($meta C-M))
  (alias S-RETURN ($smeta C-M))
  (alias C-RETURN ($cmeta C-M))
  (alias ENTER  ($meta "M))
  (alias BACKSPACE ($backspace))
  (alias HELP ($meta C-V))
  (alias TAB ($meta C-I))

  (alias INSERT ($meta C-F))
  (alias S-INSERT ($smeta C-F))
  (alias S-BACKSPACE ($smeta C-H))
  (alias HOME ($home))
  (alias S-HOME ($smeta C-A))
  (alias C-HELP ($cmeta "s))
  (alias S-HELP ($smeta C-V))
  (alias UNDO ($meta C-U))
  (alias S-UNDO ($smeta C-U))
  (alias CTRL-UNDO ($cmeta "r))
  (alias Key_- ($meta "-))          ; '+' on numeric keypad
  (alias Key_+ ($meta "+))          ; '-' on numeric keypad
  }}}
  {{{  Cursor Keys
  (alias UP ($up))
  (alias DOWN ($down))
  (alias LEFT ($left))
  (alias RIGHT ($right))
  (alias S-UP ($smeta C-B))
  (alias CTRL-UP ($cmeta "l))
  (alias S-LEFT ($smeta C-C))
  (alias CTRL-LEFT ($cmeta "m))
  (alias S-RIGHT ($smeta C-D))
  (alias CTRL-RIGHT ($cmeta "n))
  (alias S-DOWN ($smeta C-E))
  (alias CTRL-DOWN ($cmeta "o))
  }}}
  {{{  special CTRL-Keys
  (alias CTRL-ESC ($cmeta $ESC))
  (alias C-2 ($cmeta "2))
  (alias C-M ($cmeta C-M))
  (alias CTRL-KEY-1 ($cmeta "B))
  (alias CTRL-KEY-2 ($cmeta "C))
  (alias CTRL-KEY-3 ($cmeta "D))
  }}}
  {{{  ALT-Keys
  (alias ALT-C ($ameta "C))
  (alias ALT-L ($ameta "L))
  (alias ALT-M ($ameta "M))
  (alias ALT-Q ($ameta "Q))
  (alias ALT-R ($ameta "R))
  (alias ALT-S ($ameta "S))
  (alias ALT-V ($ameta "V))
  (alias ALT-Y ($ameta "Y))
  }}}
  {{{  Shift+Function-Keys
  (alias S-F1 ($smeta C-J))
  (alias S-F2 ($smeta C-K))
  (alias S-F3 ($smeta C-L))
  (alias S-F4 ($smeta C-N))
  (alias S-F5 ($smeta C-O))
  (alias S-F6 ($smeta C-P))
  (alias S-F7 ($smeta C-Q))
  (alias S-F8 ($smeta C-S))
  (alias S-F9 ($smeta C-S))
  (alias S-F10 ($smeta C-T))
  }}}
}}}
@fi
@if-using(xterm)
;@write( "generating " "Xterm " "bindings. )
{{{  this is the ST-like binding
  (defbinding ST-like-Origami)
}}}
{{{  aliases for X11 xterm special keys (works on SUN)
(alias ESC ($esc))
(alias rubout (C-?))
(alias _up ($esc "[ "A))
(alias _down ($esc "[ "B))
(alias _left ($esc "[ "D))
(alias _right ($esc "[ "C))
(alias INS ($esc "[ "2))
(alias HELP ($esc "[ "1 "9 "6 "z))
(alias ESC ($esc))
(alias BACKSPACE ($backspace))
(alias DEL ($rubout))
(alias TAB (C-I))
(alias UP ($_up))
(alias DOWN ($_down))
(alias LEFT ($_left))
(alias RIGHT ($_right))
(alias RETURN (C-M))

(alias prev_page ($ESC "[ "2 "1 "6 "z))
(alias next_page ($ESC "[ "2 "2 "2 "z))
(alias HOME ($ESC "[ "2 "1 "4 "z))
(alias END ($ESC "[ "2 "2 "0 "z))
@if-using(xterm)
(alias K-5 ($ESC "[ "2 "1 "8 "z))
@fi
}}}
(keybind abort (C-\))
@fi
}}}

{{{  OCL macros
  @if-using (towers)
  ;@write( "using " "towers-of-hanoi " "macros. )
  {{{F fun/towers
  :::F fun/towers
  }}}
  (keybind towers-of-hanoi ($ESC "h "a "n "o "i ))
  @fi
  {{{F fun/delspaces
  :::F fun/delspaces
  }}}
  {{{F fun/append
  :::F fun/append
  }}}
  (keybind append-to-previous-line ($ESC $BACKSPACE))

  {{{  save/restore position
  (deffun save-position(
    set-counter save_pos_x store-pos
    set-counter save-pos-y store-line
  ))
  (deffun restore-position(
    goto-line-counter save-pos-y
    goto-counter save_pos_x
  ))
  (keybind save-position ($ESC "s "p))
  (keybind restore-position ($ESC "r "p))
  }}}

  {{{F fun/fillpara
  :::F fun/fillpara
  }}}
  (keybind set-fill-column ($ESC "s "c))
  (keybind fill-paragraph ($ESC "f "p))
  (keybind inv-blank-handle ($ESC "f "m))
  @if-using ($f1)
  {{{  format-para-1
  (deffun format-para-1
  (
    beginning-of-line newline-and-indent append-to-previous-line "  "  next-line
    beginning-of-line "  "   set-counter fill-save-y -(0 store-line)
    previous-line fill-paragraph

    while counter>0 +(store-line fill-save-y)
    (
      beginning-of-line delete-previous-character delete-previous-character
      previous-line
    )
    if counter>0 -(0 +(store-line fill-save-y))
    (
      next-line
    ) else
    (
      beginning-of-line delete-previous-character delete-previous-character
    ) fi
    fill-paragraph
    beginning-of-line next-line
  ))
  (keybind format-para-1 ($f1))
  }}}
  @fi
  @if-using ($f2)
  {{{  format-para-2
  (deffun format-para-2
  (
    beginning-of-line
    set-counter fill-save-y store-line
    set-counter fill-save-x store-pos
    delete-character "  ;
    fill-paragraph
    set-counter fill-tmp store-line
    goto-line-counter fill-save-y
    goto-counter fill-save-x
    "- delete-character
    goto-line-counter fill-tmp
    next-line
    beginning-of-line
  ))
  (keybind format-para-2 ($f2))
  }}}
  @fi

  {{{F fun/go-match
  :::F fun/go-match
  }}}
  (keybind goto-matching-fence ($ESC "( ))
  (keybind goto-matching-fence ($ESC ") ))

  {{{F fun/lookup
  :::F fun/lookup
  }}}
  (keybind lookup ($ESC "l "u))

  {{{F fun/put-pick
  :::F fun/put-pick
  }}}
  {{{F fun/tab
  :::F fun/tab
  }}}
  (keybind go_to_next_tab ($TAB))
  (keybind define-tab ($ESC $TAB))

  {{{F fun/mt-fold
  :::F fun/mt-fold
  }}}
  (keybind mtool-top ($ESC $UP))      ; goto top of current fold
  (keybind mtool-bot ($ESC $DOWN))    ; goto bottom of current fold

  {{{  make-keybinding
  (deffun make-binding (save-file
                        shell-command "keybind " "-s "  "$ORIFILE
                        newline-and-indent newline-and-indent))
  (keybind make-binding ($ESC "m "k))
  }}}
  @if-using(st-keyb)
  {{{  unindent line
  (deffun unindent-line (
    previous-line
    end-of-line
    delete-character
    delspaces
    newline-and-indent
  ))
  (keybind unindent-line ($S-BACKSPACE))
  }}}
  @fi
  {{{  clear pick-buffer
  (deffun clear-pick-buffer (
    end-of-line
    newline-and-indent
    kill-line
    beginning-of-line
  ;  backward-word
    insert-folded-kill-buffer
    delete-line
    previous-line
    message-exit ("pick " "buffer " "cleared )
  ))
  }}}
  @if-using(maze)
  ;;@write( "using " "maze-macros. )
  {{{F fun/maze-mac
  :::F fun/maze-mac
  }}}
  (keybind get-new-maze    ($ESC "m "1))
  (keybind set-destination ($ESC "m "2))
  (keybind maze-step       ($ESC "m "3))
  @fi
  {{{F fun/wordmacs
  :::F fun/wordmacs
  }}}

  {{{F fun/oripager
  :::F fun/oripager
  }}}

  (keybind pager-start ($ESC "p "s))
  (keybind pager-end ($ESC "p "e))
  (keybind pager-next ($ESC "p "n))
  (keybind pager-previous ($ESC "p "p))

@if-using (st-keyb)
  {{{  disk list functions
  {{{F fun/disklist
  :::F fun/disklist
  }}}
  (keybind read-short-info-a ($ESC "r "a))
  (keybind read-short-info-b ($ESC "r "b))
  (keybind read-info-a       ($ESC "R "A))
  (keybind read-info-b       ($ESC "R "B))
  }}}
@fi

}}}
{{{  mouse functions
@if-using (mouse)
;@write( "using " "mouse." )
{{{  set-cursor
(deffun set-cursor(
  if not(in-prompt)
  (
    {{{  x-movement
    if counter>0 mouse-go-x (
      while counter>0 mouse-go-x
      (
        forward-character
        add-counter mouse-go-x -1
      )
    ) else (
      inv-counter mouse-go-x
      while counter>0 mouse-go-x
      (
        backward-character
        add-counter mouse-go-x -1
      )
    ) fi
    }}}
    {{{  y-movement
    if counter>0 mouse-go-y (
      while counter>0 mouse-go-y
      (
        next-line
        add-counter mouse-go-y -1
      )
    ) else (
      inv-counter mouse-go-y
      while counter>0 mouse-go-y
      (
        previous-line
        add-counter mouse-go-y -1
      )
    ) fi
    }}}
  )fi
))
}}}
{{{  open-and-close
(deffun open-and-close(
  if not(in-prompt)
  (
    set-cursor
    if test-fold-line (
      open-fold
    ) else (
      close-fold
    ) fi
  )fi
))
}}}
{{{  top-bottom
(deffun top-bottom(
  if not(in-prompt)
  (
    set-cursor
    if test-begin-fold (
      mtool-bot
    ) else (
      mtool-top
    ) fi
  )fi
))
}}}
(mouse-buttons set-cursor open-and-close top-bottom open-and-close)
@fi
}}}
{{{  ST GEM menu bar
@if-using(st-keyb)
  (keybind put-pick-and-copy-pick   ($mmeta "3))

  (deffun do_nothing (
    return-from-macro
  ))
  (keybind do_nothing               ($mmeta "@))
@fi
}}}

{{{  moving cursor
@if-using(st-keyb)
  (keybind backward-word ($CTRL-LEFT))
  (keybind forward-word ($CTRL-RIGHT))
  (keybind beginning-of-line ($S-LEFT))
  (keybind end-of-line ($S-RIGHT))
  (keybind previous-page ($S-UP))
  (keybind next-page ($S-DOWN))
  (keybind beginning-of-fold ($HOME))
  (keybind end-of-fold ($S-HOME))
@fi
@if-using (xterm)
  (keybind beginning-of-line ($HOME))
  (keybind end-of-line ($END))
;  (keybind previous-page ($ESC $UP))
;  (keybind next-page ($ESC $DOWN))
@fi
  (keybind backward-character ($LEFT))
  (keybind backward-character (C-F))
  (keybind forward-character ($RIGHT))
  (keybind forward-character (C-G))
  (keybind beginning-of-line ($ESC $LEFT))
  (keybind end-of-line ($ESC $RIGHT))
  (keybind previous-line ($UP))
  (keybind previous-line (C-T))
  (keybind next-line ($DOWN))
  (keybind next-line (C-V))
  (keybind previous-page ($prev_page))
  (keybind next-page ($next_page))
  (keybind beginning-of-fold ($ESC "<))
  (keybind end-of-fold ($ESC ">))
  (keybind goto-line ($ESC "g))
}}}
{{{  folding
  (keybind open-fold (C-O))
  (keybind close-fold (C-C))
  (keybind enter-fold ($ESC "o))
;  (keybind enter-fold ($ESC "O))
  (keybind exit-fold ($ESC "c))
  (keybind exit-fold ($ESC "C))
  (keybind unfold-fold (C-U))
  (keybind create-fold (C-N))
  (keybind auto-header ($ESC "a "h))
  (keybind auto-header ($ESC "A "H))
  (keybind toggle-file-fold ($ESC "f "f))
  (keybind toggle-file-fold ($ESC "F "F))
  (keybind attach-file-to-fold ($ESC "a "f))
  (keybind attach-file-to-fold ($ESC "A "F))
}}}
{{{  editing
@if-using(st-keyb)
  (keybind newline-and-indent ($ENTER))
  (keybind copy-to-kill-buffer ($UNDO))
  (keybind insert-folded-kill-buffer ($ALT-V))
  (keybind put-pick-and-copy-pick ($S-UNDO))
  (keybind clear-pick-buffer ($CTRL-UNDO))
  (keybind move-line ($ALT-M))
  (keybind double-line ($C-2))
@fi
  (keybind newline-and-indent ($RETURN))
  (keybind delete-previous-character ($BACKSPACE))
  (keybind undo-delete-character ($ESC $DEL))
  (keybind delete-character ($DEL))
  (keybind delete-to-end-of-line (C-K))
  (keybind kill-line (C-Y))
  (keybind copy-to-kill-buffer ($ESC "y))
  (keybind copy-to-kill-buffer ($ESC "Y))
  (keybind put-pick-and-copy-pick ($ESC "v))
  (keybind put-pick-and-copy-pick ($ESC "V))
  (keybind move-line ($ESC "m "m))
  (keybind move-line ($ESC "M "M))
  (keybind double-line ($ESC "d "l))
  (keybind double-line ($ESC "D "L))
  (keybind case-word-capitalize ($ESC "w "c))
  (keybind case-word-capitalize ($ESC "W "C))
  (keybind case-word-lower ($ESC "w "l))
  (keybind case-word-lower ($ESC "W "L))
  (keybind case-word-upper ($ESC "w "u))
  (keybind case-word-upper ($ESC "W "U))
}}}
{{{  search & replace
@if-using(st-keyb)
  (keybind query-replace-string ($ALT-R))
@fi
  (keybind incremental-search-forward (C-L))
  (keybind incremental-search-reverse ($ESC C-L))
  (keybind replace-string (C-R))
  (keybind query-replace-string ($ESC "q "r))
  (keybind query-replace-string ($ESC "Q "R))
}}}
{{{  files
@if-using(st-keyb)
  (keybind save-file ($ALT-S))
@fi
  (keybind insert-file   (C-X C-I))
  (keybind save-file     (C-S))
  (keybind save-file     (C-X C-S))
  (keybind write-file    (C-X C-W))
  (keybind read-file     (C-X C-R))
  (keybind read-file     (C-X C-O))
  (keybind next-file     (C-X C-N))
  (keybind previous-file (C-X C-P))
  (keybind set-file-unchanged (C-X C-U))
}}}
{{{  modes and arguments
  (keybind set-argument-0 ($ESC "0))
  (keybind set-argument-1 ($ESC "1))
  (keybind set-argument-2 ($ESC "2))
  (keybind set-argument-3 ($ESC "3))
  (keybind set-argument-4 ($ESC "4))
  (keybind set-argument-5 ($ESC "5))
  (keybind set-argument-6 ($ESC "6))
  (keybind set-argument-7 ($ESC "7))
  (keybind set-argument-8 ($ESC "8))
  (keybind set-argument-9 ($ESC "9))

  (keybind add-mode-overwrite ($ESC "+ "o))
  (keybind add-mode-overwrite ($ESC "+ "O))
@if-using(st-keyb)
  (keybind add-mode-overwrite ($S-INSERT))
  (keybind delete-mode-overwrite ($INSERT))
@fi
  (keybind delete-mode-overwrite ($ESC "- "o))
  (keybind delete-mode-overwrite ($ESC "- "O))

  (keybind add-mode-view ($ESC "+ "v))
  (keybind add-mode-view ($ESC "+ "V))
  (keybind delete-mode-view ($ESC "- "v))
  (keybind delete-mode-view ($ESC "- "V))

  (keybind add-mode-echo ($ESC "+ "e))
  (keybind add-mode-echo ($ESC "+ "E))
  (keybind delete-mode-echo ($ESC "- "e))
  (keybind delete-mode-echo ($ESC "- "E))

  (keybind add-mode-autosave ($ESC "+ "a))
  (keybind add-mode-autosave ($ESC "+ "A))
  (keybind delete-mode-autosave ($ESC "- "a))
  (keybind delete-mode-autosave ($ESC "- "A))

  (keybind add-mode-wrap ($ESC "+ "w))
  (keybind add-mode-wrap ($ESC "+ "W))
  (keybind delete-mode-wrap ($ESC "- "w))
  (keybind delete-mode-wrap ($ESC "- "W))
}}}
{{{  keyboard macros
@if-using(st-keyb)
;-  (keybind execute-macro-1 ($f6))
;-  (keybind execute-macro-2 ($f7))
;-  (keybind execute-macro-3 ($f8))
;-  (keybind execute-macro-4 ($f9))
;-  (keybind execute-macro-5 ($f10))
  (keybind define-macro (C-M C-D))
@fi
  (keybind define-macro ($ESC "m "d))
  (keybind define-macro ($ESC "M "D))
  (keybind execute-macro (C-A))
  (keybind save-keyboard-macro ($ESC "d "f))
  (keybind save-keyboard-macro ($ESC "D "F))
}}}
{{{  shell commands
  (keybind shell (C-Z))
  (keybind shell-command ($ESC "!))
}}}
{{{  special functions
@if-using(st-keyb)
  (keybind describe-fold ($S-HELP))
  (keybind help ($C-HELP))
  (keybind quote-character ($CTRL-ESC))
@fi
@if-using(xterm)
  (keybind redraw-display ($K-5))
@fi
  (keybind redraw-display (C-W))
  (keybind set-language ($ESC "s "l))
  (keybind set-language ($ESC "S "L))
  (keybind help ($ESC "h "e "l "p))
  (keybind help ($ESC "H "E "L "P))
  (keybind describe-bindings ($ESC "?))
  (keybind describe-bindings ($HELP))
  (keybind describe-fold ($ESC "=))
  (keybind filter-buffer ($ESC "f "b))
  (keybind filter-buffer ($ESC "F "B))
  (keybind pipe-from-command ($ESC "p "f))
  (keybind pipe-from-command ($ESC "P "F))
  (keybind pipe-to-command ($ESC "p "t))
  (keybind pipe-to-command ($ESC "P "T))
  (keybind pipe-kbd-from-command ($ESC "p "k))
  (keybind pipe-kbd-from-command ($ESC "P "K))
  (keybind quote-character ($ESC "q "u))
}}}
{{{  how to get out
@if-using(st-keyb)
  (keybind exit-origami ($ALT-Q))
  (keybind save-and-exit-origami ($CTRL-KEY-1))
  (keybind save-and-exit-origami ($CTRL-KEY-2))
  (keybind save-and-exit-origami ($CTRL-KEY-3))
@fi
  (keybind exit-origami (C-Q))
  (keybind exit-origami (C-X C-C))
}}}

{{{  auto-startup and mode macros
{{{  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
}}}
{{{F fun/startup
:::F fun/startup
}}}
(read-newfile-macro start-up)
(keybind skip-mode ($ESC "s "m))
}}}
{{{  standard macros & c-mode
{{{F fun/standard
:::F fun/standard
}}}
(keybind space ("  ))
(keybind parens ("( ))
(keybind brackets ("[ ))
(keybind curly-brackets ("{ ))
(keybind doublequotes ("" ))
(keybind singlequotes ("' ))
(keybind semicolon ("; ))
}}}

