public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: "Scott L. Burson via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Johannes Sixt" <j6t@kdbg.org>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Jaydeep P Das" <jaydeepjd.8914@gmail.com>,
	"D. Ben Knoble" <ben.knoble@gmail.com>,
	"Scott L. Burson" <Scott@sympoiesis.com>,
	"Scott L. Burson" <Scott@sympoiesis.com>
Subject: [PATCH v3 2/2] userdiff: extend Scheme support to cover other Lisp dialects
Date: Thu, 15 Jan 2026 23:18:40 +0000	[thread overview]
Message-ID: <fb4c8dc5d4434deab9c8f1872f309a79351dc799.1768519120.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2000.v3.git.1768519120.gitgitgadget@gmail.com>

From: "Scott L. Burson" <Scott@sympoiesis.com>

Common Lisp has top-level forms, such as 'defun' and 'defmacro', that
are not matched by the current Scheme pattern.  Also, it is more
common in CL, when defining user macros intended as top-level forms,
to prefix their names with "def" instead of "define"; such forms are
also not matched.  And some top-level forms don't even begin with
"def".

On the other hand, it is an established formatting convention in the
Lisp community that only top-level forms start at the left margin.  So
matching any unindented line starting with an open parenthesis is an
acceptable heuristic; false positives will be rare.

However, there are also cases where notionally top-level forms are
grouped together within some containing form.  At least in the Common
Lisp community, it is conventional to indent these by two spaces, or
sometimes one.  But matching just an open parenthesis indented by two
spaces would be too broad; so the pattern added by this commit
requires an indented form to start with "(def".  It is believed that
this strikes a good balance between potential false positives and
false negatives.

Signed-off-by: Scott L. Burson <Scott@sympoiesis.com>
---
 Documentation/gitattributes.adoc           |  1 +
 t/t4018/scheme-lisp-defun-a                |  4 ++++
 t/t4018/scheme-lisp-defun-b                |  4 ++++
 t/t4018/scheme-lisp-eval-when              |  4 ++++
 t/t4018/{scheme-module => scheme-module-a} |  0
 t/t4018/scheme-module-b                    |  6 ++++++
 t/t4034/scheme/expect                      |  2 +-
 t/t4034/scheme/post                        |  2 +-
 t/t4034/scheme/pre                         |  2 +-
 userdiff.c                                 | 22 ++++++++++++++++------
 10 files changed, 38 insertions(+), 9 deletions(-)
 create mode 100644 t/t4018/scheme-lisp-defun-a
 create mode 100644 t/t4018/scheme-lisp-defun-b
 create mode 100644 t/t4018/scheme-lisp-eval-when
 rename t/t4018/{scheme-module => scheme-module-a} (100%)
 create mode 100644 t/t4018/scheme-module-b

diff --git a/Documentation/gitattributes.adoc b/Documentation/gitattributes.adoc
index f20041a323..a9ce5adef9 100644
--- a/Documentation/gitattributes.adoc
+++ b/Documentation/gitattributes.adoc
@@ -912,6 +912,7 @@ patterns are available:
 - `rust` suitable for source code in the Rust language.
 
 - `scheme` suitable for source code in the Scheme language.
+Also handles Emacs Lisp, Common Lisp, and most other dialects.
 
 - `tex` suitable for source code for LaTeX documents.
 
diff --git a/t/t4018/scheme-lisp-defun-a b/t/t4018/scheme-lisp-defun-a
new file mode 100644
index 0000000000..c3c750f76d
--- /dev/null
+++ b/t/t4018/scheme-lisp-defun-a
@@ -0,0 +1,4 @@
+(defun some-func (x y z) RIGHT
+  (let ((a x)
+        (b y))
+        (ChangeMe a b)))
diff --git a/t/t4018/scheme-lisp-defun-b b/t/t4018/scheme-lisp-defun-b
new file mode 100644
index 0000000000..21be305968
--- /dev/null
+++ b/t/t4018/scheme-lisp-defun-b
@@ -0,0 +1,4 @@
+(macrolet ((foo (x) `(bar ,x)))
+  (defun mumble (x) ; RIGHT
+    (when (> x 0)
+      (foo x)))) ; ChangeMe
diff --git a/t/t4018/scheme-lisp-eval-when b/t/t4018/scheme-lisp-eval-when
new file mode 100644
index 0000000000..5d941d7e0e
--- /dev/null
+++ b/t/t4018/scheme-lisp-eval-when
@@ -0,0 +1,4 @@
+(eval-when (:compile-toplevel :load-toplevel :execute)  ; RIGHT
+  (set-macro-character #\?
+		       (lambda (stream char)
+			 `(make-pattern-variable ,(read stream)))))  ; ChangeMe
diff --git a/t/t4018/scheme-module b/t/t4018/scheme-module-a
similarity index 100%
rename from t/t4018/scheme-module
rename to t/t4018/scheme-module-a
diff --git a/t/t4018/scheme-module-b b/t/t4018/scheme-module-b
new file mode 100644
index 0000000000..77bc0c5eff
--- /dev/null
+++ b/t/t4018/scheme-module-b
@@ -0,0 +1,6 @@
+(module A
+  (export with-display-exception)
+  (extern (display-exception display-exception))
+  (def (with-display-exception thunk) RIGHT
+    (with-catch (lambda (e) (display-exception e (current-error-port)) e)
+      thunk ChangeMe)))
diff --git a/t/t4034/scheme/expect b/t/t4034/scheme/expect
index 138abe9f56..72592665f1 100644
--- a/t/t4034/scheme/expect
+++ b/t/t4034/scheme/expect
@@ -6,7 +6,7 @@
 (define (<RED>myfunc a b<RESET><GREEN>my-func first second<RESET>)
   ; This is a <RED>really<RESET><GREEN>(moderately)<RESET> cool function.
   (<RED>this\place<RESET><GREEN>that\place<RESET> (+ 3 4))
-  (define <RED>|the greeting|<RESET><GREEN>|a greeting|<RESET> "hello")
+  (define <RED>|the \greeting|<RESET><GREEN>|a \greeting|<RESET> |hello there|)
   ({<RED>}<RESET>(([<RED>]<RESET>(func-n)<RED>[<RESET>]))<RED>{<RESET>})
   (let ((c (<RED>+ a b<RESET><GREEN>add1 first<RESET>)))
     (format "one more than the total is %d" (<RED>add1<RESET><GREEN>+<RESET> c <GREEN>second<RESET>))))
diff --git a/t/t4034/scheme/post b/t/t4034/scheme/post
index 0e3bab101d..450cc234f7 100644
--- a/t/t4034/scheme/post
+++ b/t/t4034/scheme/post
@@ -1,7 +1,7 @@
 (define (my-func first second)
   ; This is a (moderately) cool function.
   (that\place (+ 3 4))
-  (define |a greeting| "hello")
+  (define |a \greeting| |hello there|)
   ({(([(func-n)]))})
   (let ((c (add1 first)))
     (format "one more than the total is %d" (+ c second))))
diff --git a/t/t4034/scheme/pre b/t/t4034/scheme/pre
index 03d77c7c43..ba8b8ac0a4 100644
--- a/t/t4034/scheme/pre
+++ b/t/t4034/scheme/pre
@@ -1,7 +1,7 @@
 (define (myfunc a b)
   ; This is a really cool function.
   (this\place (+ 3 4))
-  (define |the greeting| "hello")
+  (define |the \greeting| |hello there|)
   ({}(([](func-n)[])){})
   (let ((c (+ a b)))
     (format "one more than the total is %d" (add1 c))))
diff --git a/userdiff.c b/userdiff.c
index fe710a68bf..b5412e6bc3 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -344,14 +344,24 @@ PATTERNS("rust",
 	 "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"
 	 "|[-+*\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\|\\||->|=>|\\.{2}=|\\.{3}|::"),
 PATTERNS("scheme",
-	 "^[\t ]*(\\(((define|def(struct|syntax|class|method|rules|record|proto|alias)?)[-*/ \t]|(library|module|struct|class)[*+ \t]).*)$",
 	 /*
-	  * R7RS valid identifiers include any sequence enclosed
-	  * within vertical lines having no backslashes
+	  * An unindented opening parenthesis identifies a top-level
+	  * expression in all Lisp dialects.
 	  */
-	 "\\|([^\\\\]*)\\|"
-	 /* All other words should be delimited by spaces or parentheses */
-	 "|([^][)(}{[ \t])+"),
+	 "^(\\(.*)$\n"
+	 /* For Scheme: a possibly indented left paren followed by a keyword. */
+	 "^[\t ]*(\\(((define|def(struct|syntax|class|method|rules|record|proto|alias)?)[-*/ \t]|(library|module|struct|class)[*+ \t]).*)$\n"
+	 /*
+	  * For all Lisp dialects: a slightly indented line starting with "(def".
+	  */
+	 "^  ?(\\([Dd][Ee][Ff].*)$",
+	 /*
+	  * The union of R7RS and Common Lisp symbol syntax: allows arbitrary
+	  * strings between vertical bars, including any escaped characters.
+	  */
+	 "\\|([^|\\\\]|\\\\.)*\\|"
+	 /* All other words should be delimited by spaces or parentheses. */
+	 "|([^][)(}{ \t])+"),
 PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
 	 "\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
 { .name = "default", .binary = -1 },
-- 
gitgitgadget

  parent reply	other threads:[~2026-01-15 23:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-15 10:17 [PATCH] diff: "lisp" userdiff_driver Scott L. Burson via GitGitGadget
2025-11-15 17:06 ` Johannes Sixt
2025-11-15 23:32   ` Scott L. Burson
2025-11-20 16:47     ` D. Ben Knoble
2025-11-27  2:10       ` Scott L. Burson
2025-11-16  5:30   ` Junio C Hamano
2025-11-17 23:23     ` Scott L. Burson
2025-11-18  4:38       ` Junio C Hamano
2025-11-27  2:38 ` [PATCH v2 0/2] userdiff: extend Scheme support to cover other Lisp dialects Scott L. Burson via GitGitGadget
2025-11-27  2:38   ` [PATCH v2 1/2] diff: "lisp" userdiff_driver Scott L. Burson via GitGitGadget
2025-11-27 10:32     ` Scott L. Burson
2025-11-27 10:51       ` Johannes Sixt
2025-11-27  2:38   ` [PATCH v2 2/2] merge with Scheme regexp; fix bugs Scott L. Burson via GitGitGadget
2025-11-27 16:09     ` Johannes Sixt
2025-12-02 10:27       ` Johannes Sixt
2026-01-14  6:18         ` Scott L. Burson
2026-01-14  8:40           ` Johannes Sixt
2026-01-15 23:18   ` [PATCH v3 0/2] userdiff: extend Scheme support to cover other Lisp dialects Scott L. Burson via GitGitGadget
2026-01-15 23:18     ` [PATCH v3 1/2] userdiff: tighten word-diff test case of the scheme driver Johannes Sixt via GitGitGadget
2026-01-15 23:18     ` Scott L. Burson via GitGitGadget [this message]
2026-01-16  8:49       ` [PATCH v3 2/2] userdiff: extend Scheme support to cover other Lisp dialects Johannes Sixt
2026-01-17  2:09         ` Scott L. Burson
2026-01-17  8:15           ` Johannes Sixt

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb4c8dc5d4434deab9c8f1872f309a79351dc799.1768519120.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Scott@sympoiesis.com \
    --cc=avarab@gmail.com \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jaydeepjd.8914@gmail.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox