Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cider-ns-form-p produces false positive when the form contains namespace-like string. #3754

Closed
a13 opened this issue Oct 30, 2024 · 3 comments
Labels
bug good first issue A simple tasks suitable for first-time contributors

Comments

@a13
Copy link
Contributor

a13 commented Oct 30, 2024

Hi, while working on https://github.com/scicloj/clay (we have Clojure file parser tests there) I hit a problem, so

I have code like this in a file

(ns wtf)

(def foo
  "
(ns bar)
"
  )

Expected behavior

foo evals to #'wtf/foo

Actual behavior

#'user/foo

Steps to reproduce the problem

put the code above into a file, start repl, eval it in cider

Environment & Version information

CIDER version information

;; CIDER 1.16.0 (Kherson), babashka.nrepl 0.0.6-SNAPSHOT
;; Babashka 1.3.191

Lein / Clojure CLI version

Babashka 1.3.191

Emacs version

29.4

Operating system

Ubuntu 22.04

JDK distribution

Babashka 1.3.191

The problems is the regex used in cider-ns-form-p - "^[[:space:]]*\(ns\\([[:space:]]*$\\|[[:space:]]+\\)" treats namespace in a string as a real namespace, so cider-interactive-eval evals it in user namespace instead of the current one.

I tried to fix it by myself but unfortunately, Emacs regexes don't support look ahead, so probably we should discuss the way it should be fixed.

@bbatsov bbatsov added bug good first issue A simple tasks suitable for first-time contributors labels Nov 1, 2024
@bbatsov
Copy link
Member

bbatsov commented Nov 1, 2024

Probably in this case we can combine the regexp check with some check that whatever gets matched is not a string and keep looping. Or alternatively - match only at the beginning of the file, which is not without risks either.

@yuhan0
Copy link
Contributor

yuhan0 commented Nov 1, 2024

The ^ in the regex is (likely unintentionally) matching the middle of the form - changing it to

"\\`"

ie. (rx string-start) should be an easy fix.

@bbatsov
Copy link
Member

bbatsov commented Nov 1, 2024

Ah, yeah. Even I forgot about this from time to time - Emacs RX's are so weird! 😅

a13 added a commit to a13/cider that referenced this issue Nov 8, 2024
a13 added a commit to a13/cider that referenced this issue Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue A simple tasks suitable for first-time contributors
Projects
None yet
Development

No branches or pull requests

3 participants