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

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

[nongnu] elpa/forth-mode e6ee5ddf99 069/153: Handle ( ...) comments with


From: ELPA Syncer
Subject: [nongnu] elpa/forth-mode e6ee5ddf99 069/153: Handle ( ...) comments with syntax-propertize-function
Date: Sat, 29 Jan 2022 08:02:17 -0500 (EST)

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

    Handle ( ...) comments with syntax-propertize-function
---
 forth-mode.el | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/forth-mode.el b/forth-mode.el
index 2d618670da..190ea925fd 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -35,8 +35,8 @@
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?\\ "<" table)
     (modify-syntax-entry ?\n ">" table)
-    (modify-syntax-entry ?\( "<1" table)
-    (modify-syntax-entry ?\) ">4" table)
+    (modify-syntax-entry ?\( "!" table)
+    (modify-syntax-entry ?\) "_" table)
     (modify-syntax-entry ?* "_23n" table)
     (modify-syntax-entry ?\{ "<" table)
     (modify-syntax-entry ?\} ">" table)
@@ -73,6 +73,27 @@
 (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]\\|\\\`\\)\\((\\|\\\\\\)[ \n]")))
+              (put-text-property (point) (forth-symbol-end)
+                                 'syntax-table (string-to-syntax "_")))
+             ((and (looking-at "(")
+                   (re-search-forward ")" nil t))
+              (put-text-property (point) (1+ (point))
+                                 'syntax-table (string-to-syntax "!")))))
+      (forward-char))))
+
 (defun forth-expand-symbol ()
   (let ((list (forth-words)))
     (when (fboundp 'imenu--make-index-alist)
@@ -119,6 +140,8 @@
       (forth-block-mode))
   (setq font-lock-defaults '(forth-font-lock-keywords))
   (setq-local completion-at-point-functions '(forth-expand-symbol))
+  (setq-local syntax-propertize-function #'forth--syntax-propertize)
+  (setq-local parse-sexp-lookup-properties t)
   (setq ;; font-lock-defaults
        comment-start-skip "\\((\\*?\\|\\\\\\) *"
        comment-start "("



reply via email to

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