[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))
- [nongnu] elpa/forth-mode d1498037a2 107/153: Add simple tests for forward-sexp, (continued)
- [nongnu] elpa/forth-mode d1498037a2 107/153: Add simple tests for forward-sexp, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 83a62c82c4 030/153: Move all package metadata to forth-mode.el., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 186bae4853 083/153: Fix set-process-window-size parameter order., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 48bcf41d63 058/153: Cache words from interactive Forth., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode f418b9aac2 087/153: Set process coding system for SwiftForth., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode f3d76c12c1 125/153: Test completion-at-point, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 4dc1ff0f3b 086/153: Include backend files in make dependencies., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 2779ca61ab 075/153: Improve building of backend files., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 71016700dc 095/153: Emacs 23: use cl library instead of cl-lib., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 715d813c83 062/153: Clean up tests., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode e35317f2f7 093/153: Improve syntax-propertize function,
ELPA Syncer <=
- [nongnu] elpa/forth-mode 76e3885c0b 150/153: Remove obsolete Wercker CI build., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 443193e02f 071/153: Auto-detect Forth implementation., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode a7a5d4ba05 137/153: Use defcustom to define forth-smie-basic-indent, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 522256d98d 145/153: Adding support for ?of, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 08d891c907 026/153: Use LOCAL argument to add-hook., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 82f746ba54 049/153: Use ERT for some light testing as part of build., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode ad5ce072ca 006/153: GPL3, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 6f18e1c20e 011/153: Tweak syntax table., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 6efdba0686 029/153: Remove dependency from forth-mode to forth-block-mode., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b69527cdd2 084/153: SwiftForth shouldn't concern itself with terminal settings., ELPA Syncer, 2022/01/29