]> git.eshelyaron.com Git - emacs.git/commitdiff
eieio: Improve some obsolecence warnings and fix #<CLASS CLASS-XX> names
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 7 Apr 2025 16:41:49 +0000 (12:41 -0400)
committerEshel Yaron <me@eshelyaron.com>
Tue, 8 Apr 2025 05:50:00 +0000 (07:50 +0200)
* lisp/emacs-lisp/eieio.el (eieio--constructor-macro): Improve message.
(eieio-object-name-string): Avoid repeated class name in the output of
`eieio-object-name`.
(make-instance, clone): Improve message.

* lisp/emacs-lisp/eieio-core.el (eieio-defclass-autoload): Use the same
obsolescence warning as elsewhere.

(cherry picked from commit 9663c959c73d6cca0c56f833d80ff1d9e9708b70)

lisp/emacs-lisp/eieio-core.el
lisp/emacs-lisp/eieio.el

index b3a8698e31d93deddaeca453ac140f7ad20d3df7..99f8feb96441742dbb446c308d5f4c05ab866483 100644 (file)
@@ -208,9 +208,7 @@ It creates an autoload function for CNAME's constructor."
       ;; turn this into a usable self-pointing symbol
       (when eieio-backward-compatibility
         (set cname cname)
-        (make-obsolete-variable cname (format "\
-use '%s or turn off `eieio-backward-compatibility' instead" cname)
-                                "25.1"))
+        (make-obsolete-variable cname (format "use '%s instead" cname) "25.1"))
 
       (when (memq nil parents)
         ;; If some parents aren't yet fully defined, just ignore them for now.
index e8f31eec975658b3d8b9421d5a33fa66f5ac53d2..10a25004b4d9b6275cdfacff62fed21a68ea90fd 100644 (file)
@@ -293,12 +293,15 @@ and reference them using the function `class-option'."
              (apply #'make-instance ',name slots))))))
 
 (defun eieio--constructor-macro (whole &rest slots)
+  ;; When `eieio-backward-compatibility' is removed, we should
+  ;; remove this compiler-macro, until then, it's best to emit a compile-time
+  ;; warning even if `eieio-backward-compatibility' is nil, I think.
   (if (or (null slots) (keywordp (car slots))
           ;; Detect the second pass!
           (eq 'identity (car-safe (car slots))))
       whole
     (macroexp-warn-and-return
-     (format "Obsolete name arg %S to constructor %S"
+     (format "Obsolete name argument %S to constructor %S"
              (car slots) (car whole))
      ;; Keep the name arg, for backward compatibility,
      ;; but hide it so we don't trigger indefinitely.
@@ -405,7 +408,7 @@ contents of field NAME is matched against PAT, or they can be of
 (cl-defgeneric eieio-object-name-string (obj)
   "Return a string which is OBJ's name."
   (or (gethash obj eieio--object-names)
-      (format "%s-%x" (eieio-object-class obj) (sxhash-eq obj))))
+      (format "%x" (sxhash-eq obj))))
 
 (define-obsolete-function-alias
   'object-name-string #'eieio-object-name-string "24.4")
@@ -702,6 +705,9 @@ for each slot.  For example:
   (make-instance \\='foo :slot1 value1 :slotN valueN)")
 
 (put 'make-instance 'compiler-macro
+     ;; When `eieio-backward-compatibility' is removed, we should
+     ;; remove this compiler-macro, until then, it's best to emit a compile-time
+     ;; warning even if `eieio-backward-compatibility' is nil, I think.
      (lambda (whole class &rest slots)
        (if (or (null slots) (keywordp (car slots))
                ;; Detect the second pass!
@@ -730,7 +736,7 @@ calls `initialize-instance' on that object."
              (let ((x (car slots)))
                (or (stringp x) (null x))))
         (funcall (if eieio-backward-compatibility #'ignore #'message)
-                 "Obsolete name %S passed to %S constructor"
+                 "Obsolete name argument %S passed to %S constructor"
                  (pop slots) class))
     ;; Call the initialize method on the new object with the slots
     ;; that were passed down to us.
@@ -837,7 +843,7 @@ first and modify the returned object.")
   (let ((nobj (copy-sequence obj)))
     (if (stringp (car params))
         (funcall (if eieio-backward-compatibility #'ignore #'message)
-                 "Obsolete name %S passed to clone" (pop params)))
+                 "Obsolete name argument %S passed to clone" (pop params)))
     (if params (shared-initialize nobj params))
     nobj))