branch: elpa/forth-mode
commit 5502816e37c543f1771404e243575a02d25dd60a
Author: Helmut Eller <[email protected]>
Commit: Helmut Eller <[email protected]>
Make it easier to emulate Open Firmware indentation style
By setting forth-smie-basic-indent to 3, indentation should look more
like what Mitch Bradley uses in Open Firmware.
* forht-smie.el (forth-smie-basic-indent): Rename from
forth-smie--basic-indent.
(forth-smie--indentation-rules): Indent colon definitions like
begin-structure.
* test/tests.el (forth-indent-colon-definition): Add test for
forth-smie-basic-indent = 3.
---
forth-smie.el | 20 ++++++++++----------
test/tests.el | 8 +++++++-
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/forth-smie.el b/forth-smie.el
index d242ec8035..f008c30f48 100644
--- a/forth-smie.el
+++ b/forth-smie.el
@@ -22,28 +22,28 @@
(":noname" words ";"))
(words)))))
-(defvar forth-smie--basic-indent 2)
+(defvar forth-smie-basic-indent 2)
(unless (fboundp 'pcase)
(defmacro pcase (form &rest forms)
0))
(defun forth-smie--indentation-rules (kind token)
- (pcase (cons kind token)
- (`(:elem . basic) forth-smie--basic-indent)
- (`(:elem . args)
- (cond ((smie-rule-prev-p "begin-structure")
+ (pcase (list kind token)
+ (`(:elem basic) 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)
+ forth-smie-basic-indent)
(current-column)))
(t 0)))
- (`(:after . "begin-structure")
- (* 2 forth-smie--basic-indent))
- (`(:list-intro . "begin-structure")
+ (`(:after ,(or ":" "begin-structure"))
+ (* 2 forth-smie-basic-indent))
+ (`(:list-intro ,(or ":" "begin-structure"))
nil)
- (`(:list-intro . ,_) t)
+ (`(:list-intro ,_) t)
(_ nil)))
(defun forth-smie--forward-token ()
diff --git a/test/tests.el b/test/tests.el
index cb9331b068..893731650f 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -188,7 +188,13 @@ The whitespace before and including \"|\" on each line is
removed."
(forth-should-indent
": foo ( x y -- y x )
| swap
- |;"))
+ |;")
+ ;; Open Firmware style
+ (let ((forth-smie-basic-indent 3))
+ (forth-should-indent
+ ": foo ( x y -- y x )
+ | swap
+ |;")))
(ert-deftest forth-indent-if-then-else ()
(forth-should-indent