Function: eieio--defmethod
eieio--defmethod is a byte-compiled function defined in
eieio-compat.el.gz.
Signature
(eieio--defmethod METHOD KIND ARGCLASS CODE)
Source Code
;; Defined in /usr/src/emacs/lisp/obsolete/eieio-compat.el.gz
;;;###autoload
(defun eieio--defmethod (method kind argclass code)
(setq kind (intern (downcase (symbol-name kind))))
(let* ((specializer (if (not (eq kind :static))
(or argclass t)
(setq kind nil)
`(eieio--static ,argclass)))
(uses-cnm (not (memq kind '(:before :after))))
(specializers `((arg ,specializer)))
(code
;; Backward compatibility for `no-next-method' and
;; `no-applicable-method', which have slightly different calling
;; convention than their cl-generic counterpart.
(pcase method
('no-next-method
(setq method 'cl-no-next-method)
(setq specializers `(generic method ,@specializers))
(lambda (_generic _method &rest args) (apply code args)))
('no-applicable-method
(setq method 'cl-no-applicable-method)
(setq specializers `(generic ,@specializers))
(lambda (generic arg &rest args)
(apply code arg (cl--generic-name generic) (cons arg args))))
(_ code))))
(cl-generic-define-method
method (unless (memq kind '(nil :primary)) (list kind))
specializers uses-cnm
(if uses-cnm
(let* ((docstring (documentation code 'raw))
(args (help-function-arglist code 'preserve-names))
(doc-only (if docstring
(let ((split (help-split-fundoc docstring nil)))
(if split (cdr split) docstring)))))
(lambda (cnm &rest args)
(:documentation
(help-add-fundoc-usage doc-only (cons 'cl-cnm args)))
(cl-letf (((symbol-function 'call-next-method) cnm)
((symbol-function 'next-method-p)
(lambda () (cl--generic-isnot-nnm-p cnm))))
(apply code args))))
code))
;; The old EIEIO code did not signal an error when there are methods
;; applicable but only of the before/after kind. So if we add a :before
;; or :after, make sure there's a matching dummy primary.
(when (and (memq kind '(:before :after))
;; FIXME: Use `cl-find-method'?
(not (cl-find-method method ()
(mapcar (lambda (arg)
(if (consp arg) (nth 1 arg) t))
specializers))))
(cl-generic-define-method method () specializers t
(lambda (cnm &rest args)
(if (cl--generic-isnot-nnm-p cnm)
(apply cnm args)))))
method))