all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Scheme-mode: Add support for regular expression literal
@ 2024-03-23  2:40 Toshi Umehara
  2024-03-23 14:28 ` Jakub T. Jankiewicz
  2024-03-23 20:57 ` Stefan Monnier
  0 siblings, 2 replies; 17+ messages in thread
From: Toshi Umehara @ 2024-03-23  2:40 UTC (permalink / raw)
  To: emacs-devel; +Cc: monnier, Eli Zaretskii, jcubic

[-- 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)

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-04-02  8:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-23  2:40 [PATCH] Scheme-mode: Add support for regular expression literal Toshi Umehara
2024-03-23 14:28 ` 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.