Function: define-overloadable-function

define-overloadable-function is a macro defined in mode-local.el.gz.

Signature

(define-overloadable-function NAME ARGS DOCSTRING &rest BODY)

Documentation

Define a new function, as with defun, which can be overloaded.

NAME is the name of the function to create. ARGS are the arguments to the function. DOCSTRING is a documentation string to describe the function. The docstring will automatically have details about its overload symbol appended to the end. BODY is code that would be run when there is no override defined. The default is to call the function NAME-default with the appropriate arguments.

BODY can also include an override form that specifies which part of BODY is specifically overridden. This permits specifying common code run for both default and overridden implementations. An override form is one of:

  1. (:override [OVERBODY])
  2. (:override-with-args OVERARGS [OVERBODY])

OVERBODY is the code that would be run when there is no override defined. The default is to call the function NAME-default with the appropriate arguments deduced from ARGS. OVERARGS is a list of arguments passed to the override and NAME-default function, in place of those deduced from ARGS.

Probably introduced at or before Emacs version 25.1.

Aliases

define-overload (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/mode-local.el.gz
(defmacro define-overloadable-function (name args docstring &rest body)
  "Define a new function, as with `defun', which can be overloaded.
NAME is the name of the function to create.
ARGS are the arguments to the function.
DOCSTRING is a documentation string to describe the function.  The
docstring will automatically have details about its overload symbol
appended to the end.
BODY is code that would be run when there is no override defined.  The
default is to call the function `NAME-default' with the appropriate
arguments.

BODY can also include an override form that specifies which part of
BODY is specifically overridden.  This permits specifying common code
run for both default and overridden implementations.
An override form is one of:

  1. (:override [OVERBODY])
  2. (:override-with-args OVERARGS [OVERBODY])

OVERBODY is the code that would be run when there is no override
defined.  The default is to call the function `NAME-default' with the
appropriate arguments deduced from ARGS.
OVERARGS is a list of arguments passed to the override and
`NAME-default' function, in place of those deduced from ARGS."
  (declare (doc-string 3)
           (indent defun)
           (debug (&define name lambda-list stringp def-body))
           (autoload-macro expand))
  `(progn
     (defun ,name ,args
       ,docstring
       ,@(mode-local--overload-body name args body))
     :autoload-end
     (eval-and-compile
       (put ',name 'mode-local-overload t))))