-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonto-handlers.el
74 lines (65 loc) · 2.5 KB
/
monto-handlers.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
;;;;;;;;;;;;;;;;;;;;
;;; User Options ;;;
;;;;;;;;;;;;;;;;;;;;
(defconst monto-errors-face 'underline
"The face the error marker is drawn with.")
(defconst monto-highlighting-styles nil
"An alist of faces cooresponding to styles.")
;;;;;;;;;;;;;;;;;;;;;;;
;;; Library Globals ;;;
;;;;;;;;;;;;;;;;;;;;;;;
(defvar monto-errors--buffer nil
"The buffer errors are displayed in.")
;;;;;;;;;;;;;;;;;;;;;;
;;; Errors Handler ;;;
;;;;;;;;;;;;;;;;;;;;;;
(defun monto-errors--handler (path errors)
(unless monto-errors--buffer
(setq monto-errors--buffer (generate-new-buffer "*monto-errors*"))
(with-current-buffer monto-errors--buffer
(read-only-mode 1)))
(unless (get-buffer-window monto-errors--buffer)
(set-window-buffer (split-window-right) monto-errors--buffer))
(with-current-buffer monto-errors--buffer
(let ((inhibit-read-only t))
(goto-char 1)
(erase-buffer)
(remove-overlays (point-min) (point-max) 'monto-errors t)
(if (= (length errors) 0)
(insert "No errors!\n")
(dotimes (i (length errors))
(let ((err (elt errors i)))
(insert (monto--json-get err 'description))
(insert "\n\n"))))))
(dotimes (i (length errors))
(let* ((err (elt errors i))
(loc (monto--json-get err 'offset)))
(monto-errors--draw path loc))))
(defun monto-errors--draw (path location)
(let ((buf (find-file-noselect path)))
(with-current-buffer buf
(let* ((start (+ (point-min) location))
(end (1+ location))
(overlay (make-overlay start end buf)))
(overlay-put overlay 'face monto-errors-face)
(overlay-put overlay 'monto-errors t)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Highlighting Handler ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun monto-highlighting--handler (path tokens)
(let ((buf (find-file-noselect path)))
(with-current-buffer buf
(dotimes (i (length tokens))
(let* ((tok (elt tokens i))
(length (monto--json-get tok 'length))
(offset (monto--json-get tok 'offset))
(style (monto--json-get tok 'style))
(start (+ (point-min) offset))
(end (+ start length)))
(if (> (length style) 0)
(let* ((style (elt style 0))
(face (cdr (assoc style monto-highlighting-styles))))
(if face
(put-text-property start end 'font-lock-face face)
(print (concat "Unknown style: " style))))))))))
(provide 'monto-handlers)