reorder filtering functions, ajust filter-plexus
[arxana.git] / elisp / simple-ui.el
blob048eb7f0bb142f9c0461e06694d5b9c6a77b9578
1 (require 'cl)
2 (require 'cl-macs)
3 (require 'prelim)
4 (require 'honey)
6 (defvar simple-ui-buff (list nil (make-list 7 nil) nil))
7 ;; This variable stores three items: the buffer in which
8 ;; the nema is to be edited, markers inside that buffer
9 ;; which delimit the text which the user supplies, and
10 ;; the number of the nema being edited.
12 (defun simple-ui-init ()
13 "Initialize the buffer for editing nemata."
14 (interactive)
15 (let ((buff (get-buffer-create "nema-edit"))
16 (marx nil)
17 (places nil))
18 (cl-flet ((add-rubric (pre mid post)
19 (insert
20 (concat
21 (propertize pre
22 'face 'bold
23 'read-only "Rubric."
24 'front-sticky nil
25 'rear-nonsticky nil)
26 (propertize mid
27 'face 'bold
28 'read-only "Rubric."
29 'front-sticky t
30 'rear-nonsticky nil)
31 (propertize post
32 'face 'bold
33 'read-only "Rubric."
34 'front-sticky t
35 'rear-nonsticky t)))))
36 ;; Since the buffer may contain read-only
37 ;; text, we must inhibit the read-only
38 ;; property in order to erase such text.
39 (with-current-buffer buff
40 (let ((inhibit-read-only t))
41 (erase-buffer))
42 (dotimes (n 7)
43 (push (make-marker) marx))
44 (add-rubric "" "Editing nema" ":")
45 (push (- (point) 1) places)
46 (push (+ (point) 1) places)
47 (add-rubric "\n" "Source" ":")
48 (push (- (point) 1) places)
49 (insert " ")
50 (push (+ (point) 1) places)
51 (add-rubric "\n" "Sink" ":")
52 (push (- (point) 1) places)
53 (insert " ")
54 (push (+ (point) 1) places)
55 (add-rubric "\n" "Content" ":")
56 (push (- (point) 1) places)
57 (insert " ")
58 (mapply 'set-marker `(,marx ,(reverse places)))
59 (setq simple-ui-buff (list buff marx nil)))))
60 simple-ui-buff)
62 (defun simple-ui-load (nema)
63 "Load a nema into the editing buffer."
64 (interactive "xNema uid:")
65 (if (uid-p nema)
66 (cl-flet (
67 ;; Helper function to figure out character
68 ;; positions between which text goes.
69 (spot (n)
70 (if (< n 7)
71 (+ (marker-position
72 (nth n (nth 1 simple-ui-buff)))
73 (- 1 (* (% n 2) 2)))
74 (point-max))))
75 (with-current-buffer (nth 0 simple-ui-buff)
76 ;; Replace nema
77 (delete-region (spot 0) (spot 1))
78 (goto-char (spot 0))
79 (insert (prin1-to-string nema))
80 ;; Replace source.
81 (delete-region (spot 2) (spot 3))
82 (goto-char (spot 2))
83 (insert (prin1-to-string (get-source nema)))
84 ;; Replce sink.
85 (delete-region (spot 4) (spot 5))
86 (goto-char (spot 4))
87 (insert (prin1-to-string (get-sink nema)))
88 ;; Replace content
89 (delete-region (spot 6) (spot 7))
90 (goto-char (spot 6))
91 (insert (prin1-to-string (get-content nema)))
92 (setcar (cddr simple-ui-buff) nema))
93 nema)
94 'huh))
96 (defun simple-ui-new ()
97 "Make a new nema and edit it."
98 (interactive)
99 (simple-ui-load
100 (put-article 0 0 "")))
103 (defun simple-ui-save ()
104 "Save the nema in the editing buffer."
105 (interactive)
106 (if (uid-p (nth 2 simple-ui-buff))
107 (cl-flet (
108 ;; Helper function to figure out character
109 ;; positions between which text goes.
110 (spot (n)
111 (if (< n 7)
112 (+ (marker-position
113 (nth n (nth 1 simple-ui-buff)))
114 (- 1 (* (% n 2) 2)))
115 (point-max))))
116 (with-current-buffer (nth 0 simple-ui-buff)
117 (update-source
118 (nth 2 simple-ui-buff)
119 (car (read-from-string
120 (buffer-substring (spot 2) (spot 3)))))
121 (update-sink
122 (nth 2 simple-ui-buff)
123 (car (read-from-string
124 (buffer-substring (spot 4) (spot 5)))))
125 (update-content
126 (nth 2 simple-ui-buff)
127 (car (read-from-string
128 (buffer-substring (spot 6) (spot 7))))))
129 (nth 2 simple-ui-buff))
130 nil))