]> git.eshelyaron.com Git - emacs.git/commitdiff
scheme.el: Enable dealing with regular expression literal
authorniceume <toshi@niceume.com>
Sun, 17 Mar 2024 00:12:32 +0000 (09:12 +0900)
committerEshel Yaron <me@eshelyaron.com>
Tue, 2 Apr 2024 13:22:27 +0000 (15:22 +0200)
* lisp/progmodes/scheme.el (scheme-syntax-propertize-regexp): New function.
(scheme-syntax-propertize): Use it.

(cherry picked from commit 02c2a95a52e53486d034de4cd2831b258a49f9c4)

etc/NEWS
lisp/progmodes/scheme.el

index d168c63894b81f292951a202e649f158b6b200b1..e86471a2969c2df9b0c57efcb680d93b6d039135 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1316,6 +1316,11 @@ instead of:
 This allows the user to specify command line arguments to the non
 interactive Python interpreter specified by 'python-interpreter'.
 
+** Scheme mode
+
+Scheme mode now handles regular expression literal #/regexp/ that is
+available in some Scheme implementations.
+
 ** use-package
 
 +++
index 67abab6913d914b9619e0e25a6dda446dd363317..dc46f0fbbb8876c11de03c61aa5ff518d5ef95fc 100644 (file)
@@ -410,10 +410,19 @@ See `run-hooks'."
 (defun scheme-syntax-propertize (beg end)
   (goto-char beg)
   (scheme-syntax-propertize-sexp-comment (point) end)
+  (scheme-syntax-propertize-regexp end)
   (funcall
    (syntax-propertize-rules
     ("\\(#\\);" (1 (prog1 "< cn"
-                     (scheme-syntax-propertize-sexp-comment (point) end)))))
+                     (scheme-syntax-propertize-sexp-comment (point) end))))
+    ("\\(#\\)/" (1 (when (null (nth 8 (save-excursion
+                                        (syntax-ppss (match-beginning 0)))))
+                     (put-text-property
+                      (match-beginning 1)
+                      (match-end 1)
+                      'syntax-table (string-to-syntax "|"))
+                     (scheme-syntax-propertize-regexp end)
+                     nil))))
    (point) end))
 
 (defun scheme-syntax-propertize-sexp-comment (_ end)
@@ -430,6 +439,22 @@ See `run-hooks'."
                                'syntax-table (string-to-syntax "> cn")))
         (scan-error (goto-char end))))))
 
+(defun scheme-syntax-propertize-regexp (end)
+  (let* ((state (syntax-ppss))
+         (within-str (nth 3 state))
+         (start-delim-pos (nth 8 state)))
+    (when (and within-str
+               (char-equal ?# (char-after start-delim-pos)))
+      (while (and (re-search-forward "/" end 'move)
+                  (eq -1
+                      (% (save-excursion
+                           (backward-char)
+                           (skip-chars-backward "\\\\"))
+                         2))))
+      (when (< (point) end)
+       (put-text-property (match-beginning 0) (match-end 0)
+                          'syntax-table (string-to-syntax "|"))))))
+
 ;;;###autoload
 (define-derived-mode dsssl-mode scheme-mode "DSSSL"
   "Major mode for editing DSSSL code.