From d2d8cfef8de442f095235f75b555e063dc5d6d85 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 16 May 2024 04:14:25 +0800 Subject: [PATCH 1/2] Fix syntax-table class of carriage returns The syntax table interprets ASCII control chars (including CRs) as symbols in clojure buffers, affecting functions such as (thing-at-point 'symbol) This caused clojure-find-ns to report "^M" as the namespace in some files with \r\n line encodings. --- clojure-mode.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clojure-mode.el b/clojure-mode.el index 7031c625..c5b9e801 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -373,7 +373,8 @@ The prefixes are used to generate the correct namespace." (defvar clojure-mode-syntax-table (let ((table (make-syntax-table))) ;; Initialize ASCII charset as symbol syntax - (modify-syntax-entry '(0 . 127) "_" table) + ;; Control characters from 0-31 default to the punctuation syntax class + (modify-syntax-entry '(32 . 127) "_" table) ;; Word syntax (modify-syntax-entry '(?0 . ?9) "w" table) @@ -385,6 +386,7 @@ The prefixes are used to generate the correct namespace." (modify-syntax-entry ?\xa0 " " table) ; non-breaking space (modify-syntax-entry ?\t " " table) (modify-syntax-entry ?\f " " table) + (modify-syntax-entry ?\r " " table) ;; Setting commas as whitespace makes functions like `delete-trailing-whitespace' behave unexpectedly (#561) (modify-syntax-entry ?, "." table) From 437e9b64c07d9753282595b9c1a95d5efd745ca3 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 16 May 2024 04:42:17 +0800 Subject: [PATCH 2/2] Add tests and changelog --- CHANGELOG.md | 1 + test/clojure-mode-util-test.el | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c7e65e..386bc1d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fix `clojure-align` when called from `clojure-ts-mode` major mode buffers. * [#671](https://github.com/clojure-emacs/clojure-mode/issues/671): Syntax highlighting for digits after the first in `%` args. (e.g. `%10`) +- [#680](https://github.com/clojure-emacs/clojure-mode/issues/680): Change syntax class of ASCII control characters to punctuation, fixing situations where carriage returns were being interpreted as symbols # Changes diff --git a/test/clojure-mode-util-test.el b/test/clojure-mode-util-test.el index 6157a3d0..78a2ac17 100644 --- a/test/clojure-mode-util-test.el +++ b/test/clojure-mode-util-test.el @@ -163,6 +163,11 @@ (with-clojure-buffer "(ns)(ns foo)" (expect (clojure-find-ns) :to-equal "foo")) (with-clojure-buffer "(ns )(ns foo)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should ignore carriage returns" + (with-clojure-buffer "(ns \r\n foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns\r\n ^{:doc \"meta\r\n\"}\r\n foo\r\n)" (expect (clojure-find-ns) :to-equal "foo")))) (describe "clojure-sort-ns"