{{{F fun/xsel
:::F fun/xsel
}}}
@if-using (L-EXT)
   {{{F fun/std_c
   :::F fun/std_c
   }}}
@fi
{{{F fun/tab
:::F fun/tab
}}}
{{{  buffer-handling
{{{F fun/file-buffers
:::F fun/file-buffers
}}}
{{{  add-mode-buffer-save
( deffun add-mode-buffer-save ( set-counter buff-saving 1 set-user-mode BS ) )
}}}
{{{  delete-mode-buffer-save
( deffun delete-mode-buffer-save ( set-counter buff-saving 0 reset-user-mode BS ) )
}}}
}}}
{{{  create-fold-
( deffun create-fold-
   ( if and(@if-using (L-EXT) counter>0 extended @fi counter-0 fold-activ)
      ( switch-to-move-mode )
     else
      ( if counter-0 fold-activ
         ( set-counter fold-activ 1 create-fold )
        else
         ( ; to reset the old displayed message
           if or(last-message M_NO_BACK_FOLDING last-message M_FOLDERR ) () fi
           ; try to create the fold
           create-fold
           set-counter fold-activ counter or(last-message M_NO_BACK_FOLDING
                                             last-message M_FOLDERR )
         )
        fi
      )
     fi
   )
)
}}}
{{{  filerequester
@if-using ( FILEREQUEST )
   ( deffun read-file- ( read-file file-requester ) )
   ( deffun insert-file- ( insert-file file-requester ) )
   ( deffun write-file- ( write-file file-requester ) )
   ( deffun enter-fold-- ( enter-fold if in-prompt ( file-requester ) fi ) )
@fi
@if-using not( FILEREQUEST )
   ( defmac read-file- ( read-file ) )
   ( defmac insert-file- ( insert-file ) )
   ( defmac write-file- ( write-file ) )
   ( defmac enter-fold-- ( enter-fold ) )
@fi
}}}
{{{  enter-fold-
( deffun enter-fold-
   ( @if-using (L-EXT)
     if and(test-text counter>0 extended not(in-prompt))
      ( case
         {{{  c : try to move to #include"*name"
         ( test-language "c
            ( set-counter x store-pos
              beginning-of-line
              if test-char "#
               {{{  try to move to "name
               ( while not(or(test-char "" test-end-line))
                  ( forward-character )
                 if test-char "" ( forward-character ) fi
               )
               }}}
              fi
            )
         )
         }}}
        esac
      )
     fi
     @fi
     enter-fold--
   )
)
}}}
{{{  auto-indent
( defvar ( auto-indent ) )
{{{  add-mode-auto-indent
( deffun add-mode-auto-indent
   ( set-counter auto-indent 1
     set-user-mode AI
   )
)
}}}
{{{  delete-mode-auto-indent
( deffun delete-mode-auto-indent
   ( set-counter auto-indent 0
     reset-user-mode AI
   )
)
}}}
{{{  newline-and-indent-
( deffun newline-and-indent-
   ( if or(in-prompt counter>0 auto-indent)
      ( newline-and-indent )
     else
      ( newline-and-indent
        "$
        goto-counter 1
        delspaces
        delete-character
      )
     fi
   )
)
}}}
}}}
{{{  save-file-with-leading-tabs
( deffun save-file-with-leading-tabs
   ( if not(in-prompt)
      ( pipe-to-command
        if in-prompt
         ( "unexpand "  ">$ORIFILE
           newline-and-indent
           set-file-unchanged
         )
        fi
      )
     fi
   )
)
}}}
{{{  fill-paragraph
@use (TEX-FILL)
{{{F fun/fillpara
:::F fun/fillpara
}}}
{{{  set-fill-column-
( deffun set-fill-column-
   ( para
     set-fill-column
     edit
   )
)
}}}
}}}
{{{  language-dependent extensions for '"..
@if-using (L-EXT)
   {{{  parens
   ( deffun paired-parens
      ( "(
        if and(counter>0 extended,
               not(in-prompt),
               or(test-language "p,
                  test-language "c,
                  test-language "o,
                  test-language "i,
                  test-language "t))

         ( ") backward-character )
        fi
      )
   )
   }}}
   {{{  brackets
   ( deffun paired-brackets
      ( "[
        if and(counter>0 extended,
               not(in-prompt),
               or(test-language "p,
                  test-language "c,
                  test-language "o,
                  test-language "i))
         ( "] backward-character )
        fi
      )
   )
   }}}
   {{{  curly brackets
   ( deffun paired-curly-brackets
      ( case
         (in-prompt ())
         (not(test-text) ())
         {{{  c-mode
         ( test-language "c
           @if-using (MY-C-CB)
            ( my-c-cb )
           @fi
           @if-using not(MY-C-CB)
            {{{  {} at right position
            ( 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
                 if counter>0 +(x_pos_1 set-space-enter -1)
                  ( goto-counter x_pos_1 "  )
                 fi
               )
              fi
              "{ newline-and-indent "} previous-line "  ;
              return-from-macro
            )
            }}}
           @fi
         )
         }}}
         {{{  p-mode
         ( test-language "p
           @if-using (MY-P-CB)
            ( my-p-cb )
           @fi
           @if-using not(MY-P-CB)
            {{{  begin/end at right position
            ( set-counter x_pos_1 store-pos
              beginning-of-line
              if not(test-char " )
               ( set-counter x_pos_1 store-pos
                 end-of-line
                 newline-and-indent "  "  ;
               )
              else
               ( goto-counter x_pos_1 )
              fi
              "begin
              newline-and-indent
              newline-and-indent
              "end
              previous-line
              backward-character
              return-from-macro
            )
            }}}
           @fi
         )
         }}}
         {{{  occam
         ( or(test-language "t test-language "o)
            ( end-of-line
              newline-and-indent
              "SEQ
              newline-and-indent
              "  "  ;
              return-from-macro
            )
         )
         }}}
        esac
        "{
      )
   )
   }}}
   {{{  doublequotes
   ( deffun doublequotes
      ( ""
        if and(counter>0 extended,
               not(in-prompt),
               or(test-language "p,
                  test-language "c,
                  test-language "o,
                  test-language "i))
         ( "" backward-character )
        fi
   ))
   }}}
   {{{  singlequotes
   ( deffun singlequotes
      ( "'
        if and(counter>0 extended,
               not(in-prompt),
               or(test-language "p,
                  test-language "c,
                  test-language "o,
                  test-language "i))
         ( "' backward-character )
        fi
      )
   )
   }}}
   {{{  semicolon
   ( deffun semicolon
      ( if and(counter>0 extended,
               not(in-prompt),
               test-text,
               or(test-language "c,test-language "p))
        @if-using (MY-L-SEMICOLON)
         ( my-l-semicolon )
        @fi
        @if-using not(MY-L-SEMICOLON)
         {{{  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(test-language "c,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
           return-from-macro
         )
         }}}
        @fi
        fi
        ";
      )
   )
   }}}
@fi
}}}
{{{  file-menu
( deffun file-menu
   ( if in-prompt ( newline-and-indent return-from-macro ) fi
     set-counter x 0
     menu-counter x ( "bindings "  "help "  "save "  "read "  "insert "  "ok "  "exit-origami)
     case
      ( counter-0 x ( describe-bindings ) )
      ( counter-0 +(x -1) ( help ) )
      ( counter-0 +(x -2) ( save-file ) )
      ( counter-0 +(x -3) ( read-file- ) )
      ( counter-0 +(x -4) ( insert-file- ) )
      ( counter-0 +(x -6) ( exit-origami ) )
     default
      ( return-from-macro )
     esac
   )
)
}}}
{{{  extend some simple commands for open-fold-lines
{{{  front-fold-action
( defvar ( action action-pos ) )
( deffun front-fold-action
   ( if and(not(in-prompt) or(test-begin-fold test-end-fold))
      ( set-counter action-pos store-pos
        beginning-of-line
        if not(counter>0 -(action-pos store-pos))
         ( if test-end-fold
            ( set-counter action-pos cursor-level )
           else
            ( set-counter action-pos 0 )
           fi
           @if-using (SCR-OFF)
              screen-off
           @fi
           close-fold
           if counter-0 -(action delete-character)
            ( set-counter action delete-previous-character )
           fi
           insert-ascii action
           open-fold
           if action-pos ( mtool-bot set-cursor-line action-pos ) fi
           @if-using (SCR-OFF)
              screen-on
              redraw-display
           @fi
           return-from-macro
         )
        fi
        goto-counter action-pos
      )
     fi
     insert-ascii action
   )
)
}}}
{{{  wrap-word-
( deffun wrap-word-
   ( set-counter action execute-number-macro wrap-word
     front-fold-action
   )
)
}}}
{{{  delete-character-
( deffun delete-character-
   ( set-counter action delete-character
     front-fold-action
   )
)
}}}
{{{  delete-character-
( deffun delete-previous-character-
   ( set-counter action delete-previous-character
     front-fold-action
   )
)
}}}
}}}
