diff options
| author | Stefan Monnier | 2014-12-22 22:05:46 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2014-12-22 22:05:46 -0500 |
| commit | ee93d7ad4291a0946efe3197481cfbeff92f29b8 (patch) | |
| tree | 4ff0ca7149c5bead965c4e3e49d104af1cf42e1c /lisp | |
| parent | d4a12e7a9a46bbff2f9c4d59ecc284621634a2e8 (diff) | |
| download | emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.tar.gz emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.zip | |
* lisp/emacs-lisp/eieio*.el: Remove "name" field of objects
* lisp/emacs-lisp/eieio-base.el (clone) <eieio-instance-inheritor>:
Use call-next-method.
(eieio-constructor): Rename from `constructor'.
(eieio-persistent-convert-list-to-object): Drop objname.
(eieio-persistent-validate/fix-slot-value): Don't hardcode
eieio--object-num-slots.
(eieio-named): Use a normal slot.
(slot-missing) <eieio-named>: Remove.
(eieio-object-name-string, eieio-object-set-name-string, clone)
<eieio-named>: New methods.
* lisp/emacs-lisp/eieio-core.el (eieio--defalias): Follow aliases.
(eieio--object): Remove `name' field.
(eieio-defclass): Adjust to new convention where constructors don't
take an "object name" any more.
(eieio--defgeneric-init-form, eieio--defmethod): Follow aliases.
(eieio-validate-slot-value, eieio-oset-default)
(eieio-slot-name-index): Don't hardcode eieio--object-num-slots.
(eieio-generic-call-primary-only): Simplify.
* lisp/emacs-lisp/eieio-custom.el (eieio-widget-test): Remove dummy arg.
(eieio-object-value-get): Use eieio-object-set-name-string.
* lisp/emacs-lisp/eieio.el (make-instance): Simplify by not adding an object
name argument.
(eieio-object-name): Use eieio-object-name-string.
(eieio--object-names): New const.
(eieio-object-name-string, eieio-object-set-name-string): Re-implement
using a hashtable rather than a built-in slot.
(eieio-constructor): Rename from `constructor'. Remove `newname' arg.
(clone): Don't mess with the object's "name".
* test/automated/eieio-test-persist.el (persistent-with-objs-slot-subs):
The type FOO-child is the same as FOO.
* test/automated/eieio-tests.el: Remove dummy object names.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 34 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-base.el | 80 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-core.el | 55 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-custom.el | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 60 |
5 files changed, 132 insertions, 101 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 739d442c55b..1a0383814cd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,37 @@ | |||
| 1 | 2014-12-23 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/eieio.el (make-instance): Simplify by not adding an object | ||
| 4 | name argument. | ||
| 5 | (eieio-object-name): Use eieio-object-name-string. | ||
| 6 | (eieio--object-names): New const. | ||
| 7 | (eieio-object-name-string, eieio-object-set-name-string): Re-implement | ||
| 8 | using a hashtable rather than a built-in slot. | ||
| 9 | (eieio-constructor): Rename from `constructor'. Remove `newname' arg. | ||
| 10 | (clone): Don't mess with the object's "name". | ||
| 11 | |||
| 12 | * emacs-lisp/eieio-custom.el (eieio-widget-test): Remove dummy arg. | ||
| 13 | (eieio-object-value-get): Use eieio-object-set-name-string. | ||
| 14 | |||
| 15 | * emacs-lisp/eieio-core.el (eieio--defalias): Follow aliases. | ||
| 16 | (eieio--object): Remove `name' field. | ||
| 17 | (eieio-defclass): Adjust to new convention where constructors don't | ||
| 18 | take an "object name" any more. | ||
| 19 | (eieio--defgeneric-init-form, eieio--defmethod): Follow aliases. | ||
| 20 | (eieio-validate-slot-value, eieio-oset-default) | ||
| 21 | (eieio-slot-name-index): Don't hardcode eieio--object-num-slots. | ||
| 22 | (eieio-generic-call-primary-only): Simplify. | ||
| 23 | |||
| 24 | * emacs-lisp/eieio-base.el (clone) <eieio-instance-inheritor>: | ||
| 25 | Use call-next-method. | ||
| 26 | (eieio-constructor): Rename from `constructor'. | ||
| 27 | (eieio-persistent-convert-list-to-object): Drop objname. | ||
| 28 | (eieio-persistent-validate/fix-slot-value): Don't hardcode | ||
| 29 | eieio--object-num-slots. | ||
| 30 | (eieio-named): Use a normal slot. | ||
| 31 | (slot-missing) <eieio-named>: Remove. | ||
| 32 | (eieio-object-name-string, eieio-object-set-name-string, clone) | ||
| 33 | <eieio-named>: New methods. | ||
| 34 | |||
| 1 | 2014-12-22 Stefan Monnier <monnier@iro.umontreal.ca> | 35 | 2014-12-22 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 36 | ||
| 3 | * emacs-lisp/eieio-core.el (eieio--class-v): Rename from class-v. | 37 | * emacs-lisp/eieio-core.el (eieio--class-v): Rename from class-v. |
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index f2020dfa74d..8a09dac2dff 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el | |||
| @@ -63,25 +63,10 @@ SLOT-NAME is the offending slot. FN is the function signaling the error." | |||
| 63 | ;; Throw the regular signal. | 63 | ;; Throw the regular signal. |
| 64 | (call-next-method))) | 64 | (call-next-method))) |
| 65 | 65 | ||
| 66 | (defmethod clone ((obj eieio-instance-inheritor) &rest params) | 66 | (defmethod clone ((obj eieio-instance-inheritor) &rest _params) |
| 67 | "Clone OBJ, initializing `:parent' to OBJ. | 67 | "Clone OBJ, initializing `:parent' to OBJ. |
| 68 | All slots are unbound, except those initialized with PARAMS." | 68 | All slots are unbound, except those initialized with PARAMS." |
| 69 | (let ((nobj (make-vector (length obj) eieio-unbound)) | 69 | (let ((nobj (call-next-method))) |
| 70 | (nm (eieio--object-name obj)) | ||
| 71 | (passname (and params (stringp (car params)))) | ||
| 72 | (num 1)) | ||
| 73 | (aset nobj 0 'object) | ||
| 74 | (setf (eieio--object-class nobj) (eieio--object-class obj)) | ||
| 75 | ;; The following was copied from the default clone. | ||
| 76 | (if (not passname) | ||
| 77 | (save-match-data | ||
| 78 | (if (string-match "-\\([0-9]+\\)" nm) | ||
| 79 | (setq num (1+ (string-to-number (match-string 1 nm))) | ||
| 80 | nm (substring nm 0 (match-beginning 0)))) | ||
| 81 | (setf (eieio--object-name nobj) (concat nm "-" (int-to-string num)))) | ||
| 82 | (setf (eieio--object-name nobj) (car params))) | ||
| 83 | ;; Now initialize from params. | ||
| 84 | (if params (shared-initialize nobj (if passname (cdr params) params))) | ||
| 85 | (oset nobj parent-instance obj) | 70 | (oset nobj parent-instance obj) |
| 86 | nobj)) | 71 | nobj)) |
| 87 | 72 | ||
| @@ -155,7 +140,7 @@ Multiple calls to `make-instance' will return this object.")) | |||
| 155 | 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." |
| 156 | :abstract t) | 141 | :abstract t) |
| 157 | 142 | ||
| 158 | (defmethod constructor :STATIC ((class eieio-singleton) _name &rest _slots) | 143 | (defmethod eieio-constructor :STATIC ((class eieio-singleton) &rest _slots) |
| 159 | "Constructor for singleton CLASS. | 144 | "Constructor for singleton CLASS. |
| 160 | NAME and SLOTS initialize the new object. | 145 | NAME and SLOTS initialize the new object. |
| 161 | This constructor guarantees that no matter how many you request, | 146 | This constructor guarantees that no matter how many you request, |
| @@ -270,7 +255,7 @@ malicious code. | |||
| 270 | Note: This function recurses when a slot of :type of some object is | 255 | Note: This function recurses when a slot of :type of some object is |
| 271 | identified, and needing more object creation." | 256 | identified, and needing more object creation." |
| 272 | (let ((objclass (nth 0 inputlist)) | 257 | (let ((objclass (nth 0 inputlist)) |
| 273 | (objname (nth 1 inputlist)) | 258 | ;; (objname (nth 1 inputlist)) |
| 274 | (slots (nthcdr 2 inputlist)) | 259 | (slots (nthcdr 2 inputlist)) |
| 275 | (createslots nil)) | 260 | (createslots nil)) |
| 276 | 261 | ||
| @@ -293,7 +278,7 @@ identified, and needing more object creation." | |||
| 293 | 278 | ||
| 294 | (setq slots (cdr (cdr slots)))) | 279 | (setq slots (cdr (cdr slots)))) |
| 295 | 280 | ||
| 296 | (apply 'make-instance objclass objname (nreverse createslots)) | 281 | (apply #'make-instance objclass (nreverse createslots)) |
| 297 | 282 | ||
| 298 | ;;(eval inputlist) | 283 | ;;(eval inputlist) |
| 299 | )) | 284 | )) |
| @@ -308,7 +293,8 @@ Second, any text properties will be stripped from strings." | |||
| 308 | (let ((slot-idx (eieio-slot-name-index class nil slot)) | 293 | (let ((slot-idx (eieio-slot-name-index class nil slot)) |
| 309 | (type nil) | 294 | (type nil) |
| 310 | (classtype nil)) | 295 | (classtype nil)) |
| 311 | (setq slot-idx (- slot-idx 3)) | 296 | (setq slot-idx (- slot-idx |
| 297 | (eval-when-compile eieio--object-num-slots))) | ||
| 312 | (setq type (aref (eieio--class-public-type (eieio--class-v class)) | 298 | (setq type (aref (eieio--class-public-type (eieio--class-v class)) |
| 313 | slot-idx)) | 299 | slot-idx)) |
| 314 | 300 | ||
| @@ -463,34 +449,38 @@ instance." | |||
| 463 | 449 | ||
| 464 | 450 | ||
| 465 | ;;; Named object | 451 | ;;; Named object |
| 466 | ;; | ||
| 467 | ;; Named objects use the objects `name' as a slot, and that slot | ||
| 468 | ;; is accessed with the `object-name' symbol. | ||
| 469 | 452 | ||
| 470 | (defclass eieio-named () | 453 | (defclass eieio-named () |
| 471 | () | 454 | ((object-name :initarg :object-name :initform nil)) |
| 472 | "Object with a name. | 455 | "Object with a name." |
| 473 | Name storage already occurs in an object. This object provides get/set | ||
| 474 | access to it." | ||
| 475 | :abstract t) | 456 | :abstract t) |
| 476 | 457 | ||
| 477 | (defmethod slot-missing ((obj eieio-named) | 458 | (defmethod eieio-object-name-string ((obj eieio-named)) |
| 478 | slot-name operation &optional new-value) | 459 | "Return a string which is OBJ's name." |
| 479 | "Called when a non-existent slot is accessed. | 460 | (or (slot-value obj 'object-name) |
| 480 | For variable `eieio-named', provide an imaginary `object-name' slot. | 461 | (symbol-name (eieio-object-class obj)))) |
| 481 | Argument OBJ is the named object. | 462 | |
| 482 | Argument SLOT-NAME is the slot that was attempted to be accessed. | 463 | (defmethod eieio-object-set-name-string ((obj eieio-named) name) |
| 483 | OPERATION is the type of access, such as `oref' or `oset'. | 464 | "Set the string which is OBJ's NAME." |
| 484 | NEW-VALUE is the value that was being set into SLOT if OPERATION were | 465 | (eieio--check-type stringp name) |
| 485 | a set type." | 466 | (eieio-oset obj 'object-name name)) |
| 486 | (if (memq slot-name '(object-name :object-name)) | 467 | |
| 487 | (cond ((eq operation 'oset) | 468 | (defmethod clone ((obj eieio-named) &rest params) |
| 488 | (if (not (stringp new-value)) | 469 | "Clone OBJ, initializing `:parent' to OBJ. |
| 489 | (signal 'invalid-slot-type | 470 | All slots are unbound, except those initialized with PARAMS." |
| 490 | (list obj slot-name 'string new-value))) | 471 | (let* ((newname (and (stringp (car params)) (pop params))) |
| 491 | (eieio-object-set-name-string obj new-value)) | 472 | (nobj (apply #'call-next-method obj params)) |
| 492 | (t (eieio-object-name-string obj))) | 473 | (nm (slot-value obj 'object-name))) |
| 493 | (call-next-method))) | 474 | (eieio-oset obj 'object-name |
| 475 | (or newname | ||
| 476 | (save-match-data | ||
| 477 | (if (and nm (string-match "-\\([0-9]+\\)" nm)) | ||
| 478 | (let ((num (1+ (string-to-number | ||
| 479 | (match-string 1 nm))))) | ||
| 480 | (concat (substring nm 0 (match-beginning 0)) | ||
| 481 | "-" (int-to-string num))) | ||
| 482 | (concat nm "-1"))))) | ||
| 483 | nobj)) | ||
| 494 | 484 | ||
| 495 | (provide 'eieio-base) | 485 | (provide 'eieio-base) |
| 496 | 486 | ||
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index 1e8d17d2652..299df8db378 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el | |||
| @@ -39,6 +39,9 @@ | |||
| 39 | "Like `defalias', but with less side-effects. | 39 | "Like `defalias', but with less side-effects. |
| 40 | More specifically, it has no side-effects at all when the new function | 40 | More specifically, it has no side-effects at all when the new function |
| 41 | definition is the same (`eq') as the old one." | 41 | definition is the same (`eq') as the old one." |
| 42 | (while (and (fboundp name) (symbolp (symbol-function name))) | ||
| 43 | ;; Follow aliases, so methods applied to obsolete aliases still work. | ||
| 44 | (setq name (symbol-function name))) | ||
| 42 | (unless (and (fboundp name) | 45 | (unless (and (fboundp name) |
| 43 | (eq (symbol-function name) body)) | 46 | (eq (symbol-function name) body)) |
| 44 | (defalias name body))) | 47 | (defalias name body))) |
| @@ -167,8 +170,7 @@ Stored outright without modifications or stripping."))) | |||
| 167 | 170 | ||
| 168 | (eieio--define-field-accessors object | 171 | (eieio--define-field-accessors object |
| 169 | (-unused-0 ;;Constant slot, set to `object'. | 172 | (-unused-0 ;;Constant slot, set to `object'. |
| 170 | (class "class struct defining OBJ") | 173 | (class "class struct defining OBJ"))) |
| 171 | name)) ;FIXME: Get rid of this field! | ||
| 172 | 174 | ||
| 173 | ;; FIXME: The constants below should have an `eieio-' prefix added!! | 175 | ;; FIXME: The constants below should have an `eieio-' prefix added!! |
| 174 | (defconst eieio--method-static 0 "Index into :static tag on a method.") | 176 | (defconst eieio--method-static 0 "Index into :static tag on a method.") |
| @@ -480,10 +482,10 @@ See `defclass' for more information." | |||
| 480 | ;; Create the test function | 482 | ;; Create the test function |
| 481 | (let ((csym (intern (concat (symbol-name cname) "-p")))) | 483 | (let ((csym (intern (concat (symbol-name cname) "-p")))) |
| 482 | (fset csym | 484 | (fset csym |
| 483 | (list 'lambda (list 'obj) | 485 | `(lambda (obj) |
| 484 | (format "Test OBJ to see if it an object of type %s" cname) | 486 | ,(format "Test OBJ to see if it an object of type %s" cname) |
| 485 | (list 'and '(eieio-object-p obj) | 487 | (and (eieio-object-p obj) |
| 486 | (list 'same-class-p 'obj cname))))) | 488 | (same-class-p obj ',cname))))) |
| 487 | 489 | ||
| 488 | ;; Make sure the method invocation order is a valid value. | 490 | ;; Make sure the method invocation order is a valid value. |
| 489 | (let ((io (class-option-assoc options :method-invocation-order))) | 491 | (let ((io (class-option-assoc options :method-invocation-order))) |
| @@ -499,7 +501,7 @@ See `defclass' for more information." | |||
| 499 | "Test OBJ to see if it an object is a child of type %s" | 501 | "Test OBJ to see if it an object is a child of type %s" |
| 500 | cname) | 502 | cname) |
| 501 | (and (eieio-object-p obj) | 503 | (and (eieio-object-p obj) |
| 502 | (object-of-class-p obj ,cname)))) | 504 | (object-of-class-p obj ',cname)))) |
| 503 | 505 | ||
| 504 | ;; When using typep, (typep OBJ 'myclass) returns t for objects which | 506 | ;; When using typep, (typep OBJ 'myclass) returns t for objects which |
| 505 | ;; are subclasses of myclass. For our predicates, however, it is | 507 | ;; are subclasses of myclass. For our predicates, however, it is |
| @@ -722,9 +724,14 @@ See `defclass' for more information." | |||
| 722 | 724 | ||
| 723 | ;; Non-abstract classes need a constructor. | 725 | ;; Non-abstract classes need a constructor. |
| 724 | (fset cname | 726 | (fset cname |
| 725 | `(lambda (newname &rest slots) | 727 | `(lambda (&rest slots) |
| 726 | ,(format "Create a new object with name NAME of class type %s" cname) | 728 | ,(format "Create a new object with name NAME of class type %s" cname) |
| 727 | (apply #'constructor ,cname newname slots))) | 729 | (if (and slots |
| 730 | (let ((x (car slots))) | ||
| 731 | (or (stringp x) (null x)))) | ||
| 732 | (message "Obsolete name %S passed to %S constructor" | ||
| 733 | (pop slots) ',cname)) | ||
| 734 | (apply #'eieio-constructor ',cname slots))) | ||
| 728 | ) | 735 | ) |
| 729 | 736 | ||
| 730 | ;; Set up a specialized doc string. | 737 | ;; Set up a specialized doc string. |
| @@ -761,7 +768,6 @@ See `defclass' for more information." | |||
| 761 | nil))) | 768 | nil))) |
| 762 | (aset cache 0 'object) | 769 | (aset cache 0 'object) |
| 763 | (setf (eieio--object-class cache) cname) | 770 | (setf (eieio--object-class cache) cname) |
| 764 | (setf (eieio--object-name cache) 'default-cache-object) | ||
| 765 | (let ((eieio-skip-typecheck t)) | 771 | (let ((eieio-skip-typecheck t)) |
| 766 | ;; All type-checking has been done to our satisfaction | 772 | ;; All type-checking has been done to our satisfaction |
| 767 | ;; before this call. Don't waste our time in this call.. | 773 | ;; before this call. Don't waste our time in this call.. |
| @@ -1087,6 +1093,10 @@ the new child class." | |||
| 1087 | 1093 | ||
| 1088 | (defun eieio--defgeneric-init-form (method doc-string) | 1094 | (defun eieio--defgeneric-init-form (method doc-string) |
| 1089 | "Form to use for the initial definition of a generic." | 1095 | "Form to use for the initial definition of a generic." |
| 1096 | (while (and (fboundp method) (symbolp (symbol-function method))) | ||
| 1097 | ;; Follow aliases, so methods applied to obsolete aliases still work. | ||
| 1098 | (setq method (symbol-function method))) | ||
| 1099 | |||
| 1090 | (cond | 1100 | (cond |
| 1091 | ((or (not (fboundp method)) | 1101 | ((or (not (fboundp method)) |
| 1092 | (eq 'autoload (car-safe (symbol-function method)))) | 1102 | (eq 'autoload (car-safe (symbol-function method)))) |
| @@ -1198,6 +1208,11 @@ but remove reference to all implementations of METHOD." | |||
| 1198 | ;; Primary key. | 1208 | ;; Primary key. |
| 1199 | ;; (t eieio--method-primary) | 1209 | ;; (t eieio--method-primary) |
| 1200 | (t (error "Unknown method kind %S" kind))))) | 1210 | (t (error "Unknown method kind %S" kind))))) |
| 1211 | |||
| 1212 | (while (and (fboundp method) (symbolp (symbol-function method))) | ||
| 1213 | ;; Follow aliases, so methods applied to obsolete aliases still work. | ||
| 1214 | (setq method (symbol-function method))) | ||
| 1215 | |||
| 1201 | ;; Make sure there is a generic (when called from defclass). | 1216 | ;; Make sure there is a generic (when called from defclass). |
| 1202 | (eieio--defalias | 1217 | (eieio--defalias |
| 1203 | method (eieio--defgeneric-init-form | 1218 | method (eieio--defgeneric-init-form |
| @@ -1253,7 +1268,7 @@ an error." | |||
| 1253 | (if eieio-skip-typecheck | 1268 | (if eieio-skip-typecheck |
| 1254 | nil | 1269 | nil |
| 1255 | ;; Trim off object IDX junk added in for the object index. | 1270 | ;; Trim off object IDX junk added in for the object index. |
| 1256 | (setq slot-idx (- slot-idx 3)) | 1271 | (setq slot-idx (- slot-idx (eval-when-compile eieio--object-num-slots))) |
| 1257 | (let ((st (aref (eieio--class-public-type (eieio--class-v class)) slot-idx))) | 1272 | (let ((st (aref (eieio--class-public-type (eieio--class-v class)) slot-idx))) |
| 1258 | (if (not (eieio-perform-slot-validation st value)) | 1273 | (if (not (eieio-perform-slot-validation st value)) |
| 1259 | (signal 'invalid-slot-type (list class slot st value)))))) | 1274 | (signal 'invalid-slot-type (list class slot st value)))))) |
| @@ -1324,7 +1339,8 @@ Fills in OBJ's SLOT with its default value." | |||
| 1324 | ;;(signal 'invalid-slot-name (list (class-name cl) slot)) | 1339 | ;;(signal 'invalid-slot-name (list (class-name cl) slot)) |
| 1325 | ) | 1340 | ) |
| 1326 | (eieio-barf-if-slot-unbound | 1341 | (eieio-barf-if-slot-unbound |
| 1327 | (let ((val (nth (- c 3) (eieio--class-public-d (eieio--class-v cl))))) | 1342 | (let ((val (nth (- c (eval-when-compile eieio--object-num-slots)) |
| 1343 | (eieio--class-public-d (eieio--class-v cl))))) | ||
| 1328 | (eieio-default-eval-maybe val)) | 1344 | (eieio-default-eval-maybe val)) |
| 1329 | obj cl 'oref-default)))) | 1345 | obj cl 'oref-default)))) |
| 1330 | 1346 | ||
| @@ -1382,7 +1398,8 @@ Fills in the default value in CLASS' in SLOT with VALUE." | |||
| 1382 | (signal 'invalid-slot-name (list (eieio-class-name class) slot))) | 1398 | (signal 'invalid-slot-name (list (eieio-class-name class) slot))) |
| 1383 | (eieio-validate-slot-value class c value slot) | 1399 | (eieio-validate-slot-value class c value slot) |
| 1384 | ;; Set this into the storage for defaults. | 1400 | ;; Set this into the storage for defaults. |
| 1385 | (setcar (nthcdr (- c 3) (eieio--class-public-d (eieio--class-v class))) | 1401 | (setcar (nthcdr (- c (eval-when-compile eieio--object-num-slots)) |
| 1402 | (eieio--class-public-d (eieio--class-v class))) | ||
| 1386 | value) | 1403 | value) |
| 1387 | ;; Take the value, and put it into our cache object. | 1404 | ;; Take the value, and put it into our cache object. |
| 1388 | (eieio-oset (eieio--class-default-object-cache (eieio--class-v class)) | 1405 | (eieio-oset (eieio--class-default-object-cache (eieio--class-v class)) |
| @@ -1420,18 +1437,18 @@ reverse-lookup that name, and recurse with the associated slot value." | |||
| 1420 | (if (integerp fsi) | 1437 | (if (integerp fsi) |
| 1421 | (cond | 1438 | (cond |
| 1422 | ((not (cdr fsym)) | 1439 | ((not (cdr fsym)) |
| 1423 | (+ 3 fsi)) | 1440 | (+ (eval-when-compile eieio--object-num-slots) fsi)) |
| 1424 | ((and (eq (cdr fsym) 'protected) | 1441 | ((and (eq (cdr fsym) 'protected) |
| 1425 | (eieio--scoped-class) | 1442 | (eieio--scoped-class) |
| 1426 | (or (child-of-class-p class (eieio--scoped-class)) | 1443 | (or (child-of-class-p class (eieio--scoped-class)) |
| 1427 | (and (eieio-object-p obj) | 1444 | (and (eieio-object-p obj) |
| 1428 | (child-of-class-p class (eieio--object-class obj))))) | 1445 | (child-of-class-p class (eieio--object-class obj))))) |
| 1429 | (+ 3 fsi)) | 1446 | (+ (eval-when-compile eieio--object-num-slots) fsi)) |
| 1430 | ((and (eq (cdr fsym) 'private) | 1447 | ((and (eq (cdr fsym) 'private) |
| 1431 | (or (and (eieio--scoped-class) | 1448 | (or (and (eieio--scoped-class) |
| 1432 | (eieio-slot-originating-class-p (eieio--scoped-class) slot)) | 1449 | (eieio-slot-originating-class-p (eieio--scoped-class) slot)) |
| 1433 | eieio-initializing-object)) | 1450 | eieio-initializing-object)) |
| 1434 | (+ 3 fsi)) | 1451 | (+ (eval-when-compile eieio--object-num-slots) fsi)) |
| 1435 | (t nil)) | 1452 | (t nil)) |
| 1436 | (let ((fn (eieio-initarg-to-attribute class slot))) | 1453 | (let ((fn (eieio-initarg-to-attribute class slot))) |
| 1437 | (if fn (eieio-slot-name-index class obj fn) nil))))) | 1454 | (if fn (eieio-slot-name-index class obj fn) nil))))) |
| @@ -1778,12 +1795,8 @@ for this common case to improve performance." | |||
| 1778 | (setq mclass (eieio--object-class firstarg))) | 1795 | (setq mclass (eieio--object-class firstarg))) |
| 1779 | ((not firstarg) | 1796 | ((not firstarg) |
| 1780 | (error "Method %s called on nil" method)) | 1797 | (error "Method %s called on nil" method)) |
| 1781 | ((not (eieio-object-p firstarg)) | ||
| 1782 | (error "Primary-only method %s called on something not an object" method)) | ||
| 1783 | (t | 1798 | (t |
| 1784 | (error "EIEIO Error: Improperly classified method %s as primary only" | 1799 | (error "Primary-only method %s called on something not an object" method))) |
| 1785 | method) | ||
| 1786 | )) | ||
| 1787 | ;; Make sure the class is a valid class | 1800 | ;; Make sure the class is a valid class |
| 1788 | ;; mclass can be nil (meaning a generic for should be used. | 1801 | ;; mclass can be nil (meaning a generic for should be used. |
| 1789 | ;; mclass cannot have a value that is not a class, however. | 1802 | ;; mclass cannot have a value that is not a class, however. |
diff --git a/lisp/emacs-lisp/eieio-custom.el b/lisp/emacs-lisp/eieio-custom.el index 189337bd5f9..8172cbeef6f 100644 --- a/lisp/emacs-lisp/eieio-custom.el +++ b/lisp/emacs-lisp/eieio-custom.el | |||
| @@ -70,7 +70,7 @@ of these.") | |||
| 70 | :documentation "A number of thingies.")) | 70 | :documentation "A number of thingies.")) |
| 71 | "A class for testing the widget on.") | 71 | "A class for testing the widget on.") |
| 72 | 72 | ||
| 73 | (defcustom eieio-widget-test (eieio-widget-test-class "Foo") | 73 | (defcustom eieio-widget-test (eieio-widget-test-class) |
| 74 | "Test variable for editing an object." | 74 | "Test variable for editing an object." |
| 75 | :type 'object | 75 | :type 'object |
| 76 | :group 'eieio) | 76 | :group 'eieio) |
| @@ -317,7 +317,7 @@ Optional argument IGNORE is an extraneous parameter." | |||
| 317 | fgroup (cdr fgroup) | 317 | fgroup (cdr fgroup) |
| 318 | fcust (cdr fcust))) | 318 | fcust (cdr fcust))) |
| 319 | ;; Set any name updates on it. | 319 | ;; Set any name updates on it. |
| 320 | (if name (setf (eieio--object-name obj) name)) | 320 | (if name (eieio-object-set-name-string obj name)) |
| 321 | ;; This is the same object we had before. | 321 | ;; This is the same object we had before. |
| 322 | obj)) | 322 | obj)) |
| 323 | 323 | ||
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index f4e1d246011..51b8c3d2b4a 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -144,12 +144,7 @@ In EIEIO, the class' constructor requires a name for use when printing. | |||
| 144 | `make-instance' in CLOS doesn't use names the way Emacs does, so the | 144 | `make-instance' in CLOS doesn't use names the way Emacs does, so the |
| 145 | class is used as the name slot instead when INITARGS doesn't start with | 145 | class is used as the name slot instead when INITARGS doesn't start with |
| 146 | a string." | 146 | a string." |
| 147 | (if (and (car initargs) (stringp (car initargs))) | 147 | (apply (class-constructor class) initargs)) |
| 148 | (apply (class-constructor class) initargs) | ||
| 149 | (apply (class-constructor class) | ||
| 150 | (cond ((symbolp class) (symbol-name class)) | ||
| 151 | (t (format "%S" class))) | ||
| 152 | initargs))) | ||
| 153 | 148 | ||
| 154 | 149 | ||
| 155 | ;;; CLOS methods and generics | 150 | ;;; CLOS methods and generics |
| @@ -279,20 +274,28 @@ variable name of the same name as the slot." | |||
| 279 | If EXTRA, include that in the string returned to represent the symbol." | 274 | If EXTRA, include that in the string returned to represent the symbol." |
| 280 | (eieio--check-type eieio-object-p obj) | 275 | (eieio--check-type eieio-object-p obj) |
| 281 | (format "#<%s %s%s>" (symbol-name (eieio--object-class obj)) | 276 | (format "#<%s %s%s>" (symbol-name (eieio--object-class obj)) |
| 282 | (eieio--object-name obj) (or extra ""))) | 277 | (eieio-object-name-string obj) (or extra ""))) |
| 283 | (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") | 278 | (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") |
| 284 | 279 | ||
| 285 | (defun eieio-object-name-string (obj) "Return a string which is OBJ's name." | 280 | (defconst eieio--object-names (make-hash-table :test #'eq :weakness 'key)) |
| 286 | (eieio--check-type eieio-object-p obj) | 281 | |
| 287 | (eieio--object-name obj)) | 282 | ;; In the past, every EIEIO object had a `name' field, so we had the two method |
| 283 | ;; below "for free". Since this field is very rarely used, we got rid of it | ||
| 284 | ;; and instead we keep it in a weak hash-tables, for those very rare objects | ||
| 285 | ;; that use it. | ||
| 286 | (defmethod eieio-object-name-string (obj) | ||
| 287 | "Return a string which is OBJ's name." | ||
| 288 | (declare (obsolete eieio-named "25.1")) | ||
| 289 | (or (gethash obj eieio--object-names) | ||
| 290 | (symbol-name (eieio-object-class obj)))) | ||
| 288 | (define-obsolete-function-alias | 291 | (define-obsolete-function-alias |
| 289 | 'object-name-string #'eieio-object-name-string "24.4") | 292 | 'object-name-string #'eieio-object-name-string "24.4") |
| 290 | 293 | ||
| 291 | (defun eieio-object-set-name-string (obj name) | 294 | (defmethod eieio-object-set-name-string (obj name) |
| 292 | "Set the string which is OBJ's NAME." | 295 | "Set the string which is OBJ's NAME." |
| 293 | (eieio--check-type eieio-object-p obj) | 296 | (declare (obsolete eieio-named "25.1")) |
| 294 | (eieio--check-type stringp name) | 297 | (eieio--check-type stringp name) |
| 295 | (setf (eieio--object-name obj) name)) | 298 | (setf (gethash obj eieio--object-names) name)) |
| 296 | (define-obsolete-function-alias | 299 | (define-obsolete-function-alias |
| 297 | 'object-set-name-string 'eieio-object-set-name-string "24.4") | 300 | 'object-set-name-string 'eieio-object-set-name-string "24.4") |
| 298 | 301 | ||
| @@ -574,20 +577,19 @@ This class is not stored in the `parent' slot of a class vector." | |||
| 574 | 577 | ||
| 575 | (defalias 'standard-class 'eieio-default-superclass) | 578 | (defalias 'standard-class 'eieio-default-superclass) |
| 576 | 579 | ||
| 577 | (defgeneric constructor (class newname &rest slots) | 580 | (defgeneric eieio-constructor (class &rest slots) |
| 578 | "Default constructor for CLASS `eieio-default-superclass'.") | 581 | "Default constructor for CLASS `eieio-default-superclass'.") |
| 579 | 582 | ||
| 580 | (defmethod constructor :static | 583 | (define-obsolete-function-alias 'constructor #'eieio-constructor "25.1") |
| 581 | ((class eieio-default-superclass) newname &rest slots) | 584 | |
| 585 | (defmethod eieio-constructor :static | ||
| 586 | ((class eieio-default-superclass) &rest slots) | ||
| 582 | "Default constructor for CLASS `eieio-default-superclass'. | 587 | "Default constructor for CLASS `eieio-default-superclass'. |
| 583 | NEWNAME is the name to be given to the constructed object. | ||
| 584 | SLOTS are the initialization slots used by `shared-initialize'. | 588 | SLOTS are the initialization slots used by `shared-initialize'. |
| 585 | This static method is called when an object is constructed. | 589 | This static method is called when an object is constructed. |
| 586 | It allocates the vector used to represent an EIEIO object, and then | 590 | It allocates the vector used to represent an EIEIO object, and then |
| 587 | calls `shared-initialize' on that object." | 591 | calls `shared-initialize' on that object." |
| 588 | (let* ((new-object (copy-sequence (eieio--class-default-object-cache (eieio--class-v class))))) | 592 | (let* ((new-object (copy-sequence (eieio--class-default-object-cache (eieio--class-v class))))) |
| 589 | ;; Update the name for the newly created object. | ||
| 590 | (setf (eieio--object-name new-object) newname) | ||
| 591 | ;; Call the initialize method on the new object with the slots | 593 | ;; Call the initialize method on the new object with the slots |
| 592 | ;; that were passed down to us. | 594 | ;; that were passed down to us. |
| 593 | (initialize-instance new-object slots) | 595 | (initialize-instance new-object slots) |
| @@ -715,18 +717,10 @@ first and modify the returned object.") | |||
| 715 | 717 | ||
| 716 | (defmethod clone ((obj eieio-default-superclass) &rest params) | 718 | (defmethod clone ((obj eieio-default-superclass) &rest params) |
| 717 | "Make a copy of OBJ, and then apply PARAMS." | 719 | "Make a copy of OBJ, and then apply PARAMS." |
| 718 | (let ((nobj (copy-sequence obj)) | 720 | (let ((nobj (copy-sequence obj))) |
| 719 | (nm (eieio--object-name obj)) | 721 | (if (stringp (car params)) |
| 720 | (passname (and params (stringp (car params)))) | 722 | (message "Obsolete name %S passed to clone" (pop params))) |
| 721 | (num 1)) | 723 | (if params (shared-initialize nobj params)) |
| 722 | (if params (shared-initialize nobj (if passname (cdr params) params))) | ||
| 723 | (if (not passname) | ||
| 724 | (save-match-data | ||
| 725 | (if (string-match "-\\([0-9]+\\)" nm) | ||
| 726 | (setq num (1+ (string-to-number (match-string 1 nm))) | ||
| 727 | nm (substring nm 0 (match-beginning 0)))) | ||
| 728 | (setf (eieio--object-name nobj) (concat nm "-" (int-to-string num)))) | ||
| 729 | (setf (eieio--object-name nobj) (car params))) | ||
| 730 | nobj)) | 724 | nobj)) |
| 731 | 725 | ||
| 732 | (defgeneric destructor (this &rest params) | 726 | (defgeneric destructor (this &rest params) |
| @@ -889,7 +883,7 @@ variable PRINT-FUNCTION. Optional argument NOESCAPE is passed to | |||
| 889 | 883 | ||
| 890 | ;;; Start of automatically extracted autoloads. | 884 | ;;; Start of automatically extracted autoloads. |
| 891 | 885 | ||
| 892 | ;;;### (autoloads nil "eieio-custom" "eieio-custom.el" "6413249ec10091eb7094238637b40e2c") | 886 | ;;;### (autoloads nil "eieio-custom" "eieio-custom.el" "3a6fffe3af331fe960f967d0da99e8e9") |
| 893 | ;;; Generated autoloads from eieio-custom.el | 887 | ;;; Generated autoloads from eieio-custom.el |
| 894 | 888 | ||
| 895 | (autoload 'customize-object "eieio-custom" "\ | 889 | (autoload 'customize-object "eieio-custom" "\ |
| @@ -900,7 +894,7 @@ Optional argument GROUP is the sub-group of slots to display. | |||
| 900 | 894 | ||
| 901 | ;;;*** | 895 | ;;;*** |
| 902 | 896 | ||
| 903 | ;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "6f114a48de40212413d2776eedc3ec14") | 897 | ;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "2ff7d98da3f84c6af5c873ffb781930e") |
| 904 | ;;; Generated autoloads from eieio-opt.el | 898 | ;;; Generated autoloads from eieio-opt.el |
| 905 | 899 | ||
| 906 | (autoload 'eieio-browse "eieio-opt" "\ | 900 | (autoload 'eieio-browse "eieio-opt" "\ |