clojure-emacs / clj-refactor.el

A CIDER extension that provides powerful commands for refactoring Clojure code.
GNU General Public License v3.0
771 stars 111 forks source link

cljr-promote-function issues #505

Open yuhan0 opened 2 years ago

yuhan0 commented 2 years ago

Expected/Actual behavior

There appear to be several issues with the implementation of cljr--promote-function-literal (the #() -> fn case of cljr-promote-function)

#(foo %)

;; =>

(comment (fn [a] (foo a (bar a2))) )


-  Enters a loop when a string contains "%"
```clj
(comment
  #(str "%%" %)
  )

I've proposed an alternative implementation of this feature in https://github.com/clojure-emacs/clojure-mode/pull/601.

The cljr-promote-function command could delegate to it in the #()->fn case, replacing the current implementation while keeping the fn->defn logic.

Environment & Version information

clj-refactor.el version information

3.0.0alpha13

CIDER version information

;; CIDER 1.2.0snapshot, nREPL 0.8.3
;; Clojure 1.10.3, Java 13.0.2

Leiningen or Boot version

Emacs version

28.1

Operating system

macOS

bbatsov commented 2 years ago

The cljr-promote-function command could delegate to it in the #()->fn case, replacing the current implementation while keeping the fn->defn logic.

Fine by me. PR welcome!