Function: cl-defsubst

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

Signature

(cl-defsubst NAME ARGLIST [DOCSTRING] BODY...)

Documentation

Define NAME as a function.

Like defun, except the function is automatically declared inline and the arguments are immutable. ARGLIST allows full Common Lisp conventions, and BODY is implicitly surrounded by (cl-block NAME ...). The function's arguments should be treated as immutable.

View in manual

Aliases

defsubst* (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-macs.el.gz
;;;###autoload
(defmacro cl-defsubst (name args &rest body)
  "Define NAME as a function.
Like `defun', except the function is automatically declared `inline' and
the arguments are immutable.
ARGLIST allows full Common Lisp conventions, and BODY is implicitly
surrounded by (cl-block NAME ...).
The function's arguments should be treated as immutable.

\(fn NAME ARGLIST [DOCSTRING] BODY...)"
  (declare (debug cl-defun) (indent 2))
  (let* ((argns (cl--arglist-args args))
	 (real-args (if (eq '&cl-defs (car args)) (cddr args) args))
         (p argns)
         ;; (pbody (cons 'progn body))
         )
    (while (and p (eq (cl--expr-contains real-args (car p)) 1)) (pop p))
    `(progn
       ,(if p nil   ; give up if defaults refer to earlier args
          `(cl-define-compiler-macro ,name
             ,(if (memq '&key args)
                  `(&whole cl-whole &cl-quote ,@args)
                (cons '&cl-quote args))
             ;; NB.  This will produce incorrect results in some
             ;; cases, as our coding conventions says that the first
             ;; line must be a full sentence.  However, if we don't
             ;; word wrap we will have byte-compiler warnings about
             ;; overly long docstrings.  So we can't have a perfect
             ;; result here, and choose to avoid the byte-compiler
             ;; warnings.
             ,(internal--format-docstring-line "compiler-macro for `%s'." name)
             (cl--defsubst-expand
              ',argns '(cl-block ,name ,@(cdr (macroexp-parse-body body)))
              nil
              ,(and (memq '&key args) 'cl-whole) nil ,@argns)))
       (cl-defun ,name ,args ,@body))))