Skip to content

Valid clojure code causes emacs hang #127

@kthu

Description

@kthu

Opening a clojure file with the following function in clojure-ts-mode:

(defn unescape
  [s]
  (-> s
      (string/replace "&"  "&")
      (string/replace "*"  "*")
      (string/replace "^"  "^")
      (string/replace "_"  "_")
      (string/replace "~" "~")
      (string/replace "&lt;"   "<")
      (string/replace "&gt;"   ">")
      (string/replace "&#91;"  "[")
      (string/replace "&#93;"  "]")
      (string/replace "&#40;"  "(")
      (string/replace "&#41;"  ")")
      (string/replace "&quot;" "\"")))

..causes emacs to hang for over 10 minutes. Any attempt to edit the file once emacs has sprung back to life will cause another 10+ minutes of waiting. During these 10 minutes I can see emacs saturating a CPU core.

I have reproduced this with a minimal project containing just one file with just this one function, and with a stripped down emacs init.el just containing:

(package-install 'clojure-ts-mode)
(use-package clojure-ts-mode)

Interestingly clojure-ts-mode seems to be perfectly ok with the following rewrite:

(defn unescape
  [s]
  (string/replace s #"&amp;|&#42;|&#94;|&#95;|&#126;|&lt;|&gt;|&#91;|&#93;|&#40;|&#41;|&quot;"
                  {"&amp;"  "&"
                   "&#42;"  "*"
                   "&#94;"  "^"
                   "&#95;"  "_"
                   "&#126;" "~"
                   "&lt;"   "<"
                   "&gt;"   ">"
                   "&#91;"  "["
                   "&#93;"  "]"
                   "&#40;"  "("
                   "&#41;"  ")"
                   "&quot;" "\""}))

Expected behavior

File opens fine, like it does in clojure-mode

Actual behavior

Emacs hangs

Steps to reproduce the problem

Put above function into a file and open it in clojure-ts-mode

clojure-ts-mode version

0.5.1

tree-sitter-clojure grammar version

unstable-20250526 (the version emacs installs when starting clojure-ts-mode)

Emacs version

30.2

Operating system

Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions