aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorStefan Monnier2024-03-04 13:24:34 -0500
committerStefan Monnier2024-03-04 13:24:34 -0500
commitb06916cb218b133a4ebc9d7fa87b370fc2c2ed02 (patch)
tree3e57baefca2fdbe4eb689e7336f29921b685c3cb /admin
parent167c17c1ad740b35ed1c875b57817784655851d9 (diff)
downloademacs-b06916cb218b133a4ebc9d7fa87b370fc2c2ed02.tar.gz
emacs-b06916cb218b133a4ebc9d7fa87b370fc2c2ed02.zip
syncdoc-type-hierarchy.el: Adjust to changes in `cl-preloaded.el`
* admin/syncdoc-type-hierarchy.el (syncdoc-lispref-dir): Use `macroexp-file-name`. (syncdoc-hierarchy): New var. (syncdoc-insert-dot-content, syncdoc-make-type-table): Use it. (syncdoc-update-type-hierarchy): Don't crash if `dot` is absent.
Diffstat (limited to 'admin')
-rw-r--r--admin/syncdoc-type-hierarchy.el83
1 files changed, 61 insertions, 22 deletions
diff --git a/admin/syncdoc-type-hierarchy.el b/admin/syncdoc-type-hierarchy.el
index b3dfe63406a..cb4df63a312 100644
--- a/admin/syncdoc-type-hierarchy.el
+++ b/admin/syncdoc-type-hierarchy.el
@@ -24,8 +24,8 @@
24 24
25;; This file is used to keep the type hierarchy representation present 25;; This file is used to keep the type hierarchy representation present
26;; in the elisp manual in sync with the current type hierarchy. This 26;; in the elisp manual in sync with the current type hierarchy. This
27;; is specified in `cl--type-hierarchy' in cl-preloaded.el, so each 27;; is specified in `cl--direct-supertypes-of-type' in cl-preloaded.el, so each
28;; time `cl--type-hierarchy' is modified 28;; time `cl--direct-supertypes-of-type' is modified
29;; `syncdoc-update-type-hierarchy' must be run before the 29;; `syncdoc-update-type-hierarchy' must be run before the
30;; documentation is regenerated. 30;; documentation is regenerated.
31 31
@@ -37,17 +37,49 @@
37(require 'cl-lib) 37(require 'cl-lib)
38(require 'org-table) 38(require 'org-table)
39 39
40(defconst syncdoc-lispref-dir (concat (file-name-directory 40(defconst syncdoc-lispref-dir
41 (or load-file-name 41 (expand-file-name "../doc/lispref/"
42 buffer-file-name)) 42 (file-name-directory
43 "../doc/lispref/")) 43 (or (macroexp-file-name)
44 buffer-file-name))))
45
46(defconst syncdoc-hierarchy
47 (let ((ht (copy-hash-table cl--direct-supertypes-of-type)))
48 ;; Include info about "representative" other structure types,
49 ;; to illustrate how they fit.
50 (mapc #'require '(kmacro eieio-base elisp-mode frameset transient))
51 (let ((extra-types '(advice kmacro cl-structure-object cl-structure-class
52 eieio-default-superclass eieio-named transient-infix
53 xref-elisp-location frameset-register))
54 (seen ()))
55 (while extra-types
56 (let* ((type (pop extra-types))
57 (class (get type 'cl--class))
58 (parents (cl--class-parents class)))
59 (unless (member type seen)
60 (push type seen)
61 (push (type-of class) extra-types)
62 (puthash type (cond
63 (parents
64 (let ((ps (mapcar #'cl--class-name parents)))
65 (setq extra-types (append ps extra-types))
66 ps))
67 ;; EIEIO's parents don't mention the default.
68 ((and (eq (type-of class) 'eieio--class)
69 (not (eq type 'eieio-default-superclass)))
70 '(eieio-default-superclass))
71 ;; OClosures can still be lists :-(
72 ((eq 'oclosure type) '(t))
73 (t '(atom)))
74 ht)))))
75 ht))
44 76
45(defun syncdoc-insert-dot-content (rankdir) 77(defun syncdoc-insert-dot-content (rankdir)
46 (maphash (lambda (child parents) 78 (maphash (lambda (child parents)
47 (cl-loop for parent in parents 79 (cl-loop for parent in parents
48 do (insert " \"" (symbol-name child) "\" -> \"" 80 do (insert " \"" (symbol-name child) "\" -> \""
49 (symbol-name parent) "\";\n"))) 81 (symbol-name parent) "\";\n")))
50 cl--direct-supertypes-of-type) 82 syncdoc-hierarchy)
51 (sort-lines nil (point-min) (point-max)) 83 (sort-lines nil (point-min) (point-max))
52 84
53 (goto-char (point-min)) 85 (goto-char (point-min))
@@ -58,18 +90,24 @@
58(defun syncdoc-make-type-table (file) 90(defun syncdoc-make-type-table (file)
59 (with-temp-file file 91 (with-temp-file file
60 (insert "|Type| Derived Types|\n|-\n") 92 (insert "|Type| Derived Types|\n|-\n")
61 (cl-loop for (type . children) in cl--type-hierarchy 93 (let ((subtypes ()))
62 do (insert "|" (symbol-name type) " |") 94 ;; First collect info from the "builtin" types.
63 do (cl-loop with x = 0 95 (maphash (lambda (type parents)
64 for child in children 96 (dolist (parent parents)
65 for child-len = (length (symbol-name child)) 97 (push type (alist-get parent subtypes))))
66 when (> (+ x child-len 2) 60) 98 syncdoc-hierarchy)
67 do (progn 99 (cl-loop for (type . children) in (reverse subtypes)
68 (insert "|\n||") 100 do (insert "|" (symbol-name type) " |")
69 (setq x 0)) 101 do (cl-loop with x = 0
70 do (insert (symbol-name child) " ") 102 for child in (reverse children)
71 do (cl-incf x (1+ child-len)) ) 103 for child-len = (length (symbol-name child))
72 do (insert "\n")) 104 when (> (+ x child-len 2) 60)
105 do (progn
106 (insert "|\n||")
107 (setq x 0))
108 do (insert (symbol-name child) " ")
109 do (cl-incf x (1+ child-len)) )
110 do (insert "\n")))
73 (org-table-align))) 111 (org-table-align)))
74 112
75(defun syncdoc-update-type-hierarchy () 113(defun syncdoc-update-type-hierarchy ()
@@ -77,9 +115,10 @@
77 (interactive) 115 (interactive)
78 (with-temp-buffer 116 (with-temp-buffer
79 (syncdoc-insert-dot-content "LR") 117 (syncdoc-insert-dot-content "LR")
80 (call-process-region nil nil "dot" t (current-buffer) nil "-Tjpg" "-o" 118 (with-demoted-errors "%S" ;In case "dot" is not found!
81 (expand-file-name "type_hierarchy.jpg" 119 (call-process-region nil nil "dot" t (current-buffer) nil "-Tjpg" "-o"
82 syncdoc-lispref-dir))) 120 (expand-file-name "type_hierarchy.jpg"
121 syncdoc-lispref-dir))))
83 (syncdoc-make-type-table (expand-file-name "type_hierarchy.txt" 122 (syncdoc-make-type-table (expand-file-name "type_hierarchy.txt"
84 syncdoc-lispref-dir))) 123 syncdoc-lispref-dir)))
85 124