Skip to content

Fix to Emacs hang when viewing ClojureDocs for "/"#3900

Merged
bbatsov merged 3 commits into
clojure-emacs:masterfrom
metayan:docs-slash-fix
May 16, 2026
Merged

Fix to Emacs hang when viewing ClojureDocs for "/"#3900
bbatsov merged 3 commits into
clojure-emacs:masterfrom
metayan:docs-slash-fix

Conversation

@metayan
Copy link
Copy Markdown
Contributor

@metayan metayan commented May 8, 2026

Emacs hangs terribly with 100% CPU usage and enormous memory consumption if it is forced to highlight "" in a buffer.

Requesting ClojureDocs for / triggers the issue.
This PR prevents it, by correctly removing the namespace - keeping only the symbol name.


  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • All code in the relevant file passes the linter (eldev lint)

Steps to reproduce the problem

With cursor after a lone /
Don't do C-c C-d C-c
because it will send Emacs on a memory-eating spree and never return.
Occasionally it's possible to interrupt with C-g, but usually one needs to kill the Emacs process.

CIDER version information

;; CIDER 1.22.0-snapshot, nREPL 1.7.0
;; Clojure 1.12.4, Java 25.0.1

cider master branch
and any version before that, probably since at least 2022

Emacs version

30.2
28.2

Operating system

macOS and Linux

Yan added 2 commits May 8, 2026 19:54
More general way of removing namespace from symbol, so the symbol can
be properly highlighted in the ClojureDocs buffer.

Emacs hangs terribly if it tries to highlight "".
Comment thread test/cider-clojuredocs-tests.el Outdated

(describe "cider-clojuredocs-lookup-remove-namespace"
(it "removes namespace from symbol to highlight only the name"
(expect (replace-regexp-in-string "^.+?/" "" "clojure.core//") :to-equal "/")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not really testing cider-clojuredocs-lookup-remove-namespace, but only the built-in replace-regexp-in-string with your test.

Copy link
Copy Markdown
Contributor Author

@metayan metayan May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the intention with the test is to show that the regex behaves as intended. Didn't want to break out the replace-regexp-in-string into a new function.

Edit: Saw your comment below now.

@bbatsov
Copy link
Copy Markdown
Member

bbatsov commented May 9, 2026

Nice catch on the bug! The fix works. Two thoughts while we're here:

The regex could be tighter and line up with patterns already in the codebase. cider-namespace-qualified-p (cider-util.el) and cider-resolve--prefix-regexp (cider-resolve.el) both use [^/]+/ for matching namespace prefixes, and the latter is even used the same way (with replace-regexp-in-string ... ""):

(replace-regexp-in-string "\\`[^/]+/" "" sym)

Same behavior on clojure.core///, but more explicit about intent ("non-slash chars + slash") and \`` is more precise than ^` (string start vs. line start).

The other thing: the new tests exercise the regex inline, not the production code — if someone tweaks the regex inside cider-clojuredocs-lookup, the tests pass regardless. Worth extracting a tiny helper and pointing the tests at that, mirroring how cider-clojuredocs-replace-special is factored:

(defun cider-clojuredocs--strip-ns (sym)
  "Strip the namespace prefix from SYM, leaving just the symbol name."
  (replace-regexp-in-string "\\`[^/]+/" "" sym))

And then:

(describe "cider-clojuredocs--strip-ns"
  (it "removes the namespace from qualified symbols"
    (expect (cider-clojuredocs--strip-ns "clojure.core/subs") :to-equal "subs")
    (expect (cider-clojuredocs--strip-ns "clojure.string/trim") :to-equal "trim"))
  (it "preserves a slash symbol name (the bug being fixed)"
    (expect (cider-clojuredocs--strip-ns "clojure.core//") :to-equal "/"))
  (it "preserves operator-like names"
    (expect (cider-clojuredocs--strip-ns "clojure.core/+") :to-equal "+"))
  (it "leaves unqualified symbols unchanged"
    (expect (cider-clojuredocs--strip-ns "subs") :to-equal "subs")))

@metayan
Copy link
Copy Markdown
Contributor Author

metayan commented May 9, 2026

Clever with the "is" comments in the tests. Thanks. Learning...
I'll modify the PR accordingly.

More general way of removing namespace from symbol, so the symbol can
be properly highlighted in the ClojureDocs buffer.

Emacs hangs terribly if it tries to highlight "".

Thanks to @bbatsov for cleverer solution and better tests.
@metayan
Copy link
Copy Markdown
Contributor Author

metayan commented May 9, 2026

PR modified - with an extra test for unqualified "/" added.
Do you have a way of squashing the three commits into one, or should I do that somehow?

@bbatsov bbatsov merged commit 84800ca into clojure-emacs:master May 16, 2026
13 checks passed
@bbatsov
Copy link
Copy Markdown
Member

bbatsov commented May 16, 2026

Yeah, I can squash when merging. Thanks!

@metayan metayan deleted the docs-slash-fix branch May 17, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants