-
Notifications
You must be signed in to change notification settings - Fork 0
/
ott-debug.el
52 lines (48 loc) · 1.75 KB
/
ott-debug.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;; ott-debug.el --- Prettify ott's multiple parse errors in tree format -*- lexical-binding: t; -*-
;;; Code:
(require 'comint)
(defconst +space+
" ")
(defconst +pipe+
" │ ")
(defconst +tee+
" ├─ ")
(defconst +lower-knee+
" ╰─ ")
(defun format-tree-segments (node)
(unless node
(cl-return-from format-tree-segments nil))
(cl-flet ((prefix-node-strings (child-node &key
(root-connector +tee+)
(lower-connector +pipe+))
(cl-multiple-value-bind (r l)
(format-tree-segments child-node)
(nconc
(list (cl-concatenate 'string root-connector r))
(mapcar
(lambda (str) (cl-concatenate 'string lower-connector str))
l)))))
(let ((children (rest node)))
(values
(let ((root-name (funcall #'symbol-name (car node))))
(if (= 1 (length root-name))
(cl-concatenate 'string " " root-name)
root-name))
(when children
(cl-loop
for (head . tail) on children
while tail
nconc (prefix-node-strings head)
into strlist
finally (cl-return
(nconc
strlist
(prefix-node-strings head
:root-connector +lower-knee+
:lower-connector +space+)))))))))
(defun format-tree (tree)
(cl-multiple-value-bind (r l)
(format-tree-segments tree)
(cl-loop for i in (nconc (list r) l) do (insert (format "%s\n" i)))))
(provide 'ott-debug)
;;; ott-debug.el ends here