[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 02c2a95a52e 1/2: scheme.el: Enable dealing with regular expressio
From: |
Stefan Monnier |
Subject: |
master 02c2a95a52e 1/2: scheme.el: Enable dealing with regular expression literal |
Date: |
Mon, 1 Apr 2024 01:23:53 -0400 (EDT) |
branch: master
commit 02c2a95a52e53486d034de4cd2831b258a49f9c4
Author: niceume <toshi@niceume.com>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
scheme.el: Enable dealing with regular expression literal
* lisp/progmodes/scheme.el (scheme-syntax-propertize-regexp): New function.
(scheme-syntax-propertize): Use it.
---
etc/NEWS | 5 +++++
lisp/progmodes/scheme.el | 27 ++++++++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 775c8e02a95..1b86a968c5d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1218,6 +1218,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
+++
diff --git a/lisp/progmodes/scheme.el b/lisp/progmodes/scheme.el
index 67abab6913d..dc46f0fbbb8 100644
--- a/lisp/progmodes/scheme.el
+++ b/lisp/progmodes/scheme.el
@@ -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.