emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/forth-mode 312f3860aa 124/153: Try to indent (foo)


From: ELPA Syncer
Subject: [nongnu] elpa/forth-mode 312f3860aa 124/153: Try to indent (foo)
Date: Sat, 29 Jan 2022 08:02:25 -0500 (EST)

branch: elpa/forth-mode
commit 312f3860aa84793bec30b3f5410b786ad3b45f2a
Author: Helmut Eller <eller.helmut@gmail.com>
Commit: Helmut Eller <eller.helmut@gmail.com>

    Try to indent (foo)
    
    This is a tricky case because SMIE thinks, depending on
    `comment-start-skip` (which indirectly depends on `comment-start`
    thru `comment-normalize-vars`), that (foo) is a comment.  But since
    (foo) is not actually a comment this leads to an endless recursion.
    
    * forth-mode.el (comment-start-skip, comment-start): Choose them
    so that SMIE doesn't run into the endless recursion. (Quite brittle.)
    
    * test/tests.el (forth-indent-\(foo\)): New test.
    (forth-backslash-comment-font-lock, forth-comment-dwim): Adjust for
    new values of comment-start-skip.
    
    * forth-smiel.el (forth-smie--indentation-rules): For clarity, make
    default case explicit.
---
 forth-mode.el |  6 +++---
 forth-smie.el |  3 ++-
 test/tests.el | 17 +++++++++++++----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/forth-mode.el b/forth-mode.el
index 0799f96b79..9b014c54e1 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -146,9 +146,9 @@
   (forth-smie-setup)
   (setq-local fill-paragraph-function #'forth-fill-paragraph)
   (setq-local beginning-of-defun-function #'forth-beginning-of-defun)
-  (setq-local comment-start-skip "\\(?:([*]?\\|\\\\\\) *")
-  (setq-local comment-start "(")
-  (setq-local comment-end ")")
+  (setq-local comment-start-skip "[(\\][ \t*]+")
+  (setq-local comment-start "( ")
+  (setq-local comment-end " )")
   (setq-local comment-region-function #'forth-comment-region)
   (setq imenu-generic-expression
        '(("Words"
diff --git a/forth-smie.el b/forth-smie.el
index aa6b64a382..ea4a634ae5 100644
--- a/forth-smie.el
+++ b/forth-smie.el
@@ -32,7 +32,8 @@
   (pcase (cons kind token)
     (`(:elem . basic) forth-smie--basic-indent)
     (`(:elem . args) 0)
-    (`(:list-intro . ,_) forth-smie--basic-indent)))
+    (`(:list-intro . ,_) forth-smie--basic-indent)
+    (_ nil)))
 
 (defun forth-smie--forward-token ()
   (forward-comment (point-max))
diff --git a/test/tests.el b/test/tests.el
index db6b49638e..b954667bcd 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -114,12 +114,12 @@ The whitespace before and including \"|\" on each line is 
removed."
                         →x y )" font-lock-comment-face))
 
 (ert-deftest forth-backslash-comment-font-lock ()
-  (forth-assert-face "→\\" font-lock-comment-delimiter-face)
+  (forth-assert-face "→\\" font-lock-comment-face)
   (forth-assert-face "→\\ " font-lock-comment-delimiter-face)
-  (forth-assert-face " →\\" font-lock-comment-delimiter-face)
+  (forth-assert-face " →\\" font-lock-comment-face)
   (forth-assert-face "\t→\\ " font-lock-comment-delimiter-face)
   (forth-assert-face " →\\\t" font-lock-comment-delimiter-face)
-  (forth-assert-face " →\\\n" font-lock-comment-delimiter-face)
+  (forth-assert-face " →\\\n" font-lock-comment-face)
   (forth-assert-face "a→\\b" nil)
   (forth-assert-face "a→\\b " nil))
 
@@ -242,6 +242,15 @@ The whitespace before and including \"|\" on each line is 
removed."
    |  drop exit
    |endcase"))
 
+;; This is an tricky case because SMIE thinks, depending on
+;; `comment-start-skip` (which indirectly depends on `comment-start`
+;; thru `comment-normalize-vars`), that (foo) is a comment.  But since
+;; (foo) is not actually a comment this leads to an endless recursion.
+(ert-deftest forth-indent-\(foo\) ()
+  (forth-should-indent
+   ": foo
+   |  (foo) ;"))
+
 (ert-deftest forth-sexp-movements ()
   (forth-assert-forward-sexp " ¹: foo bar ;² \ x")
   (forth-assert-forward-sexp " ¹:noname foo bar ;² \ x")
@@ -288,7 +297,7 @@ The whitespace before and including \"|\" on each line is 
removed."
    |  again ;"
    ": frob
    |  begin     ( x y )
-   |    swap    (→)
+   |    swap    ( → )
    |  again ;"
    (lambda ()
      (call-interactively #'comment-dwim)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]