Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup SMIE #3

Open
ybiquitous opened this issue Apr 12, 2021 · 1 comment
Open

Setup SMIE #3

ybiquitous opened this issue Apr 12, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@ybiquitous
Copy link
Owner

https://www.gnu.org/software/emacs/manual/html_node/elisp/SMIE.html

@ybiquitous ybiquitous added the enhancement New feature or request label Apr 12, 2021
@ybiquitous
Copy link
Owner Author

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)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant