Function: ewoc-create

ewoc-create is an autoloaded and byte-compiled function defined in ewoc.el.gz.

Signature

(ewoc-create PRETTY-PRINTER &optional HEADER FOOTER NOSEP)

Documentation

Create an empty ewoc.

The ewoc will be inserted in the current buffer at the current position.

PRETTY-PRINTER should be a function that takes one argument, an element, and inserts a string representing it in the buffer (at point). The string PRETTY-PRINTER inserts may be empty or span several lines. The PRETTY-PRINTER should use insert, and not insert-before-markers.

Optional second and third arguments HEADER and FOOTER are strings, possibly empty, that will always be present at the top and bottom, respectively, of the ewoc.

Normally, a newline is automatically inserted after the header, the footer and every node's printed representation. Optional fourth arg NOSEP non-nil inhibits this.

View in manual

Probably introduced at or before Emacs version 22.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ewoc.el.gz
;;; ===========================================================================
;;;                  Public members of the Ewoc package

;;;###autoload
(defun ewoc-create (pretty-printer &optional header footer nosep)
  "Create an empty ewoc.

The ewoc will be inserted in the current buffer at the current position.

PRETTY-PRINTER should be a function that takes one argument, an
element, and inserts a string representing it in the buffer (at
point).  The string PRETTY-PRINTER inserts may be empty or span
several lines.  The PRETTY-PRINTER should use `insert', and not
`insert-before-markers'.

Optional second and third arguments HEADER and FOOTER are strings,
possibly empty, that will always be present at the top and bottom,
respectively, of the ewoc.

Normally, a newline is automatically inserted after the header,
the footer and every node's printed representation.  Optional
fourth arg NOSEP non-nil inhibits this."
  (let* ((dummy-node (ewoc--node-create 'DL-LIST 'DL-LIST))
         (dll (progn (setf (ewoc--node-right dummy-node) dummy-node)
                     (setf (ewoc--node-left dummy-node) dummy-node)
                     dummy-node))
         (wrap (if nosep 'identity 'ewoc--wrap))
         (new-ewoc (ewoc--create (current-buffer)
                                 (funcall wrap pretty-printer)
                                 dll))
         (hf-pp (funcall wrap 'insert))
         (pos (point))
         head foot)
    (ewoc--set-buffer-bind-dll new-ewoc
      ;; Set default values
      (unless header (setq header ""))
      (unless footer (setq footer ""))
      (setf (ewoc--node-start-marker dll) (copy-marker pos)
            foot (ewoc--insert-new-node  dll footer hf-pp dll)
            head (ewoc--insert-new-node foot header hf-pp dll)
            (ewoc--hf-pp new-ewoc) hf-pp
            (ewoc--footer new-ewoc) foot
            (ewoc--header new-ewoc) head))
    ;; Return the ewoc
    new-ewoc))