From: niceume Date: Sun, 17 Mar 2024 00:12:32 +0000 (+0900) Subject: scheme.el: Enable dealing with regular expression literal X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4aa965d2bfdfe7d403e79b75741c785781d96929;p=emacs.git scheme.el: Enable dealing with regular expression literal * lisp/progmodes/scheme.el (scheme-syntax-propertize-regexp): New function. (scheme-syntax-propertize): Use it. (cherry picked from commit 02c2a95a52e53486d034de4cd2831b258a49f9c4) --- diff --git a/etc/NEWS b/etc/NEWS index d168c63894b..e86471a2969 100644 --- 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 +++ 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.