]> code.delx.au - gnu-emacs-elpa/commitdiff
* cl-generic/cl-generic.el (cl-defmethod): Improve compatibility
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 12 Jul 2016 05:34:18 +0000 (01:34 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 12 Jul 2016 05:34:18 +0000 (01:34 -0400)
More specifically, map cl-no-applicable-method to no-applicable-method.
(cl-generic-apply): New function.

packages/cl-generic/cl-generic.el

index 4b1a377ad27e91e379e299f32264f32c488979a9..a40723ce8ff97b2f076f9921cda8c0690edf89f8 100644 (file)
@@ -1,10 +1,10 @@
 ;;; cl-generic.el --- Forward cl-generic compatibility for Emacs<25
 
-;; Copyright (C) 2015  Free Software Foundation, Inc
+;; Copyright (C) 2015, 2016  Free Software Foundation, Inc
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; vcomment: Emacs-25's version is 1.0 so this has to stay below.
-;; Version: 0.2
+;; Version: 0.3
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
   ;; `cl-no-applicable-method' errors.
   (push 'cl-no-applicable-method (get 'no-method-definition 'error-conditions))
 
+  (defalias 'cl-generic-apply #'apply)
+
   (defmacro cl-defmethod (name args &rest body)
     (let ((qualifiers nil))
       (while (not (listp args))
         (push args qualifiers)
         (setq args (pop body)))
-      (let ((arg1 (car args)))
-        (when (eq (car-safe (car (cdr-safe arg1))) 'subclass)
-          ;; There's no exact equivalent to `subclass', but :static
-          ;; provides a superset which should work just as well in practice.
-          (push :static qualifiers)
-          (setf (cadr arg1) (cadr (cadr arg1)))))
       (let ((docstring (if (and (stringp (car body)) (cdr body)) (pop body))))
+        ;; Backward compatibility for `no-next-method' and
+        ;; `no-applicable-method', which have slightly different calling
+        ;; convention than their cl-generic counterpart.
+        (pcase name
+          (`cl-no-next-method
+           (setq name 'no-next-method)
+           (setq args (cddr args)))
+          (`cl-no-applicable-method
+           (setq name 'no-applicable-method)
+           (setq args `(,(nth 1 args) ,(nth 0 args)
+                        ,(make-symbol "_ignore") . ,(nthcdr 2 args)))))
+        (let ((arg1 (car args)))
+          (when (eq (car-safe (car (cdr-safe arg1))) 'subclass)
+            ;; There's no exact equivalent to `subclass', but :static
+            ;; provides a superset which should work just as well in practice.
+            (push :static qualifiers)
+            (setf (cadr arg1) (cadr (cadr arg1)))))
+
         `(defmethod ,name ,@qualifiers ,args
            ,@(if docstring (list docstring))
            ;; We could just alias `cl-call-next-method' to `call-next-method',
                       ((cl-call-next-method (&rest args)
                                             (apply #'call-next-method args))
                        (cl-next-method-p () (next-method-p)))
-                   ,@body))))))))
+                  ,@body))))))))
 
 (provide 'cl-generic)
 ;;; cl-generic.el ends here