Function: defmethod

defmethod is an autoloaded macro defined in eieio-compat.el.gz.

This macro is obsolete since 25.1; use cl-defmethod instead.

Signature

(defmethod METHOD &rest ARGS)

Documentation

Create a new METHOD through defgeneric with ARGS.

The optional second argument KEY is a specifier that modifies how the method is called, including:
   :before - Method will be called before the :primary
   :primary - The default if not specified
   :after - Method will be called after the :primary
   :static - First arg could be an object or class
The next argument is the ARGLIST. The ARGLIST specifies the arguments to the method as with defun. The first argument can have a type specifier, such as:
  ((VARNAME CLASS) ARG2 ...)
where VARNAME is the name of the local variable for the method being created. The CLASS is a class symbol for a class made with defclass. A DOCSTRING comes after the ARGLIST, and is optional. All the rest of the args are the BODY of the method. A method will return the value of the last form in the BODY.

Summary:

 (defmethod mymethod [:before | :primary | :after | :static]
                     ((typearg class-name) arg2 &optional opt &rest rest)
    "doc-string"
     body)

Probably introduced at or before Emacs version 25.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/eieio-compat.el.gz
;;;###autoload
(defmacro defmethod (method &rest args)
  "Create a new METHOD through `defgeneric' with ARGS.

The optional second argument KEY is a specifier that
modifies how the method is called, including:
   :before  - Method will be called before the :primary
   :primary - The default if not specified
   :after   - Method will be called after the :primary
   :static  - First arg could be an object or class
The next argument is the ARGLIST.  The ARGLIST specifies the arguments
to the method as with `defun'.  The first argument can have a type
specifier, such as:
  ((VARNAME CLASS) ARG2 ...)
where VARNAME is the name of the local variable for the method being
created.  The CLASS is a class symbol for a class made with `defclass'.
A DOCSTRING comes after the ARGLIST, and is optional.
All the rest of the args are the BODY of the method.  A method will
return the value of the last form in the BODY.

Summary:

 (defmethod mymethod [:before | :primary | :after | :static]
                     ((typearg class-name) arg2 &optional opt &rest rest)
    \"doc-string\"
     body)"
  (declare (doc-string 3) (obsolete cl-defmethod "25.1")
           (debug
            (&define                    ; this means we are defining something
             [&name sexp]   ;Allow (setf ...) additionally to symbols.
             ;; ^^ This is the methods symbol
             [ &optional symbolp ]                ; this is key :before etc
             cl-generic-method-args               ; arguments
             [ &optional stringp ]                ; documentation string
             def-body                             ; part to be debugged
             )))
  (let* ((key (if (keywordp (car args)) (pop args)))
	 (params (car args))
	 (arg1 (car params))
         (fargs (if (consp arg1)
                   (cons (car arg1) (cdr params))
                 params))
	 (class (if (consp arg1) (nth 1 arg1)))
         (code `(lambda ,fargs ,@(cdr args))))
    `(progn
       ;; Make sure there is a generic and the byte-compiler sees it.
       (defgeneric ,method ,args)
       (eieio--defmethod ',method ',key ',class #',code))))