diff options
| author | Stefan Monnier | 2015-02-16 02:22:46 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2015-02-16 02:22:46 -0500 |
| commit | c4e2be4587ec6d0f1367b1bfe220a71360e25bea (patch) | |
| tree | eb33c5650fe7ad152462f577523f115bb94e061c /lisp | |
| parent | 6bf61df8ab359f1371ab2e3e278bc8642d65a985 (diff) | |
| download | emacs-c4e2be4587ec6d0f1367b1bfe220a71360e25bea.tar.gz emacs-c4e2be4587ec6d0f1367b1bfe220a71360e25bea.zip | |
* lisp/emacs-lisp/eieio*.el: Align a bit better with CLOS
* lisp/cedet/semantic/db-el.el (semanticdb-elisp-sym->tag): Fix copy&paste
error (semanticdb-project-database => sym). Avoid eieio--class-public-a
when possible.
* lisp/emacs-lisp/eieio-base.el (make-instance): Add a method here rather
than on eieio-constructor.
* lisp/emacs-lisp/eieio-core.el (eieio--class-print-name): New function.
(eieio-class-name): Make it do what the docstring claims.
(eieio-defclass-internal): Simplify since `prots' isn't used any more.
(eieio--slot-name-index): Simplify accordingly.
(eieio-barf-if-slot-unbound): Pass the class object rather than its
name to `slot-unbound'.
* lisp/emacs-lisp/eieio.el (defclass): Use make-instance rather than
eieio-constructor.
(set-slot-value): Mark as obsolete.
(eieio-object-class-name): Improve call to eieio-class-name.
(eieio-slot-descriptor-name, eieio-class-slots): New functions.
(object-slots): Use it. Declare obsolete.
(eieio-constructor): Merge it with `make-instance'.
(initialize-instance): Use `dolist'.
(eieio-override-prin1, eieio-edebug-prin1-to-string):
Use eieio--class-print-name.
* test/automated/eieio-test-methodinvoke.el (make-instance): Add methods
here rather than on eieio-constructor.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/cedet/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/cedet/semantic/db-el.el | 8 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-base.el | 2 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-core.el | 33 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 91 |
6 files changed, 94 insertions, 69 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bb8c97badf7..e4383437c6d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,28 @@ | |||
| 1 | 2015-02-16 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2015-02-16 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * emacs-lisp/eieio.el (defclass): Use make-instance rather than | ||
| 4 | eieio-constructor. | ||
| 5 | (set-slot-value): Mark as obsolete. | ||
| 6 | (eieio-object-class-name): Improve call to eieio-class-name. | ||
| 7 | (eieio-slot-descriptor-name, eieio-class-slots): New functions. | ||
| 8 | (object-slots): Use it. Declare obsolete. | ||
| 9 | (eieio-constructor): Merge it with `make-instance'. | ||
| 10 | (initialize-instance): Use `dolist'. | ||
| 11 | (eieio-override-prin1, eieio-edebug-prin1-to-string): | ||
| 12 | Use eieio--class-print-name. | ||
| 13 | |||
| 14 | * emacs-lisp/eieio-core.el (eieio--class-print-name): New function. | ||
| 15 | (eieio-class-name): Make it do what the docstring claims. | ||
| 16 | (eieio-defclass-internal): Simplify since `prots' isn't used any more. | ||
| 17 | (eieio--slot-name-index): Simplify accordingly. | ||
| 18 | (eieio-barf-if-slot-unbound): Pass the class object rather than its | ||
| 19 | name to `slot-unbound'. | ||
| 20 | |||
| 21 | * emacs-lisp/eieio-base.el (make-instance): Add a method here rather | ||
| 22 | than on eieio-constructor. | ||
| 23 | |||
| 24 | 2015-02-16 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 25 | |||
| 3 | * emacs-lisp/cl-macs.el (cl-defstruct): Keep type=nil by default. | 26 | * emacs-lisp/cl-macs.el (cl-defstruct): Keep type=nil by default. |
| 4 | * emacs-lisp/cl-preloaded.el (cl-struct-define): Add sanity checks | 27 | * emacs-lisp/cl-preloaded.el (cl-struct-define): Add sanity checks |
| 5 | about relationship between `type', `named', and `slots'. | 28 | about relationship between `type', `named', and `slots'. |
diff --git a/lisp/cedet/ChangeLog b/lisp/cedet/ChangeLog index 6bbae7e08a8..838a2693491 100644 --- a/lisp/cedet/ChangeLog +++ b/lisp/cedet/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2015-02-16 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * semantic/db-el.el (semanticdb-elisp-sym->tag): Fix copy&paste error | ||
| 4 | (semanticdb-project-database => sym). Avoid eieio--class-public-a | ||
| 5 | when possible. | ||
| 6 | |||
| 1 | 2015-02-04 Stefan Monnier <monnier@iro.umontreal.ca> | 7 | 2015-02-04 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 8 | ||
| 3 | Use cl-generic instead of EIEIO's defgeneric/defmethod. | 9 | Use cl-generic instead of EIEIO's defgeneric/defmethod. |
diff --git a/lisp/cedet/semantic/db-el.el b/lisp/cedet/semantic/db-el.el index e37b65a461e..b20a756f6b7 100644 --- a/lisp/cedet/semantic/db-el.el +++ b/lisp/cedet/semantic/db-el.el | |||
| @@ -223,9 +223,11 @@ TOKTYPE is a hint to the type of tag desired." | |||
| 223 | (symbol-name sym) | 223 | (symbol-name sym) |
| 224 | "class" | 224 | "class" |
| 225 | (semantic-elisp-desymbolify | 225 | (semantic-elisp-desymbolify |
| 226 | ;; FIXME: This only gives the instance slots and ignores the | 226 | (let ((class (find-class sym))) |
| 227 | ;; class-allocated slots. | 227 | (if (fboundp 'eieio-slot-descriptor-name) |
| 228 | (eieio--class-public-a (find-class 'semanticdb-project-database))) ;; slots ;FIXME: eieio-- | 228 | (mapcar #'eieio-slot-descriptor-name |
| 229 | (eieio-class-slots class)) | ||
| 230 | (eieio--class-public-a class)))) | ||
| 229 | (semantic-elisp-desymbolify (eieio-class-parents sym)) ;; parents | 231 | (semantic-elisp-desymbolify (eieio-class-parents sym)) ;; parents |
| 230 | )) | 232 | )) |
| 231 | ((not toktype) | 233 | ((not toktype) |
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index fcf02b92736..1cc9f895f8a 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el | |||
| @@ -140,7 +140,7 @@ Multiple calls to `make-instance' will return this object.")) | |||
| 140 | A singleton is a class which will only ever have one instance." | 140 | A singleton is a class which will only ever have one instance." |
| 141 | :abstract t) | 141 | :abstract t) |
| 142 | 142 | ||
| 143 | (cl-defmethod eieio-constructor ((class (subclass eieio-singleton)) &rest _slots) | 143 | (cl-defmethod make-instance ((class (subclass eieio-singleton)) &rest _slots) |
| 144 | "Constructor for singleton CLASS. | 144 | "Constructor for singleton CLASS. |
| 145 | NAME and SLOTS initialize the new object. | 145 | NAME and SLOTS initialize the new object. |
| 146 | This constructor guarantees that no matter how many you request, | 146 | This constructor guarantees that no matter how many you request, |
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index e71c54d4123..408922a2daa 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el | |||
| @@ -181,15 +181,15 @@ Currently under control of this var: | |||
| 181 | CLASS is a symbol." ;FIXME: Is it a vector or a symbol? | 181 | CLASS is a symbol." ;FIXME: Is it a vector or a symbol? |
| 182 | (and (symbolp class) (eieio--class-p (eieio--class-v class)))) | 182 | (and (symbolp class) (eieio--class-p (eieio--class-v class)))) |
| 183 | 183 | ||
| 184 | (defun eieio--class-print-name (class) | ||
| 185 | "Return a printed representation of CLASS." | ||
| 186 | (format "#<class %s>" (eieio-class-name class))) | ||
| 187 | |||
| 184 | (defun eieio-class-name (class) | 188 | (defun eieio-class-name (class) |
| 185 | "Return a Lisp like symbol name for CLASS." | 189 | "Return a Lisp like symbol name for CLASS." |
| 186 | ;; FIXME: What's a "Lisp like symbol name"? | 190 | (setq class (eieio--class-object class)) |
| 187 | ;; FIXME: CLOS returns a symbol, but the code returns a string. | 191 | (cl-check-type class eieio--class) |
| 188 | (if (eieio--class-p class) (setq class (eieio--class-symbol class))) | 192 | (eieio--class-symbol class)) |
| 189 | (cl-check-type class class) | ||
| 190 | ;; I think this is supposed to return a symbol, but to me CLASS is a symbol, | ||
| 191 | ;; and I wanted a string. Arg! | ||
| 192 | (format "#<class %s>" (symbol-name class))) | ||
| 193 | (define-obsolete-function-alias 'class-name #'eieio-class-name "24.4") | 193 | (define-obsolete-function-alias 'class-name #'eieio-class-name "24.4") |
| 194 | 194 | ||
| 195 | (defalias 'eieio--class-constructor #'identity | 195 | (defalias 'eieio--class-constructor #'identity |
| @@ -317,7 +317,7 @@ See `defclass' for more information." | |||
| 317 | (newc (if (and oldc (not (eieio--class-default-object-cache oldc))) | 317 | (newc (if (and oldc (not (eieio--class-default-object-cache oldc))) |
| 318 | ;; The oldc class is a stub setup by eieio-defclass-autoload. | 318 | ;; The oldc class is a stub setup by eieio-defclass-autoload. |
| 319 | ;; Reuse it instead of creating a new one, so that existing | 319 | ;; Reuse it instead of creating a new one, so that existing |
| 320 | ;; references are still valid. | 320 | ;; references stay valid. |
| 321 | oldc | 321 | oldc |
| 322 | (eieio--class-make cname))) | 322 | (eieio--class-make cname))) |
| 323 | (groups nil) ;; list of groups id'd from slots | 323 | (groups nil) ;; list of groups id'd from slots |
| @@ -488,16 +488,10 @@ See `defclass' for more information." | |||
| 488 | ;; Attach slot symbols into a hashtable, and store the index of | 488 | ;; Attach slot symbols into a hashtable, and store the index of |
| 489 | ;; this slot as the value this table. | 489 | ;; this slot as the value this table. |
| 490 | (let* ((cnt 0) | 490 | (let* ((cnt 0) |
| 491 | (pubsyms (eieio--class-public-a newc)) | ||
| 492 | (prots (eieio--class-protection newc)) | ||
| 493 | (oa (make-hash-table :test #'eq))) | 491 | (oa (make-hash-table :test #'eq))) |
| 494 | (while pubsyms | 492 | (dolist (pubsym (eieio--class-public-a newc)) |
| 495 | (let ((newsym (list cnt))) | 493 | (setf (gethash pubsym oa) cnt) |
| 496 | (setf (gethash (car pubsyms) oa) newsym) | 494 | (setq cnt (1+ cnt))) |
| 497 | (setq cnt (1+ cnt)) | ||
| 498 | (if (car prots) (setcdr newsym (car prots)))) | ||
| 499 | (setq pubsyms (cdr pubsyms) | ||
| 500 | prots (cdr prots))) | ||
| 501 | (setf (eieio--class-symbol-hashtable newc) oa)) | 495 | (setf (eieio--class-symbol-hashtable newc) oa)) |
| 502 | 496 | ||
| 503 | ;; Set up a specialized doc string. | 497 | ;; Set up a specialized doc string. |
| @@ -895,7 +889,7 @@ INSTANCE is the object being referenced. SLOTNAME is the offending | |||
| 895 | slot. If the slot is ok, return VALUE. | 889 | slot. If the slot is ok, return VALUE. |
| 896 | Argument FN is the function calling this verifier." | 890 | Argument FN is the function calling this verifier." |
| 897 | (if (and (eq value eieio-unbound) (not eieio-skip-typecheck)) | 891 | (if (and (eq value eieio-unbound) (not eieio-skip-typecheck)) |
| 898 | (slot-unbound instance (eieio--object-class-name instance) slotname fn) | 892 | (slot-unbound instance (eieio--object-class-object instance) slotname fn) |
| 899 | value)) | 893 | value)) |
| 900 | 894 | ||
| 901 | 895 | ||
| @@ -1029,8 +1023,7 @@ The slot is a symbol which is installed in CLASS by the `defclass' call. | |||
| 1029 | If SLOT is the value created with :initarg instead, | 1023 | If SLOT is the value created with :initarg instead, |
| 1030 | reverse-lookup that name, and recurse with the associated slot value." | 1024 | reverse-lookup that name, and recurse with the associated slot value." |
| 1031 | ;; Removed checks to outside this call | 1025 | ;; Removed checks to outside this call |
| 1032 | (let* ((fsym (gethash slot (eieio--class-symbol-hashtable class))) | 1026 | (let* ((fsi (gethash slot (eieio--class-symbol-hashtable class)))) |
| 1033 | (fsi (car fsym))) | ||
| 1034 | (if (integerp fsi) | 1027 | (if (integerp fsi) |
| 1035 | (+ (eval-when-compile eieio--object-num-slots) fsi) | 1028 | (+ (eval-when-compile eieio--object-num-slots) fsi) |
| 1036 | (let ((fn (eieio--initarg-to-attribute class slot))) | 1029 | (let ((fn (eieio--initarg-to-attribute class slot))) |
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 526090954a9..4f6b6d73183 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -272,34 +272,9 @@ This method is obsolete." | |||
| 272 | ;; but hide it so we don't trigger indefinitely. | 272 | ;; but hide it so we don't trigger indefinitely. |
| 273 | `(,(car whole) (identity ,(car slots)) | 273 | `(,(car whole) (identity ,(car slots)) |
| 274 | ,@(cdr slots))))))) | 274 | ,@(cdr slots))))))) |
| 275 | (apply #'eieio-constructor ',name slots)))))) | 275 | (apply #'make-instance ',name slots)))))) |
| 276 | 276 | ||
| 277 | 277 | ||
| 278 | ;;; CLOS style implementation of object creators. | ||
| 279 | ;; | ||
| 280 | (defun make-instance (class &rest initargs) | ||
| 281 | "Make a new instance of CLASS based on INITARGS. | ||
| 282 | CLASS is a class symbol. For example: | ||
| 283 | |||
| 284 | (make-instance 'foo) | ||
| 285 | |||
| 286 | INITARGS is a property list with keywords based on the :initarg | ||
| 287 | for each slot. For example: | ||
| 288 | |||
| 289 | (make-instance 'foo :slot1 value1 :slotN valueN) | ||
| 290 | |||
| 291 | Compatibility note: | ||
| 292 | |||
| 293 | If the first element of INITARGS is a string, it is used as the | ||
| 294 | name of the class. | ||
| 295 | |||
| 296 | In EIEIO, the class' constructor requires a name for use when printing. | ||
| 297 | `make-instance' in CLOS doesn't use names the way Emacs does, so the | ||
| 298 | class is used as the name slot instead when INITARGS doesn't start with | ||
| 299 | a string." | ||
| 300 | (apply (eieio--class-constructor class) initargs)) | ||
| 301 | |||
| 302 | |||
| 303 | ;;; Get/Set slots in an object. | 278 | ;;; Get/Set slots in an object. |
| 304 | ;; | 279 | ;; |
| 305 | (defmacro oref (obj slot) | 280 | (defmacro oref (obj slot) |
| @@ -311,6 +286,7 @@ created by the :initarg tag." | |||
| 311 | 286 | ||
| 312 | (defalias 'slot-value 'eieio-oref) | 287 | (defalias 'slot-value 'eieio-oref) |
| 313 | (defalias 'set-slot-value 'eieio-oset) | 288 | (defalias 'set-slot-value 'eieio-oset) |
| 289 | (make-obsolete 'set-slot-value "use (setf (slot-value ..) ..) instead" "25.1") | ||
| 314 | 290 | ||
| 315 | (defmacro oref-default (obj slot) | 291 | (defmacro oref-default (obj slot) |
| 316 | "Get the default value of OBJ (maybe a class) for SLOT. | 292 | "Get the default value of OBJ (maybe a class) for SLOT. |
| @@ -363,7 +339,7 @@ variable name of the same name as the slot." | |||
| 363 | (declare (obsolete eieio-named "25.1"))) | 339 | (declare (obsolete eieio-named "25.1"))) |
| 364 | 340 | ||
| 365 | (defun eieio-object-name (obj &optional extra) | 341 | (defun eieio-object-name (obj &optional extra) |
| 366 | "Return a Lisp like symbol string for object OBJ. | 342 | "Return a printed representation for object OBJ. |
| 367 | If EXTRA, include that in the string returned to represent the symbol." | 343 | If EXTRA, include that in the string returned to represent the symbol." |
| 368 | (cl-check-type obj eieio-object) | 344 | (cl-check-type obj eieio-object) |
| 369 | (format "#<%s %s%s>" (eieio--object-class-name obj) | 345 | (format "#<%s %s%s>" (eieio--object-class-name obj) |
| @@ -402,7 +378,7 @@ If EXTRA, include that in the string returned to represent the symbol." | |||
| 402 | (defun eieio-object-class-name (obj) | 378 | (defun eieio-object-class-name (obj) |
| 403 | "Return a Lisp like symbol name for OBJ's class." | 379 | "Return a Lisp like symbol name for OBJ's class." |
| 404 | (cl-check-type obj eieio-object) | 380 | (cl-check-type obj eieio-object) |
| 405 | (eieio-class-name (eieio--object-class-name obj))) | 381 | (eieio-class-name (eieio--object-class-object obj))) |
| 406 | (define-obsolete-function-alias | 382 | (define-obsolete-function-alias |
| 407 | 'object-class-name 'eieio-object-class-name "24.4") | 383 | 'object-class-name 'eieio-object-class-name "24.4") |
| 408 | 384 | ||
| @@ -463,10 +439,23 @@ The CLOS function `class-direct-subclasses' is aliased to this function." | |||
| 463 | child (pop p))) | 439 | child (pop p))) |
| 464 | (if child t)))) | 440 | (if child t)))) |
| 465 | 441 | ||
| 442 | (defun eieio-slot-descriptor-name (slot) slot) | ||
| 443 | |||
| 444 | (defun eieio-class-slots (class) | ||
| 445 | "Return list of slots available in instances of CLASS." | ||
| 446 | ;; FIXME: This only gives the instance slots and ignores the | ||
| 447 | ;; class-allocated slots. | ||
| 448 | ;; FIXME: It only gives the slot's *names* rather than actual | ||
| 449 | ;; slot descriptors. | ||
| 450 | (setq class (eieio--class-object class)) | ||
| 451 | (cl-check-type class eieio--class) | ||
| 452 | (eieio--class-public-a class)) | ||
| 453 | |||
| 466 | (defun object-slots (obj) | 454 | (defun object-slots (obj) |
| 467 | "Return list of slots available in OBJ." | 455 | "Return list of slots available in OBJ." |
| 456 | (declare (obsolete eieio-class-slots "25.1")) | ||
| 468 | (cl-check-type obj eieio-object) | 457 | (cl-check-type obj eieio-object) |
| 469 | (eieio--class-public-a (eieio--object-class-object obj))) | 458 | (eieio-class-slots (eieio--object-class-object obj))) |
| 470 | 459 | ||
| 471 | (defun eieio--class-slot-initarg (class slot) "Fetch from CLASS, SLOT's :initarg." | 460 | (defun eieio--class-slot-initarg (class slot) "Fetch from CLASS, SLOT's :initarg." |
| 472 | (cl-check-type class eieio--class) | 461 | (cl-check-type class eieio--class) |
| @@ -613,6 +602,9 @@ If SLOT is unbound, do nothing." | |||
| 613 | ;;; Here are some CLOS items that need the CL package | 602 | ;;; Here are some CLOS items that need the CL package |
| 614 | ;; | 603 | ;; |
| 615 | 604 | ||
| 605 | ;; FIXME: Shouldn't this be a more complex gv-expander which extracts the | ||
| 606 | ;; common code between oref and oset, so as to reduce the redundant work done | ||
| 607 | ;; in (push foo (oref bar baz)), like we do for the `nth' expander? | ||
| 616 | (gv-define-simple-setter eieio-oref eieio-oset) | 608 | (gv-define-simple-setter eieio-oref eieio-oset) |
| 617 | 609 | ||
| 618 | 610 | ||
| @@ -636,20 +628,28 @@ This class is not stored in the `parent' slot of a class vector." | |||
| 636 | 628 | ||
| 637 | (defalias 'standard-class 'eieio-default-superclass) | 629 | (defalias 'standard-class 'eieio-default-superclass) |
| 638 | 630 | ||
| 639 | (cl-defgeneric eieio-constructor (class &rest slots) | 631 | (cl-defgeneric make-instance (class &rest initargs) |
| 640 | "Default constructor for CLASS `eieio-default-superclass'.") | 632 | "Make a new instance of CLASS based on INITARGS. |
| 633 | For example: | ||
| 634 | |||
| 635 | (make-instance 'foo) | ||
| 636 | |||
| 637 | INITARGS is a property list with keywords based on the `:initarg' | ||
| 638 | for each slot. For example: | ||
| 639 | |||
| 640 | (make-instance 'foo :slot1 value1 :slotN valueN)") | ||
| 641 | 641 | ||
| 642 | (define-obsolete-function-alias 'constructor #'eieio-constructor "25.1") | 642 | (define-obsolete-function-alias 'constructor #'make-instance "25.1") |
| 643 | 643 | ||
| 644 | (cl-defmethod eieio-constructor | 644 | (cl-defmethod make-instance |
| 645 | ((class (subclass eieio-default-superclass)) &rest slots) | 645 | ((class (subclass eieio-default-superclass)) &rest slots) |
| 646 | "Default constructor for CLASS `eieio-default-superclass'. | 646 | "Default constructor for CLASS `eieio-default-superclass'. |
| 647 | SLOTS are the initialization slots used by `shared-initialize'. | 647 | SLOTS are the initialization slots used by `initialize-instance'. |
| 648 | This static method is called when an object is constructed. | 648 | This static method is called when an object is constructed. |
| 649 | It allocates the vector used to represent an EIEIO object, and then | 649 | It allocates the vector used to represent an EIEIO object, and then |
| 650 | calls `shared-initialize' on that object." | 650 | calls `initialize-instance' on that object." |
| 651 | (let* ((new-object (copy-sequence (eieio--class-default-object-cache | 651 | (let* ((new-object (copy-sequence (eieio--class-default-object-cache |
| 652 | (eieio--class-v class))))) | 652 | (eieio--class-object class))))) |
| 653 | (if (and slots | 653 | (if (and slots |
| 654 | (let ((x (car slots))) | 654 | (let ((x (car slots))) |
| 655 | (or (stringp x) (null x)))) | 655 | (or (stringp x) (null x)))) |
| @@ -662,6 +662,7 @@ calls `shared-initialize' on that object." | |||
| 662 | ;; Return the created object. | 662 | ;; Return the created object. |
| 663 | new-object)) | 663 | new-object)) |
| 664 | 664 | ||
| 665 | ;; FIXME: CLOS uses "&rest INITARGS" instead. | ||
| 665 | (cl-defgeneric shared-initialize (obj slots) | 666 | (cl-defgeneric shared-initialize (obj slots) |
| 666 | "Set slots of OBJ with SLOTS which is a list of name/value pairs. | 667 | "Set slots of OBJ with SLOTS which is a list of name/value pairs. |
| 667 | Called from the constructor routine.") | 668 | Called from the constructor routine.") |
| @@ -677,6 +678,7 @@ Called from the constructor routine." | |||
| 677 | (eieio-oset obj rn (car (cdr slots))))) | 678 | (eieio-oset obj rn (car (cdr slots))))) |
| 678 | (setq slots (cdr (cdr slots))))) | 679 | (setq slots (cdr (cdr slots))))) |
| 679 | 680 | ||
| 681 | ;; FIXME: CLOS uses "&rest INITARGS" instead. | ||
| 680 | (cl-defgeneric initialize-instance (this &optional slots) | 682 | (cl-defgeneric initialize-instance (this &optional slots) |
| 681 | "Construct the new object THIS based on SLOTS.") | 683 | "Construct the new object THIS based on SLOTS.") |
| 682 | 684 | ||
| @@ -693,9 +695,8 @@ dynamically set from SLOTS." | |||
| 693 | ;; First, see if any of our defaults are `lambda', and | 695 | ;; First, see if any of our defaults are `lambda', and |
| 694 | ;; re-evaluate them and apply the value to our slots. | 696 | ;; re-evaluate them and apply the value to our slots. |
| 695 | (let* ((this-class (eieio--object-class-object this)) | 697 | (let* ((this-class (eieio--object-class-object this)) |
| 696 | (slot (eieio--class-public-a this-class)) | ||
| 697 | (defaults (eieio--class-public-d this-class))) | 698 | (defaults (eieio--class-public-d this-class))) |
| 698 | (while slot | 699 | (dolist (slot (eieio--class-public-a this-class)) |
| 699 | ;; For each slot, see if we need to evaluate it. | 700 | ;; For each slot, see if we need to evaluate it. |
| 700 | ;; | 701 | ;; |
| 701 | ;; Paul Landes said in an email: | 702 | ;; Paul Landes said in an email: |
| @@ -705,10 +706,9 @@ dynamically set from SLOTS." | |||
| 705 | ;; > web. | 706 | ;; > web. |
| 706 | (let ((dflt (eieio-default-eval-maybe (car defaults)))) | 707 | (let ((dflt (eieio-default-eval-maybe (car defaults)))) |
| 707 | (when (not (eq dflt (car defaults))) | 708 | (when (not (eq dflt (car defaults))) |
| 708 | (eieio-oset this (car slot) dflt) )) | 709 | (eieio-oset this slot dflt) )) |
| 709 | ;; Next. | 710 | ;; Next. |
| 710 | (setq slot (cdr slot) | 711 | (setq defaults (cdr defaults)))) |
| 711 | defaults (cdr defaults)))) | ||
| 712 | ;; Shared initialize will parse our slots for us. | 712 | ;; Shared initialize will parse our slots for us. |
| 713 | (shared-initialize this slots)) | 713 | (shared-initialize this slots)) |
| 714 | 714 | ||
| @@ -742,7 +742,8 @@ Use `slot-boundp' to determine if a slot is bound or not. | |||
| 742 | 742 | ||
| 743 | In CLOS, the argument list is (CLASS OBJECT SLOT-NAME), but | 743 | In CLOS, the argument list is (CLASS OBJECT SLOT-NAME), but |
| 744 | EIEIO can only dispatch on the first argument, so the first two are swapped." | 744 | EIEIO can only dispatch on the first argument, so the first two are swapped." |
| 745 | (signal 'unbound-slot (list (eieio-class-name class) (eieio-object-name object) | 745 | (signal 'unbound-slot (list (eieio-class-name class) |
| 746 | (eieio-object-name object) | ||
| 746 | slot-name fn))) | 747 | slot-name fn))) |
| 747 | 748 | ||
| 748 | (cl-defgeneric clone (obj &rest params) | 749 | (cl-defgeneric clone (obj &rest params) |
| @@ -861,7 +862,7 @@ this object." | |||
| 861 | ((consp thing) | 862 | ((consp thing) |
| 862 | (eieio-list-prin1 thing)) | 863 | (eieio-list-prin1 thing)) |
| 863 | ((eieio--class-p thing) | 864 | ((eieio--class-p thing) |
| 864 | (princ (eieio-class-name thing))) | 865 | (princ (eieio--class-print-name thing))) |
| 865 | (t (prin1 thing)))) | 866 | (t (prin1 thing)))) |
| 866 | 867 | ||
| 867 | (defun eieio-list-prin1 (list) | 868 | (defun eieio-list-prin1 (list) |
| @@ -902,7 +903,7 @@ of `eq'." | |||
| 902 | Used as advice around `edebug-prin1-to-string', held in the | 903 | Used as advice around `edebug-prin1-to-string', held in the |
| 903 | variable PRINT-FUNCTION. Optional argument NOESCAPE is passed to | 904 | variable PRINT-FUNCTION. Optional argument NOESCAPE is passed to |
| 904 | `prin1-to-string' when appropriate." | 905 | `prin1-to-string' when appropriate." |
| 905 | (cond ((eieio--class-p object) (eieio-class-name object)) | 906 | (cond ((eieio--class-p object) (eieio--class-print-name object)) |
| 906 | ((eieio-object-p object) (object-print object)) | 907 | ((eieio-object-p object) (object-print object)) |
| 907 | ((and (listp object) (or (eieio--class-p (car object)) | 908 | ((and (listp object) (or (eieio--class-p (car object)) |
| 908 | (eieio-object-p (car object)))) | 909 | (eieio-object-p (car object)))) |