{{{  comments
; this macro package can read/savte the kill-/delete- and move-buffer from/to
; files. Therefor it must enter a filed fold, so that the currently edited
; file will be saved.
; If no tag DUMB-FILE is set, the file $HOME/.origamibuf is used. Otherwise
; you have to define a macro 'dumb-file', which genereates the filename on a
; empty text-line.
}}}
@if-using not(BUFF-FILER)
   @use (BUFF-FILER)
   {{{F fun/error
   :::F fun/error
   }}}
   {{{  bf-action
   @if-using not(DUMB-FILE)
      {{{  dumb-file
      ( defmac dumb-file
         ( pipe-from-command
              "echo "  "$HOME/.origamibuf
           newline-and-indent
         )
      )
      }}}
   @fi
   {{{  using the mark-versions for buffers, maybe define the macros here!
   @if-using not(MOVE-MARK)
      ( defmac move-line- ( move-line ) )
   @fi
   @if-using not(KILL-MARK)
      ( defmac kill-line- ( kill-line ) )
      ( defmac insert-folded-kill-buffer- ( insert-folded-kill-buffer ) )
   @fi
   }}}

   ( defvar ( bf-save bf-delay bf-view bf-move bf-error ) )

   ( deffun bf-action
      (
        {{{  save the file
        if or ( and ( test-view test-file-changed )
                pre ( save-file ) test-file-changed
              )
         ( message ( M_NO_OUTFILE ", M_FAILED )
           show-cursor 20
         )
        fi
        }}}
        {{{  get old status of Origami
        set-counter bf-error 0
        delete-mode-autosave set-counter bf-delay ocl-argument
        set-counter bf-view 0
        if test-view ( set-counter bf-view 1 delete-mode-view ) fi
        set-counter bf-move 0
        if test-top ( set-counter bf-move 1 next-line ) fi
        }}}
        screen-off
        {{{  create the fold with header of dumb-filename
        create-fold
        create-fold
        open-fold
        next-line
        dumb-file
        close-fold
        auto-header
        }}}
        if bf-save
         {{{  save the buffer to file, leave filed-fold
         ( enter-fold
           next-line
           beginning-of-line create-fold create-fold "move
           enter-fold move-line- exit-fold
           beginning-of-line create-fold create-fold "delete
           enter-fold undo-delete-line exit-fold
           beginning-of-line create-fold create-fold "kill
           enter-fold insert-folded-kill-buffer- unfold-fold exit-fold
           previous-line
           delete-line
           exit-fold
           toggle-file-fold if in-prompt ( "y newline-and-indent ) fi
         )
         }}}
        else
         {{{  remove the name-line and attach
         ( enter-fold
           delete-line
           exit-fold
           attach-file-to-fold
         )
         }}}
        fi
        if not( test-filed ) ( set-counter bf-error 1 delete-line ) fi
        if not( bf-error )
         {{{  read the buffers
         ( set-file-unchanged
           enter-fold
           end-of-fold
           move-line-
           undo-delete-line
           insert-folded-kill-buffer-
           beginning-of-fold
           next-line
           enter-fold
           while not( test-end-fold ) ( kill-line- )
           exit-fold
           next-line
           enter-fold
           delete-line
           exit-fold
           next-line
           enter-fold
           move-line-
           exit-fold
           set-file-unchanged
           exit-fold
         )
         }}}
        fi
        {{{  restore old status
        set-file-unchanged
        if bf-view ( add-mode-view ) fi
        if bf-delay ( add-mode-autosave counter bf-delay newline-and-indent ) fi
        if bf-error ( message ( M_FAILED ) show-cursor 20 ) fi
        }}}
        screen-on
        redraw-display
      )
   )
   }}}
   {{{  dumb-buffers-to-file
   ( deffun dumb-buffers-to-file ( set-counter bf-save 1 bf-action ) )
   }}}
   {{{  get-buffers-from-file
   ( deffun get-buffers-from-file ( set-counter bf-save 0 bf-action ) )
   }}}
   {{{  undeclares
   ( undeclare ( bf-action bf-save bf-delay bf-view bf-move bf-error ) )
   @if-using not(MOVE-MARK)
      ( undeclare ( move-line- ) )
   @fi
   @if-using not(KILL-MARK)
      ( undeclare ( kill-line- insert-folded-kill-buffer- ) )
   @fi
   @if-using not(DUMB-FILE)
      ( undeclare ( dumb-file ) )
   @fi
   }}}
@fi
