From: Toshi Umehara <toshi@niceume.com>
To: emacs-devel@gnu.org
Cc: monnier@iro.umontreal.ca, Eli Zaretskii <eliz@gnu.org>, jcubic@onet.pl
Subject: [PATCH] Scheme-mode: Add support for regular expression literal
Date: Sat, 23 Mar 2024 11:40:47 +0900 [thread overview]
Message-ID: <87msqpfz68.fsf@niceume.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 975 bytes --]
This patch against 'scheme.el' enables scheme-mode to handle regular
expression literal #/regexp/ that is availabe in some Scheme
implementations such as GNU Kawa [1] and Gauche [2].
Its need was posted by Jakub [3] and init configuration was first
proposed [4]. To allow multiline regular expression literal and to make
the code sophisticated, Stephan has given many advices [5-7]. These
advices are incorporated, and now the code works fine.
Thanks
Reference
[1] https://www.gnu.org/software/kawa/Regular-expressions.html
[2] https://practical-scheme.net/gauche/man/gauche-refe/Regular-expressions.html
[3] https://lists.gnu.org/archive/html/emacs-devel/2024-02/msg00896.html
[4] https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00282.html
[5] https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00397.html
[6] https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00478.html
[7] https://lists.gnu.org/archive/html/emacs-devel/2024-03/msg00538.html
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Enable dealing with scheme regular expression literal --]
[-- Type: text/x-patch, Size: 2979 bytes --]
From dc502360d9310408a8a72bafc2f8fa4fb120f30c Mon Sep 17 00:00:00 2001
From: niceume <toshi@niceume.com>
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
[-- Attachment #3: Type: text/plain, Size: 31 bytes --]
--
Toshi (Toshihiro Umehara)
next reply other threads:[~2024-03-23 2:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-23 2:40 Toshi Umehara [this message]
2024-03-23 14:28 ` [PATCH] Scheme-mode: Add support for regular expression literal Jakub T. Jankiewicz
2024-03-23 20:57 ` Stefan Monnier
2024-03-24 4:33 ` Toshi Umehara
2024-03-28 11:33 ` Jakub T. Jankiewicz
2024-03-28 12:40 ` Toshi Umehara
2024-03-28 23:43 ` Jakub T. Jankiewicz
2024-03-29 6:48 ` Eli Zaretskii
2024-03-29 11:09 ` Jakub T. Jankiewicz
2024-03-29 15:02 ` Toshi Umehara
2024-03-29 15:38 ` Eli Zaretskii
2024-03-30 0:48 ` Toshi Umehara
2024-04-01 6:17 ` Stefan Monnier
2024-03-30 7:59 ` Eli Zaretskii
2024-04-01 5:31 ` Stefan Monnier
2024-04-01 5:24 ` Stefan Monnier
2024-04-02 8:48 ` Toshi Umehara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87msqpfz68.fsf@niceume.com \
--to=toshi@niceume.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=jcubic@onet.pl \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).