From dc502360d9310408a8a72bafc2f8fa4fb120f30c Mon Sep 17 00:00:00 2001 From: niceume Date: Sun, 17 Mar 2024 09:12:32 +0900 Subject: [PATCH] Scheme-mode update for regular expression literal --- etc/NEWS | 6 ++++++ lisp/progmodes/scheme.el | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index f4b4c30855c..d2c258bc6d8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1188,6 +1188,12 @@ 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..d3fb40ea471 100644 --- a/lisp/progmodes/scheme.el +++ b/lisp/progmodes/scheme.el @@ -410,10 +410,22 @@ scheme-sexp-comment-syntax-table (defun scheme-syntax-propertize (beg end) (goto-char beg) (scheme-syntax-propertize-sexp-comment (point) end) + (scheme-syntax-propertize-regexp (point) 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 0) + (1+ (match-beginning 0)) + 'syntax-table (string-to-syntax "|")) + (scheme-syntax-propertize-regexp + (point) end) + nil) + ))) (point) end)) (defun scheme-syntax-propertize-sexp-comment (_ end) @@ -430,6 +442,29 @@ scheme-syntax-propertize-sexp-comment '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 t) + (eq -1 + (% (save-excursion + (backward-char) + (skip-chars-backward "\\\\")) 2)))) + (when (< (point) end) + (progn + (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. -- 2.44.0