]> git.eshelyaron.com Git - emacs.git/commitdiff
* Update syncdoc to dump all preloaded type hierarchy
authorAndrea Corallo <acorallo@gnu.org>
Wed, 6 Mar 2024 14:41:37 +0000 (15:41 +0100)
committerEshel Yaron <me@eshelyaron.com>
Thu, 7 Mar 2024 08:21:12 +0000 (09:21 +0100)
* admin/syncdoc-type-hierarchy.el (syncdoc-file)
(syncdoc-emacs-repo-dir): New constants.
(syncdoc-lispref-dir): Make use of.
(syncdoc-all-types): New function.
(comp--direct-supertypes): Declare.
(syncdoc-hierarchy): Update.
(syncdoc-update-type-hierarchy0): Rename from
'syncdoc-update-type-hierarchy' and make non interactive.
(syncdoc-update-type-hierarchy): New function.

(cherry picked from commit 9526bd3cf8eb5e5ed78c7fb8eb03d9e7dac9b941)

admin/syncdoc-type-hierarchy.el

index 6448369625bbf86145653ad9ec541958caccf247..b8cd71fe84e891e57b929417c69c1de1baacbdff 100644 (file)
 (require 'cl-lib)
 (require 'org-table)
 
+(defconst syncdoc-file (or (macroexp-file-name) buffer-file-name))
+
+(defconst syncdoc-emacs-repo-dir
+  (expand-file-name "../" (file-name-directory syncdoc-file)))
+
 (defconst syncdoc-lispref-dir
-  (expand-file-name "../doc/lispref/"
-                    (file-name-directory
-                     (or (macroexp-file-name)
-                         buffer-file-name))))
+  (expand-file-name "doc/lispref/" syncdoc-emacs-repo-dir))
+
+(defconst syncdoc-all-types
+  (let (res)
+    (maphash (lambda (type _)
+               (push type res))
+             cl--direct-supertypes-of-type)
+
+    (mapatoms (lambda (type)
+                (when (cl-find-class type)
+                  (push type res)))
+              obarray)
+    res)
+  "List of all types.")
+
+(declare-function 'comp--direct-supertypes "comp-cstr.el")
 
 (defconst syncdoc-hierarchy
-  (let ((ht (copy-hash-table cl--direct-supertypes-of-type)))
-    ;; Include info about "representative" other structure types,
-    ;; to illustrate how they fit.
-    (mapc #'require '(kmacro eieio-base elisp-mode frameset transient))
-    (let ((extra-types '(advice kmacro cl-structure-object cl-structure-class
-                         eieio-default-superclass eieio-named transient-infix
-                         xref-elisp-location frameset-register))
-          (seen ()))
-      (while extra-types
-        (let* ((type (pop extra-types))
-               (class (get type 'cl--class))
-               (parents (cl--class-parents class)))
-          (unless (member type seen)
-            (push type seen)
-            (push (type-of class) extra-types)
-            (puthash type (cond
-                           (parents
-                            (let ((ps (mapcar #'cl--class-name parents)))
-                              (setq extra-types (append ps extra-types))
-                              ps))
-                           ;; EIEIO's parents don't mention the default.
-                           ((and (eq (type-of class) 'eieio--class)
-                                 (not (eq type 'eieio-default-superclass)))
-                            '(eieio-default-superclass))
-                           ;; OClosures can still be lists :-(
-                           ((eq 'oclosure type) '(function))
-                           (t '(atom)))
-                     ht)))))
-    ht))
+  (progn
+    ;; Require it here so we don't load it before `syncdoc-all-types' is
+    ;; computed.
+    (require 'comp-cstr)
+    (cl-loop
+     with comp-ctxt = (make-comp-cstr-ctxt)
+     with h = (make-hash-table :test #'eq)
+     for type in syncdoc-all-types
+     do (puthash type (comp--direct-supertypes type) h)
+     finally return h)))
 
 (defun syncdoc-insert-dot-content (rankdir)
   (maphash (lambda (child parents)
                do (insert "\n")))
     (org-table-align)))
 
-(defun syncdoc-update-type-hierarchy ()
+(defun syncdoc-update-type-hierarchy0 ()
   "Update the type hierarchy representation used by the elisp manual."
-  (interactive)
   (with-temp-buffer
     (syncdoc-insert-dot-content "LR")
     (with-demoted-errors "%S"           ;In case "dot" is not found!
   (syncdoc-make-type-table (expand-file-name "type_hierarchy.txt"
                                              syncdoc-lispref-dir)))
 
+(defun syncdoc-update-type-hierarchy ()
+  "Update the type hierarchy representation used by the elisp manual."
+  (interactive)
+  (call-process (expand-file-name "src/emacs" syncdoc-emacs-repo-dir)
+               nil t t "-Q" "--batch" "-l" syncdoc-file
+                "-f" "syncdoc-update-type-hierarchy0"))
+
 ;;; syncdoc-type-hierarchy.el ends here