Function: cl-symbol-macrolet

cl-symbol-macrolet is an autoloaded macro defined in cl-macs.el.gz.

Signature

(cl-symbol-macrolet ((NAME EXPANSION) ...) FORM...)

Documentation

Make symbol macro definitions.

Within the body FORMs, references to the variable NAME will be replaced by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...).

Aliases

symbol-macrolet (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-macs.el.gz
;;;###autoload
(defmacro cl-symbol-macrolet (bindings &rest body)
  "Make symbol macro definitions.
Within the body FORMs, references to the variable NAME will be replaced
by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...).

\(fn ((NAME EXPANSION) ...) FORM...)"
  (declare (indent 1) (debug ((&rest (symbolp sexp)) cl-declarations body)))
  (let ((malformed-bindings nil)
        (advised (advice-member-p #'cl--sm-macroexpand 'macroexpand)))
    (dolist (binding bindings)
      (unless (and (consp binding) (symbolp (car binding))
                   (consp (cdr binding)) (null (cddr binding)))
        (push binding malformed-bindings)))
    (unwind-protect
        (progn
          (unless advised
            (advice-add 'macroexpand :around #'cl--sm-macroexpand))
          (let* ((venv (cdr (assq :cl-symbol-macros
                                  macroexpand-all-environment)))
                 (expansion
                  (macroexpand-all (macroexp-progn body)
                                   (cons (cons :cl-symbol-macros
                                               (append bindings venv))
                                         macroexpand-all-environment))))
            (if malformed-bindings
                (macroexp-warn-and-return
                 (format-message "Malformed `cl-symbol-macrolet' binding(s): %S"
                                 (nreverse malformed-bindings))
                 expansion)
              expansion)))
      (unless advised
        (advice-remove 'macroexpand #'cl--sm-macroexpand)))))