Function: icalendar-with-node-value

icalendar-with-node-value is a macro defined in icalendar-macs.el.gz.

Signature

(icalendar-with-node-value NODE &optional BINDINGS &rest BODY)

Documentation

Execute BODY with bindings in BINDINGS taken from NODE and its children.

NODE should be an iCalendar syntax node representing a property or parameter. If NODE is not a syntax node, this form evaluates to nil without binding the variables in BINDINGS and without executing BODY.

Within BODY, if NODE's value is itself a syntax node, the symbol value-node will be bound to the syntax node for NODE's value, value-type will be bound to value-nodes type, and value will be bound to value-nodes value.

If NODE's value is a list of syntax nodes, then within BODY, value-nodes will be bound to those value nodes, value-types will be bound to a list of their types, and values(var)/values(fun) will be bound to their values.

If NODE's value is not a syntax node, then value is instead bound directly to NODE's value, and value-type and value-node are bound to nil.

If BODY is nil, it is assumed to be the symbol value; thus
  (icalendar-with-node-value some-node)
is equivalent to
  (icalendar-with-node-value some-node nil value)

BINDINGS are passed on to icalendar-with-node-children and will be available in BODY; see its docstring for their form.

Aliases

icalendar-with-property

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-macs.el.gz
(defmacro ical:with-node-value (node &optional bindings &rest body)
  "Execute BODY with bindings in BINDINGS taken from NODE and its children.

NODE should be an iCalendar syntax node representing a property or
parameter.  If NODE is not a syntax node, this form evaluates to nil
without binding the variables in BINDINGS and without executing BODY.

Within BODY, if NODE's value is itself a syntax node, the symbol
`value-node' will be bound to the syntax node for NODE's value,
`value-type' will be bound to `value-node's type, and `value' will be
bound to `value-node's value.

If NODE's value is a list of syntax nodes, then within BODY,
`value-nodes' will be bound to those value nodes, `value-types' will be
bound to a list of their types, and `values' will be bound to their
values.

If NODE's value is not a syntax node, then `value' is instead bound
directly to NODE's value, and `value-type' and `value-node' are bound to
nil.

If BODY is nil, it is assumed to be the symbol `value'; thus
  (icalendar-with-node-value some-node)
is equivalent to
  (icalendar-with-node-value some-node nil value)

BINDINGS are passed on to `icalendar-with-node-children' and will be
available in BODY; see its docstring for their form."
  (declare (debug (form &optional form &rest form))
           (indent 2))
  (let ((vn (gensym "icalendar-node"))
        (val (gensym "icalendar-value"))
        (is-list (gensym "is-list")))
    `(let ((,vn ,node))
       (when (ical:ast-node-p ,vn)
         (let* ((,val (ical:ast-node-value ,vn))
                (value-node (when (ical:ast-node-p ,val) ,val))
                (value-type (when (ical:ast-node-p value-node)
                              (ical:ast-node-type value-node)))
                (value (if (ical:ast-node-p value-node)
                           (ical:ast-node-value value-node)
                         ,val))
                (,is-list (ical:expects-list-of-values-p (ical:ast-node-type ,vn)))
                (value-nodes (when ,is-list
                               (seq-filter #'ical:ast-node-p ,val)))
                (value-types (when ,is-list
                               (mapcar #'ical:ast-node-type value-nodes)))
                (values (when ,is-list
                          (mapcar #'ical:ast-node-value value-nodes))))
           (ignore value-type ; Silence the byte compiler when
                   value      ; one of these goes unused
                   value-types
                   values)
           (ical:with-node-children ,vn ,bindings ,@(or body (list 'value))))))))