branch: elpa/forth-mode
commit 0d22cedbaf2530386eeb5faff8feef6a7a25ee82
Author: Helmut Eller <[email protected]>
Commit: Helmut Eller <[email protected]>
Improve indentation of BEGIN-STRUCTURE/END-STRUCTURE
* forth-smie.el (forth-smie--indentation-rules): More
sophisticated/complicated rule for begin-structure.
* test/tests.el (forth-indent-structure): New test.
* forth-syntax.el (forth-syntax--font-lock-keywords): Include
begin-structure/end-structure.
---
forth-smie.el | 15 +++++++++++++--
forth-syntax.el | 3 ++-
test/tests.el | 7 +++++++
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/forth-smie.el b/forth-smie.el
index ea4a634ae5..d242ec8035 100644
--- a/forth-smie.el
+++ b/forth-smie.el
@@ -31,8 +31,19 @@
(defun forth-smie--indentation-rules (kind token)
(pcase (cons kind token)
(`(:elem . basic) forth-smie--basic-indent)
- (`(:elem . args) 0)
- (`(:list-intro . ,_) forth-smie--basic-indent)
+ (`(:elem . args)
+ (cond ((smie-rule-prev-p "begin-structure")
+ (- (+ (save-excursion
+ (forth-smie--backward-token)
+ (current-column))
+ forth-smie--basic-indent)
+ (current-column)))
+ (t 0)))
+ (`(:after . "begin-structure")
+ (* 2 forth-smie--basic-indent))
+ (`(:list-intro . "begin-structure")
+ nil)
+ (`(:list-intro . ,_) t)
(_ nil)))
(defun forth-smie--forward-token ()
diff --git a/forth-syntax.el b/forth-syntax.el
index 11f4156d8e..e2b23aec43 100644
--- a/forth-syntax.el
+++ b/forth-syntax.el
@@ -203,7 +203,8 @@ SYNTAX must be a valid argument for `string-to-syntax'."
"case" "of" "endof" "endcase"
":noname" ";" "does>" "immediate"
"is" "to"
- "literal" "2literal" "fliteral" "sliteral"))
+ "literal" "2literal" "fliteral" "sliteral"
+ "begin-structure" "end-structure"))
(dolist (w forth-syntax--parsing-words)
(forth-syntax--define w #'forth-syntax--state-parsing-word))
diff --git a/test/tests.el b/test/tests.el
index 0b747201e7..cb9331b068 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -265,6 +265,13 @@ The whitespace before and including \"|\" on each line is
removed."
": foo
| (foo) ;"))
+(ert-deftest forth-indent-structure ()
+ (forth-should-indent
+ "BEGIN-STRUCTURE point
+ | 1 CELLS +FIELD p.x
+ | 1 CELLS +FIELD p.y
+ |END-STRUCTURE"))
+
(ert-deftest forth-sexp-movements ()
(forth-assert-forward-sexp " ¹: foo bar ;² \ x")
(forth-assert-forward-sexp " ¹:noname foo bar ;² \ x")