Skip to content

Instantly share code, notes, and snippets.

@bhyde
Last active December 21, 2015 11:29
Show Gist options
  • Save bhyde/6299501 to your computer and use it in GitHub Desktop.
Save bhyde/6299501 to your computer and use it in GitHub Desktop.
Generate a graphviz of the systems required by a the given system, let dot render that, then have emacs display it. Calls back to emacs via swank::eval-in-emacs.
(in-package #:cl-user)
;; Must do ...
;; (setf slime-enable-evaluate-in-emacs t)
;; ... in emacs first. And, dot must be installed.
(defun graph-quicklisp-system (ql-system-designation)
"Display graph of system requirements."
(let ((dot-file "/tmp/ql-system.dot")
(png-file "/tmp/ql-system.png"))
(with-open-file (s dot-file
:direction :output
:if-exists :rename-and-delete)
(format s "digraph{ concentrate = true; node [shape = plaintext]; size=\"5,3\"; margin=.2;")
(labels ((sys (ql-system-designation)
(etypecase ql-system-designation
(ql-dist:system ql-system-designation)
(string (or (ql-dist:find-system ql-system-designation)
(error "Didn't find system: ~S"
ql-system-designation)))))
(clean (text)
(substitute #\_ #\- text))
(recur (ql-system-designation)
(loop
with system = (sys ql-system-designation)
with system-name = (ql-dist::name system)
initially
(format s "~&~a [label=~S];" (clean system-name) system-name)
for r in (ql-dist:required-systems system)
do
(format s "~&~A -> ~A;" (clean system-name) (clean r))
(recur r))))
(recur ql-system-designation))
(format s "~&}~&"))
(swank::eval-in-emacs
`(progn
(shell-command ,(format nil "dot ~A -Tpng -o~A" dot-file png-file))
(find-file-noselect ,png-file t)
(switch-to-buffer "ql-system.png")
t))))
; HT: https://github.com/PuercoPop/cl-datastructures/blob/7a5513a42fa53fe181a6d2f22732ccab01b00ecb/src/binary-tree.lisp#L135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment