forked from semiosis/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpen-dni.el
99 lines (83 loc) · 3.38 KB
/
pen-dni.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(define-derived-mode dni-description-mode yaml-mode "dni"
"D'ni script mode")
(add-to-list 'auto-mode-alist '("\\.dni\\'" . dni-description-mode))
;; TODO Make this into dni-let macro
;; dni is an alist
(defmacro dni-let (dni &rest body)
;; dni can be a string to a dni path or a yaml-ht
(let* ((yaml-al (if (stringp dni)
(pen--htlist-to-alist (yamlmod-read-file dni))
dni))
(defs-al yaml-al)
(dni-values)
(yaml-defs
(let* ((vars-al defs-al)
(keys (cl-loop
for atp in vars-al
collect
(car atp)))
(values (cl-loop
for atp in vars-al
collect
(cdr atp))))
(setq dni-values values)
keys))
(dni-slugs (mapcar 'slugify yaml-defs))
;; use the slugs of the keys, so i can use them in further replacements
(dni-keyvals (-zip dni-slugs dni-values))
;; (display
;; (pen-tv (pps dni-keyvals)))
(dni-replacement-keyvals)
(dni-keyvals
(cl-loop
for atp in dni-keyvals
collect
(let ((defkey (car atp))
(val (str (cdr atp))))
(cons
defkey
(let* ((eval-template-keys
(mapcar
(lambda (s)
(s-replace-regexp "<" "" (s-replace-regexp ">" "" (chomp s))))
(append
(-filter-not-empty-string
(mapcar
(lambda (e) (scrape "<\\(.*\\)>" e))
(mapcar
(lambda (s) (concat s ")>"))
(s-split ")>" val))))
(-filter-not-empty-string
(mapcar
(lambda (e) (scrape "<[a-z-]+>" e))
(mapcar
(lambda (s) (concat s ">"))
(s-split ">" val)))))))
(eval-template-vals
(mapcar
(lambda (s)
(eval
`(pen-let-keyvals
',dni-replacement-keyvals
(eval-string (s-replace-regexp "<\\([^>]*\\)>" "\\1" s)))))
eval-template-keys))
(eval-template-keyvals (-zip eval-template-keys eval-template-vals))
(updated-val
(pen-expand-template-keyvals val eval-template-keyvals))
(update
(setq dni-replacement-keyvals
(asoc-merge
`((,defkey . ,updated-val))
dni-replacement-keyvals))))
;; for each discovered eval template, i must create a key and value
;; the key is <(...)> inclusive, and the val is (eval-string "(...)")
;; update the vals here
updated-val))))))
`(pen-let-keyvals
',dni-keyvals
,@body)))
(defun pen-test-dni-let ()
(interactive)
(dni-let "/home/shane/source/git/semiosis/dni/parchment/trafficked-girl.dni"
(pen-etv description)))
(provide 'pen-dni)