ybiquitous/rbs-mode

Setup SMIE

ybiquitous opened this issue · 1 comments

The current implementation of indentation is naive:

rbs-mode/rbs-mode.el

Lines 43 to 74 in 40d71eb

(defun rbs-indent-line ()
"Correct the indentation of the current RBS line."
(indent-line-to (rbs-calculate-indent-level)))
(defun rbs-calculate-indent-level ()
"Return the proper indentation level of the current line."
(save-excursion
(let* ((prev-level (rbs-previous-indent-level))
(block-start-line-re (concat "^[[:space:]]*" (regexp-opt '("class" "module" "interface") 'symbols)))
(block-end-line-re (concat "^[[:space:]]*" (regexp-opt '("end") 'symbols))))
(cond
((string-match-p block-start-line-re (rbs-previous-line))
(+ prev-level rbs-indent-level))
((string-match-p block-end-line-re (rbs-current-line))
(max 0 (- prev-level rbs-indent-level)))
(t prev-level)))))
(defun rbs-current-line ()
"Return the current line."
(string-trim-right (thing-at-point 'line t)))
(defun rbs-previous-line ()
"Return the previous line."
(save-excursion
(forward-line -1)
(string-trim-right (thing-at-point 'line t))))
(defun rbs-previous-indent-level ()
"Return the previous indent level."
(save-excursion
(forward-line -1)
(current-indentation)))