From 62bfb2d0982ebe363bd657f203418ad1fe7d8467 Mon Sep 17 00:00:00 2001 From: p4v4n Date: Thu, 7 Sep 2023 13:26:29 +0530 Subject: [PATCH 1/2] Fix clojure-find-ns fir `` (#661) Closes https://github.com/clojure-emacs/clojure-mode/issues/593 --- CHANGELOG.md | 4 ++++ clojure-mode.el | 6 +++--- test/clojure-mode-util-test.el | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27aed4f3..6a4b3eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Improve support for multiple forms in the same line by replacing `beginning-of-defun` fn. +### Bugs fixed + +* [#593](https://github.com/clojure-emacs/clojure-mode/issues/593): Fix clojure-find-ns when ns form is preceded by whitespace or inside comment form. + ## 5.16.2 (2023-08-23) ### Changes diff --git a/clojure-mode.el b/clojure-mode.el index 0d2b613e..43030a1d 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -2125,7 +2125,7 @@ content) are considered part of the preceding sexp." (make-obsolete-variable 'clojure-namespace-name-regex 'clojure-namespace-regexp "5.12.0") (defconst clojure-namespace-regexp - (rx line-start "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end)) + (rx line-start (zero-or-more whitespace) "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end)) (defcustom clojure-cache-ns nil "Whether to cache the results of `clojure-find-ns'. @@ -2153,7 +2153,7 @@ DIRECTION is `forward' or `backward'." (save-match-data (goto-char end) (clojure-forward-logical-sexp) - (unless (or (clojure--in-string-p) (clojure--in-comment-p)) + (unless (or (clojure--in-string-p) (clojure--in-comment-p) (clojure-top-level-form-p "comment")) (setq candidate (string-remove-prefix "'" (thing-at-point 'symbol)))))))) candidate)) @@ -3224,7 +3224,7 @@ With universal argument \\[universal-argument], act on the \"top-level\" form." (beginning-of-defun-raw) (clojure--toggle-ignore-next-sexp))) - + ;;; ClojureScript (defconst clojurescript-font-lock-keywords (eval-when-compile diff --git a/test/clojure-mode-util-test.el b/test/clojure-mode-util-test.el index a35babbe..3f6e2de7 100644 --- a/test/clojure-mode-util-test.el +++ b/test/clojure-mode-util-test.el @@ -82,6 +82,23 @@ (expect (clojure-find-ns) :to-equal "foo")) (with-clojure-buffer "(ns ^:bar ^:baz foo)" (expect (clojure-find-ns) :to-equal "foo"))) + (it "should find namespaces with spaces before ns form" + (with-clojure-buffer " (ns foo)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should skip namespaces within any comment forms" + (with-clojure-buffer "(comment + (ns foo))" + (expect (clojure-find-ns) :to-equal nil)) + (with-clojure-buffer " (ns foo) + (comment + (ns bar))" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer " (comment + (ns foo)) + (ns bar) + (comment + (ns baz))" + (expect (clojure-find-ns) :to-equal "bar"))) (it "should find namespace declarations with nested metadata and docstrings" (with-clojure-buffer "(ns ^{:bar true} foo)" (expect (clojure-find-ns) :to-equal "foo")) From a35491b3e290360b56fe5ccc41a8111ef9d0097c Mon Sep 17 00:00:00 2001 From: vemv Date: Thu, 7 Sep 2023 09:56:33 +0200 Subject: [PATCH 2/2] Revert "Fix clojure-find-ns fir `` (#661)" This reverts commit 62bfb2d0982ebe363bd657f203418ad1fe7d8467. --- CHANGELOG.md | 4 ---- clojure-mode.el | 6 +++--- test/clojure-mode-util-test.el | 17 ----------------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4b3eb7..27aed4f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,6 @@ * Improve support for multiple forms in the same line by replacing `beginning-of-defun` fn. -### Bugs fixed - -* [#593](https://github.com/clojure-emacs/clojure-mode/issues/593): Fix clojure-find-ns when ns form is preceded by whitespace or inside comment form. - ## 5.16.2 (2023-08-23) ### Changes diff --git a/clojure-mode.el b/clojure-mode.el index 43030a1d..0d2b613e 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -2125,7 +2125,7 @@ content) are considered part of the preceding sexp." (make-obsolete-variable 'clojure-namespace-name-regex 'clojure-namespace-regexp "5.12.0") (defconst clojure-namespace-regexp - (rx line-start (zero-or-more whitespace) "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end)) + (rx line-start "(" (? "clojure.core/") (or "in-ns" "ns" "ns+") symbol-end)) (defcustom clojure-cache-ns nil "Whether to cache the results of `clojure-find-ns'. @@ -2153,7 +2153,7 @@ DIRECTION is `forward' or `backward'." (save-match-data (goto-char end) (clojure-forward-logical-sexp) - (unless (or (clojure--in-string-p) (clojure--in-comment-p) (clojure-top-level-form-p "comment")) + (unless (or (clojure--in-string-p) (clojure--in-comment-p)) (setq candidate (string-remove-prefix "'" (thing-at-point 'symbol)))))))) candidate)) @@ -3224,7 +3224,7 @@ With universal argument \\[universal-argument], act on the \"top-level\" form." (beginning-of-defun-raw) (clojure--toggle-ignore-next-sexp))) - + ;;; ClojureScript (defconst clojurescript-font-lock-keywords (eval-when-compile diff --git a/test/clojure-mode-util-test.el b/test/clojure-mode-util-test.el index 3f6e2de7..a35babbe 100644 --- a/test/clojure-mode-util-test.el +++ b/test/clojure-mode-util-test.el @@ -82,23 +82,6 @@ (expect (clojure-find-ns) :to-equal "foo")) (with-clojure-buffer "(ns ^:bar ^:baz foo)" (expect (clojure-find-ns) :to-equal "foo"))) - (it "should find namespaces with spaces before ns form" - (with-clojure-buffer " (ns foo)" - (expect (clojure-find-ns) :to-equal "foo"))) - (it "should skip namespaces within any comment forms" - (with-clojure-buffer "(comment - (ns foo))" - (expect (clojure-find-ns) :to-equal nil)) - (with-clojure-buffer " (ns foo) - (comment - (ns bar))" - (expect (clojure-find-ns) :to-equal "foo")) - (with-clojure-buffer " (comment - (ns foo)) - (ns bar) - (comment - (ns baz))" - (expect (clojure-find-ns) :to-equal "bar"))) (it "should find namespace declarations with nested metadata and docstrings" (with-clojure-buffer "(ns ^{:bar true} foo)" (expect (clojure-find-ns) :to-equal "foo")) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy