aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2015-11-25 17:03:27 -0500
committerStefan Monnier2015-11-25 17:03:27 -0500
commit82a8ad204909ee49cf6a8f2885590f0939d61e8d (patch)
treefdb02c7cf6bb3569c30a27b9a1878d0ef5153061
parentc334674695ab6c2691e29ae0d6a2993eae1414a3 (diff)
downloademacs-82a8ad204909ee49cf6a8f2885590f0939d61e8d.tar.gz
emacs-82a8ad204909ee49cf6a8f2885590f0939d61e8d.zip
* lisp/emacs-lisp/eieio.el: Add some default implementations
(standard-class): Mark it obsolete. (slot-missing): Give it a default implementation. (destructor): Simplify and mark it obsolete. (object-print): Give it a default implementation. (eieio-change-class): Rename from change-class. (change-class): Redefine as obsolete alias.
-rw-r--r--lisp/emacs-lisp/eieio-core.el12
-rw-r--r--lisp/emacs-lisp/eieio.el36
2 files changed, 19 insertions, 29 deletions
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
index dcaaab69cf5..c54cd22115d 100644
--- a/lisp/emacs-lisp/eieio-core.el
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -756,9 +756,7 @@ Argument FN is the function calling this verifier."
756 ;; The slot-missing method is a cool way of allowing an object author 756 ;; The slot-missing method is a cool way of allowing an object author
757 ;; to intercept missing slot definitions. Since it is also the LAST 757 ;; to intercept missing slot definitions. Since it is also the LAST
758 ;; thing called in this fn, its return value would be retrieved. 758 ;; thing called in this fn, its return value would be retrieved.
759 (slot-missing obj slot 'oref) 759 (slot-missing obj slot 'oref))
760 ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot))
761 )
762 (cl-check-type obj eieio-object) 760 (cl-check-type obj eieio-object)
763 (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref)))) 761 (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref))))
764 762
@@ -780,9 +778,7 @@ Fills in OBJ's SLOT with its default value."
780 ;; Oref that slot. 778 ;; Oref that slot.
781 (aref (eieio--class-class-allocation-values cl) 779 (aref (eieio--class-class-allocation-values cl)
782 c) 780 c)
783 (slot-missing obj slot 'oref-default) 781 (slot-missing obj slot 'oref-default))
784 ;;(signal 'invalid-slot-name (list (class-name cl) slot))
785 )
786 (eieio-barf-if-slot-unbound 782 (eieio-barf-if-slot-unbound
787 (let ((val (cl--slot-descriptor-initform 783 (let ((val (cl--slot-descriptor-initform
788 (aref (eieio--class-slots cl) 784 (aref (eieio--class-slots cl)
@@ -822,9 +818,7 @@ Fills in OBJ's SLOT with VALUE."
822 (aset (eieio--class-class-allocation-values class) 818 (aset (eieio--class-class-allocation-values class)
823 c value)) 819 c value))
824 ;; See oref for comment on `slot-missing' 820 ;; See oref for comment on `slot-missing'
825 (slot-missing obj slot 'oset value) 821 (slot-missing obj slot 'oset value))
826 ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot))
827 )
828 (eieio--validate-slot-value class c value slot) 822 (eieio--validate-slot-value class c value slot)
829 (aset obj c value)))) 823 (aset obj c value))))
830 824
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 790e8bc9e0e..0ec07fe7b41 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -678,7 +678,8 @@ This class is not stored in the `parent' slot of a class vector."
678 678
679(setq eieio-default-superclass (cl--find-class 'eieio-default-superclass)) 679(setq eieio-default-superclass (cl--find-class 'eieio-default-superclass))
680 680
681(defalias 'standard-class 'eieio-default-superclass) 681(define-obsolete-function-alias 'standard-class
682 'eieio-default-superclass "25.2")
682 683
683(cl-defgeneric make-instance (class &rest initargs) 684(cl-defgeneric make-instance (class &rest initargs)
684 "Make a new instance of CLASS based on INITARGS. 685 "Make a new instance of CLASS based on INITARGS.
@@ -765,11 +766,7 @@ dynamically set from SLOTS."
765 ;; Shared initialize will parse our slots for us. 766 ;; Shared initialize will parse our slots for us.
766 (shared-initialize this slots)) 767 (shared-initialize this slots))
767 768
768(cl-defgeneric slot-missing (object slot-name operation &optional new-value) 769(cl-defgeneric slot-missing (object slot-name _operation &optional _new-value)
769 "Method invoked when an attempt to access a slot in OBJECT fails.")
770
771(cl-defmethod slot-missing ((object eieio-default-superclass) slot-name
772 _operation &optional _new-value)
773 "Method invoked when an attempt to access a slot in OBJECT fails. 770 "Method invoked when an attempt to access a slot in OBJECT fails.
774SLOT-NAME is the name of the failed slot, OPERATION is the type of access 771SLOT-NAME is the name of the failed slot, OPERATION is the type of access
775that was requested, and optional NEW-VALUE is the value that was desired 772that was requested, and optional NEW-VALUE is the value that was desired
@@ -777,8 +774,9 @@ to be set.
777 774
778This method is called from `oref', `oset', and other functions which 775This method is called from `oref', `oset', and other functions which
779directly reference slots in EIEIO objects." 776directly reference slots in EIEIO objects."
780 (signal 'invalid-slot-name (list (eieio-object-name object) 777 (signal 'invalid-slot-name
781 slot-name))) 778 (list (if (eieio-object-p object) (eieio-object-name object) object)
779 slot-name)))
782 780
783(cl-defgeneric slot-unbound (object class slot-name fn) 781(cl-defgeneric slot-unbound (object class slot-name fn)
784 "Slot unbound is invoked during an attempt to reference an unbound slot.") 782 "Slot unbound is invoked during an attempt to reference an unbound slot.")
@@ -815,22 +813,19 @@ first and modify the returned object.")
815 (if params (shared-initialize nobj params)) 813 (if params (shared-initialize nobj params))
816 nobj)) 814 nobj))
817 815
818(cl-defgeneric destructor (this &rest params) 816(cl-defgeneric destructor (_this &rest _params)
819 "Destructor for cleaning up any dynamic links to our object.") 817 "Destructor for cleaning up any dynamic links to our object."
820 818 (declare (obsolete nil "25.2"))
821(cl-defmethod destructor ((_this eieio-default-superclass) &rest _params)
822 "Destructor for cleaning up any dynamic links to our object.
823Argument THIS is the object being destroyed. PARAMS are additional
824ignored parameters."
825 ;; No cleanup... yet. 819 ;; No cleanup... yet.
826 ) 820 nil)
827 821
828(cl-defgeneric object-print (this &rest strings) 822(cl-defgeneric object-print (this &rest _strings)
829 "Pretty printer for object THIS. Call function `object-name' with STRINGS. 823 "Pretty printer for object THIS.
830 824
831It is sometimes useful to put a summary of the object into the 825It is sometimes useful to put a summary of the object into the
832default #<notation> string when using EIEIO browsing tools. 826default #<notation> string when using EIEIO browsing tools.
833Implement this method to customize the summary.") 827Implement this method to customize the summary."
828 (format "%S" this))
834 829
835(cl-defmethod object-print ((this eieio-default-superclass) &rest strings) 830(cl-defmethod object-print ((this eieio-default-superclass) &rest strings)
836 "Pretty printer for object THIS. Call function `object-name' with STRINGS. 831 "Pretty printer for object THIS. Call function `object-name' with STRINGS.
@@ -938,11 +933,12 @@ this object."
938 933
939;;; Unimplemented functions from CLOS 934;;; Unimplemented functions from CLOS
940;; 935;;
941(defun change-class (_obj _class) 936(defun eieio-change-class (_obj _class)
942 "Change the class of OBJ to type CLASS. 937 "Change the class of OBJ to type CLASS.
943This may create or delete slots, but does not affect the return value 938This may create or delete slots, but does not affect the return value
944of `eq'." 939of `eq'."
945 (error "EIEIO: `change-class' is unimplemented")) 940 (error "EIEIO: `change-class' is unimplemented"))
941(define-obsolete-function-alias 'change-class 'eieio-change-class "25.2")
946 942
947;; Hook ourselves into help system for describing classes and methods. 943;; Hook ourselves into help system for describing classes and methods.
948;; FIXME: This is not actually needed any more since we can click on the 944;; FIXME: This is not actually needed any more since we can click on the