[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/forth-mode 16f359442e 109/153: Add tests for word movement
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/forth-mode 16f359442e 109/153: Add tests for word movement commands |
Date: |
Sat, 29 Jan 2022 08:02:23 -0500 (EST) |
branch: elpa/forth-mode
commit 16f359442e24bb9f71b9dbed0eae267e2574992c
Author: Helmut Eller <eller.helmut@gmail.com>
Commit: Helmut Eller <eller.helmut@gmail.com>
Add tests for word movement commands
* test/tests.el (forth-word-movements): New test.
(forth-assert-forward-word): New helper.
* forth-syntax.el (forth-syntax--state-normal): Use "word constituent"
("w") instead of "symbol constituent" ("_"), so that word movements
works better.
(forth-syntax--set-syntax): New helper.
---
forth-syntax.el | 42 +++++++++++++++++++-----------------------
test/tests.el | 15 +++++++++++++++
2 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/forth-syntax.el b/forth-syntax.el
index 8f3bd27a0d..39133fd6d5 100644
--- a/forth-syntax.el
+++ b/forth-syntax.el
@@ -22,6 +22,10 @@
(cond ((= start (point)) nil)
(t (buffer-substring-no-properties start (point)))))))
+(defmacro forth-syntax--set-syntax (start end syntax)
+ "Set the 'syntax-table property in the region START/END to SYNTAX.
+SYNTAX must be a valid argument for `string-to-syntax'."
+ `(put-text-property ,start ,end 'syntax-table ',(string-to-syntax syntax)))
;;; State functions
@@ -39,35 +43,31 @@
;; One line strings
(defun forth-syntax--state-string ()
(re-search-backward "\"\\=")
- (put-text-property (point) (1+ (point))
- 'syntax-table (string-to-syntax "\""))
+ (forth-syntax--set-syntax (point) (1+ (point)) "\"")
(forward-char)
(cond ((re-search-forward "[\"\n]" nil t)
- (put-text-property (1- (point)) (point)
- 'syntax-table (string-to-syntax "\""))
+ (forth-syntax--set-syntax (1- (point)) (point) "\"")
#'forth-syntax--state-normal)
(t
(goto-char (point-max))
- #'forth-syntax--state-normal)))
+ #'forth-syntax--state-eob)))
(defun forth-syntax--state-s\\\" ()
(re-search-backward "\"\\=")
- (put-text-property (point) (1+ (point))
- 'syntax-table (string-to-syntax "\""))
+ (forth-syntax--set-syntax (point) (1+ (point)) "\"")
(forward-char)
(while (and (re-search-forward "\\([\"\n]\\|\\\\\"\\)" nil t)
(cond ((= (char-after (match-beginning 0)) ?\\)
- (put-text-property (match-beginning 0)
- (1+ (match-beginning 0))
- 'syntax-table (string-to-syntax "\\"))
+ (forth-syntax--set-syntax (match-beginning 0)
+ (1+ (match-beginning 0))
+ "\\")
t))))
(cond ((looking-back "[\"\n]" 1)
- (put-text-property (1- (point)) (point)
- 'syntax-table (string-to-syntax "\""))
+ (forth-syntax--set-syntax (1- (point)) (point) "\"")
#'forth-syntax--state-normal)
(t
(goto-char (point-max))
- #'forth-syntax--state-normal)))
+ #'forth-syntax--state-eob)))
;; State for words that parse the following word, e.g. POSTPONE S"
;; where POSTPONE parses S".
@@ -77,23 +77,20 @@
(skip-chars-forward forth-syntax--non-whitespace)
(cond ((= start (point)) #'forth-syntax--state-eob)
(t
- (put-text-property start (point)
- 'syntax-table (string-to-syntax "_"))
+ (forth-syntax--set-syntax start (point) "w")
#'forth-syntax--state-normal))))
(defun forth-syntax--parse-comment (backward-regexp forward-regexp)
(let ((pos (point)))
(re-search-backward backward-regexp)
- (put-text-property (point) (1+ (point))
- 'syntax-table (string-to-syntax "<"))
+ (forth-syntax--set-syntax (point) (1+ (point)) "<")
(goto-char pos)
(cond ((re-search-forward forward-regexp nil t)
- (put-text-property (1- (point)) (point)
- 'syntax-table (string-to-syntax ">"))
+ (forth-syntax--set-syntax (1- (point)) (point) ">")
#'forth-syntax--state-normal)
(t
(goto-char (point-max))
- #'forth-syntax--state-normal))))
+ #'forth-syntax--state-eob))))
;; Define a state-function for comments. The comment starts with
;; the string BEGIN and ends with the string END.
@@ -138,7 +135,7 @@
(gethash (downcase word) forth-syntax--parsers))
;; Look for the next whitespace delimited word; mark all its
-;; characters as "symbol constituents"; finally return state-function
+;; characters as "word constituents"; finally return state-function
;; for the word.
(defun forth-syntax--state-normal ()
(skip-chars-forward forth-syntax--whitespace)
@@ -146,8 +143,7 @@
(skip-chars-forward forth-syntax--non-whitespace)
(cond ((= start (point)) #'forth-syntax--state-eob)
(t
- (put-text-property start (point)
- 'syntax-table (string-to-syntax "_"))
+ (forth-syntax--set-syntax start (point) "w")
(let ((word (buffer-substring-no-properties start (point))))
(cond ((forth-syntax--lookup word))
(t
diff --git a/test/tests.el b/test/tests.el
index 1681a10389..2125eb33fe 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -56,6 +56,12 @@ The whitespace before and including \"|\" on each line is
removed."
(forward-sexp)
(should (= (point) end))))
+(defun forth-assert-forward-word (content start end)
+ (forth-with-temp-buffer content
+ (goto-char start)
+ (forward-word)
+ (should (= (point) end))))
+
(ert-deftest forth-paren-comment-font-lock ()
(forth-assert-face "( )" 1 font-lock-comment-delimiter-face)
(forth-assert-face ".( )" 1 font-lock-comment-face)
@@ -181,3 +187,12 @@ The whitespace before and including \"|\" on each line is
removed."
(forth-assert-forward-sexp " : foo bar ; \ x" 2 13)
(forth-assert-forward-sexp " :noname foo bar ; \ x" 2 19)
(forth-assert-forward-sexp " if drop exit else 1+ then bar " 2 27))
+
+;; IDEA 1: in words like foo-bar give the "-" a "word constituent"
+;; syntax so that word movement works like in Lisp mode (which
+;; everybody is used to :-).
+;;
+;; IDEA 2: give the filename in "include filename" string syntax.
+(ert-deftest forth-word-movements ()
+ (forth-assert-forward-word "include /tmp/foo.fth \ bar" 1 8)
+ (forth-assert-forward-word "include /tmp/foo.fth \ bar" 8 21))
- [nongnu] elpa/forth-mode 45f3f20f18 104/153: Make indentation case-insensitive, (continued)
- [nongnu] elpa/forth-mode 45f3f20f18 104/153: Make indentation case-insensitive, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b8024ac331 088/153: Loading a Forth file provides some feedback., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 9eb3550cdc 045/153: Add imenu items to autocomplete candidates., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 350638bb0c 106/153: Make indentation case-insensitive, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 039bf122ee 067/153: Document key bindings in the manual., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 1a05d27d82 077/153: Fix loading backend file., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b95f1b8a02 146/153: Fix typos in doc, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 2e75fb156f 081/153: Fix warning about defvar ignored., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 96c20f03f5 128/153: Make completion-at-point test work with Emacs23, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 867922d61e 112/153: Handle string literals more correctly, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 16f359442e 109/153: Add tests for word movement commands,
ELPA Syncer <=
- [nongnu] elpa/forth-mode 45650c28a2 140/153: Check if forth interactive buffer is live, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode ab790fdac8 091/153: Don't kill *forth* buffer when there's a fatal error., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode be0272be3a 076/153: Inhibut Gforth terminal attribute output., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 312f3860aa 124/153: Try to indent (foo), ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 952995d95e 098/153: Add tests for indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 0bbf7992d6 135/153: Workaround pcase bug in Emacs-24.3, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode ee0781f0a8 066/153: Add more functions for evaluating Forth expressions., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 1ffc174c13 127/153: Pass Makefile variable FORTH as environment variable to build.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 9b0982e169 149/153: Fix CI, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 52d84393c0 141/153: Remove newlines to fix markdown formatting., ELPA Syncer, 2022/01/29