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

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

[nongnu] elpa/forth-mode e35317f2f7 093/153: Improve syntax-propertize f


From: ELPA Syncer
Subject: [nongnu] elpa/forth-mode e35317f2f7 093/153: Improve syntax-propertize function
Date: Sat, 29 Jan 2022 08:02:21 -0500 (EST)

branch: elpa/forth-mode
commit e35317f2f7ac053c44786430a2ca139f2a6eb1f5
Author: Helmut Eller <eller.helmut@gmail.com>
Commit: Lars Brinkhoff <lars@nocrew.org>

    Improve syntax-propertize function
    
    In particular handle `[char] "' and `postpone ('.
    
    * forth-syntax.el: Move the syntax related stuff to its own file.
    * test/tests.el: Add more font-lock tests.
    * forth-mode.el (forth-mode-syntax-table): Change the entries
    for \n and { to make the comment handling code in forth-syntax.el
    simpler.
---
 forth-mode.el | 32 +++++---------------------------
 test/tests.el | 37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/forth-mode.el b/forth-mode.el
index dfab314b24..e1c103d0d2 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -13,6 +13,7 @@
 
 (eval-when-compile (byte-compile-disable-warning 'cl-functions))
 (require 'cl)
+(require 'forth-syntax)
 (require 'forth-smie)
 
 (defvar forth-mode-map
@@ -36,12 +37,12 @@
 (defvar forth-mode-syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?\\ "<" table)
-    (modify-syntax-entry ?\n ">" table)
+    (modify-syntax-entry ?\n " " table)
     (modify-syntax-entry ?\( "!" table)
     (modify-syntax-entry ?\) "_" table)
     (modify-syntax-entry ?* "_23n" table)
-    (modify-syntax-entry ?\{ "<" table)
-    (modify-syntax-entry ?\} ">" table)
+    (modify-syntax-entry ?\{ "_" table)
+    (modify-syntax-entry ?\} "_" table)
     (modify-syntax-entry ?\: "(" table)
     (modify-syntax-entry ?\; ")" table)
     (modify-syntax-entry ?\[ "_" table)
@@ -75,29 +76,6 @@
 (defun forth-word-at-point ()
   (buffer-substring (forth-symbol-start) (forth-symbol-end)))
 
-(defun forth--ppss-in-comment-p (pos)
-  (not (null (elt (syntax-ppss pos) 4))))
-
-(defun forth--syntax-propertize (start end)
-  (save-excursion
-    (goto-char start)
-    ;; Fix some cases of comment syntax
-    (while (re-search-forward "(\\|\\\\" end t)
-      (when (and (forth--ppss-in-comment-p (point))
-                (not (forth--ppss-in-comment-p (1- (point)))))
-       (cond ((save-excursion
-                (goto-char (1- (point)))
-                (not (looking-at
-                      "\\([ \n\t]\\|\\\`\\)\\((\\|\\\\\\)[ \n\t]")))
-              (put-text-property (point) (forth-symbol-end)
-                                 'syntax-table (string-to-syntax "_")))
-             ((and (looking-at "(")
-                   (re-search-forward ")" nil t))
-              (put-text-property (1- (point)) (point)
-                                 'syntax-table (string-to-syntax "!")))))
-      (unless (eobp)
-       (forward-char)))))
-
 (defun forth-expand-symbol ()
   (let ((list (forth-words)))
     (when (fboundp 'imenu--make-index-alist)
@@ -145,7 +123,7 @@
   (setq font-lock-defaults '(forth-font-lock-keywords))
   (setq-local completion-at-point-functions '(forth-expand-symbol))
   (when (boundp 'syntax-propertize-function)
-    (setq-local syntax-propertize-function #'forth--syntax-propertize))
+    (setq-local syntax-propertize-function #'forth-syntax-propertize))
   (setq-local parse-sexp-lookup-properties t)
   (forth-smie-setup)
   (setq ;; font-lock-defaults
diff --git a/test/tests.el b/test/tests.el
index 4ef212b9fb..3e67500f41 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -30,18 +30,51 @@
 
 (ert-deftest forth-paren-comment-font-lock ()
   (forth-assert-face "( )" 1 font-lock-comment-delimiter-face)
-  (forth-assert-face ".( )" 1 nil)
+  (forth-assert-face ".( )" 1 font-lock-comment-face)
   (forth-assert-face "( )" 3 font-lock-comment-delimiter-face)
   (forth-assert-face " ( )" 2 font-lock-comment-delimiter-face)
   (forth-assert-face "\t( )" 2 font-lock-comment-delimiter-face)
   (forth-assert-face "(\t)" 1 font-lock-comment-delimiter-face)
   (forth-assert-face "(foo) " 3 nil)
+  (forth-assert-face "(foo)" 3 nil)
+  (forth-assert-face "() " 2 nil)
   (forth-assert-face "( foo) " 3 font-lock-comment-face)
   (forth-assert-face "( a b --
                         x y )" 1 font-lock-comment-delimiter-face))
 
 (ert-deftest forth-backslash-comment-font-lock ()
+  (forth-assert-face "\\" 1 nil)
   (forth-assert-face "\\ " 1 font-lock-comment-delimiter-face)
-  (forth-assert-face " \\ " 2 font-lock-comment-delimiter-face)
+  (forth-assert-face " \\" 2 nil)
   (forth-assert-face "\t\\ " 2 font-lock-comment-delimiter-face)
+  (forth-assert-face " \\\t" 2 font-lock-comment-delimiter-face)
+  (forth-assert-face " \\\n" 2 font-lock-comment-delimiter-face)
+  (forth-assert-face "a\\b" 2 nil)
   (forth-assert-face "a\\b " 2 nil))
+
+(ert-deftest forth-brace-colon-font-lock ()
+  (forth-assert-face "{: :}" 1 font-lock-comment-face)
+  (forth-assert-face "{: :}" 5 font-lock-comment-face)
+  (forth-assert-face "{: a b :}" 4 font-lock-comment-face)
+  (forth-assert-face "{::}" 1 nil)
+  (forth-assert-face "{: a b --
+                         x y :}" 1 font-lock-comment-face)
+  (forth-assert-face "t{ 2 1+ -> 3 }t" 2 nil))
+
+(ert-deftest forth-string-font-lock ()
+  (forth-assert-face "s\" ab\"" 1 nil)
+  (forth-assert-face "s\" ab\"" 2 font-lock-string-face)
+  (forth-assert-face "abort\" ab\"" 6 font-lock-string-face)
+  (forth-assert-face ".\" ab\"" 2 font-lock-string-face)
+  (forth-assert-face "c\" ab\"" 2 font-lock-string-face)
+  (forth-assert-face "[char] \" of" 10 nil)
+  (forth-assert-face "frob\" ab\" " 6 nil)
+  (forth-assert-face "s\\\" ab\"" 1 nil)
+  (forth-assert-face "s\\\" ab\"" 3 font-lock-string-face)
+  (forth-assert-face "s\\\" ab\"" 6 font-lock-string-face)
+  (forth-assert-face "s\\\" a\\\"c\"" 7 font-lock-string-face)
+  (forth-assert-face "s\\\" a\\\"c\" x" 10 nil))
+
+(ert-deftest forth-parsing-words-font-lock ()
+  (forth-assert-face "postpone ( x " 11 nil)
+  (forth-assert-face "' s\" x " 6 nil))



reply via email to

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