forked from melton1968/math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math-code.el
52 lines (40 loc) · 1.27 KB
/
math-code.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
(require 'math-parse)
;; Indent the current line based on the parameters in
;; `math-indent-list'. Return the new location for point if line is
;; successfully indented, nil otherwise.
;;
;; Assumptions:
;; point is at bol for current line.
;; point is not inside of a comment or string.
(defun math-code-indent ()
(let ((pt (math-c--parse-to-point))
(errors (math-match-tree 'Error pt)))
(cond
;; If the parse is clean, the next token must start a new
;; statement.
((not errors)
(let* ((link (math-link-lookup :statement))
(source (math-link-source link))
(offset (math-link-offset link)))
(cond
((equal :bol source)
(math-link-offset link)
(indent-line-to offset)
(move-to-column offset)
(point)))))
;; If there is a single :eof error in the parse, then we need to
;; analyze the parse.
((and (equal 1 (length errors)) (equal :eof (math-token-class (nth 3 errors))))
nil)
(t nil))))
;; Parse from bob to current point
(defun math-c--parse-to-point ()
(save-excursion
(save-restriction
(narrow-to-region (point-min) (point))
(goto-char (point-min))
(math-parse-program))))
(defun math-compute-indent (parse-tree indentation-rules)
;;
)
(provide 'math-code)