Skip to content

Commit 37b5303

Browse files
authored
Merge pull request #616 from mwette/issue603
fixes issue 603: indenting for foo[x] -> \ bar
2 parents 254c963 + 80615bf commit 37b5303

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

editors/emacs/fpp-mode.el

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
;;
33
;; Author: Dennis Ogbe <do@ogbe.net>
44
;; Keywords: languages, fpp
5-
;; Version: 1
5+
;; Version: 1.1
66

77
;;; Commentary:
88
;;
@@ -44,7 +44,7 @@
4444
"at" "base" "block" "change" "choice" "command"
4545
"connections" "cpu" "default" "diagnostic" "do"
4646
"drop" "else" "entry" "event" "exit"
47-
"false" "fatal" "format" "get" "group" "guard"
47+
"false" "fatal" "format" "get" "guard"
4848
"guarded" "health" "high" "hook" "id" "if" "import"
4949
"include" "initial" "input" "internal"
5050
"locate" "low" "match" "on" "opcode" "orange"
@@ -110,17 +110,23 @@
110110
(while (fpp-mode-is-continued-line t))
111111
(beginning-of-line))
112112

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+
113123
(defun fpp-mode-indent-function ()
114124
"A very simple-minded indentation algorithm for FPP."
115125
(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)))
124130
(if has-closing-paren
125131
;; skip closing paren to get right number of levels from `syntax-ppss'
126132
(end-of-line)

0 commit comments

Comments
 (0)