diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/cl-lib.el | 36 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-preloaded.el | 6 |
3 files changed, 44 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el index 8c4455a3dad..1f8615fad3e 100644 --- a/lisp/emacs-lisp/cl-lib.el +++ b/lisp/emacs-lisp/cl-lib.el | |||
| @@ -639,6 +639,42 @@ If ALIST is non-nil, the new pairs are prepended to it." | |||
| 639 | (require 'cl-macs) | 639 | (require 'cl-macs) |
| 640 | (require 'cl-seq)) | 640 | (require 'cl-seq)) |
| 641 | 641 | ||
| 642 | (defun cl--old-struct-type-of (orig-fun object) | ||
| 643 | (or (and (vectorp object) | ||
| 644 | (let ((tag (aref object 0))) | ||
| 645 | (when (and (symbolp tag) | ||
| 646 | (string-prefix-p "cl-struct-" (symbol-name tag))) | ||
| 647 | (unless (eq (symbol-function tag) | ||
| 648 | :quick-object-witness-check) | ||
| 649 | ;; Old-style old-style struct: | ||
| 650 | ;; Convert to new-style old-style struct! | ||
| 651 | (let* ((type (intern (substring (symbol-name tag) | ||
| 652 | (length "cl-struct-")))) | ||
| 653 | (class (cl--struct-get-class type))) | ||
| 654 | ;; If the `cl-defstruct' was recompiled after the code | ||
| 655 | ;; which constructed `object', `cl--struct-get-class' may | ||
| 656 | ;; not have called `cl-struct-define' and setup the tag | ||
| 657 | ;; symbol for us. | ||
| 658 | (unless (eq (symbol-function tag) | ||
| 659 | :quick-object-witness-check) | ||
| 660 | (set tag class) | ||
| 661 | (fset tag :quick-object-witness-check)))) | ||
| 662 | (cl--class-name (symbol-value tag))))) | ||
| 663 | (funcall orig-fun object))) | ||
| 664 | |||
| 665 | ;;;###autoload | ||
| 666 | (define-minor-mode cl-old-struct-compat-mode | ||
| 667 | "Enable backward compatibility with old-style structs. | ||
| 668 | This can be needed when using code byte-compiled using the old | ||
| 669 | macro-expansion of `cl-defstruct' that used vectors objects instead | ||
| 670 | of record objects." | ||
| 671 | :global t | ||
| 672 | (cond | ||
| 673 | (cl-old-struct-compat-mode | ||
| 674 | (advice-add 'type-of :around #'cl--old-struct-type-of)) | ||
| 675 | (t | ||
| 676 | (advice-remove 'type-of #'cl--old-struct-type-of)))) | ||
| 677 | |||
| 642 | ;; Local variables: | 678 | ;; Local variables: |
| 643 | ;; byte-compile-dynamic: t | 679 | ;; byte-compile-dynamic: t |
| 644 | ;; End: | 680 | ;; End: |
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index c282938a9bf..25c9f999920 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -2847,8 +2847,8 @@ non-nil value, that slot cannot be set via `setf'. | |||
| 2847 | ;; struct as a parent. | 2847 | ;; struct as a parent. |
| 2848 | (eval-and-compile | 2848 | (eval-and-compile |
| 2849 | (cl-struct-define ',name ,docstring ',include-name | 2849 | (cl-struct-define ',name ,docstring ',include-name |
| 2850 | ',type ,(eq named t) ',descs ',tag-symbol ',tag | 2850 | ',(or type 'record) ,(eq named t) ',descs |
| 2851 | ',print-auto)) | 2851 | ',tag-symbol ',tag ',print-auto)) |
| 2852 | ',name))) | 2852 | ',name))) |
| 2853 | 2853 | ||
| 2854 | ;;; Add cl-struct support to pcase | 2854 | ;;; Add cl-struct support to pcase |
diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el index 7432dd4978d..ab6354de7cd 100644 --- a/lisp/emacs-lisp/cl-preloaded.el +++ b/lisp/emacs-lisp/cl-preloaded.el | |||
| @@ -110,6 +110,12 @@ | |||
| 110 | ;;;###autoload | 110 | ;;;###autoload |
| 111 | (defun cl-struct-define (name docstring parent type named slots children-sym | 111 | (defun cl-struct-define (name docstring parent type named slots children-sym |
| 112 | tag print) | 112 | tag print) |
| 113 | (unless type | ||
| 114 | ;; Legacy defstruct, using tagged vectors. Enable backward compatibility. | ||
| 115 | (cl-old-struct-compat-mode 1)) | ||
| 116 | (if (eq type 'record) | ||
| 117 | ;; Defstruct using record objects. | ||
| 118 | (setq type nil)) | ||
| 113 | (cl-assert (or type (not named))) | 119 | (cl-assert (or type (not named))) |
| 114 | (if (boundp children-sym) | 120 | (if (boundp children-sym) |
| 115 | (add-to-list children-sym tag) | 121 | (add-to-list children-sym tag) |