|
2 | 2 | ;; |
3 | 3 | ;; Author: Dennis Ogbe <do@ogbe.net> |
4 | 4 | ;; Keywords: languages, fpp |
5 | | -;; Version: 1 |
| 5 | +;; Version: 1.1 |
6 | 6 |
|
7 | 7 | ;;; Commentary: |
8 | 8 | ;; |
|
44 | 44 | "at" "base" "block" "change" "choice" "command" |
45 | 45 | "connections" "cpu" "default" "diagnostic" "do" |
46 | 46 | "drop" "else" "entry" "event" "exit" |
47 | | - "false" "fatal" "format" "get" "group" "guard" |
| 47 | + "false" "fatal" "format" "get" "guard" |
48 | 48 | "guarded" "health" "high" "hook" "id" "if" "import" |
49 | 49 | "include" "initial" "input" "internal" |
50 | 50 | "locate" "low" "match" "on" "opcode" "orange" |
|
110 | 110 | (while (fpp-mode-is-continued-line t)) |
111 | 111 | (beginning-of-line)) |
112 | 112 |
|
| 113 | +(defun fpp-mode-re-count (rx) |
| 114 | + "Return the number of matches of rx in the the current line." |
| 115 | + (save-excursion |
| 116 | + (let* ((eol (progn (end-of-line) (point))) |
| 117 | + (end (progn (beginning-of-line) |
| 118 | + (or (re-search-forward "[@#]" eol t) eol)))) |
| 119 | + (beginning-of-line) |
| 120 | + (named-let loop ((cnt 0)) |
| 121 | + (if (re-search-forward rx end t) (loop (1+ cnt)) cnt))))) |
| 122 | + |
113 | 123 | (defun fpp-mode-indent-function () |
114 | 124 | "A very simple-minded indentation algorithm for FPP." |
115 | 125 | (interactive) |
116 | | - (let ((point-offset (- (current-column) (current-indentation))) |
117 | | - (has-closing-paren |
118 | | - (save-excursion |
119 | | - (beginning-of-line) |
120 | | - (fpp-mode-re-search 'forward (rx (or (intersection (not "{") "}") |
121 | | - (intersection (not "(") ")") |
122 | | - (intersection (not "[") "]"))) |
123 | | - (point-at-eol))))) |
| 126 | + (let* ((point-offset (- (current-column) (current-indentation))) |
| 127 | + (nopen (fpp-mode-re-count "[{\(\[]")) |
| 128 | + (nclose (fpp-mode-re-count "[\]\)}]")) |
| 129 | + (has-closing-paren (> (- nclose nopen) 0))) |
124 | 130 | (if has-closing-paren |
125 | 131 | ;; skip closing paren to get right number of levels from `syntax-ppss' |
126 | 132 | (end-of-line) |
|
0 commit comments