This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-26
Channels
- # announcements (4)
- # beginners (160)
- # boot (2)
- # calva (40)
- # cider (41)
- # clara (24)
- # cljdoc (2)
- # cljs-dev (99)
- # clojars (4)
- # clojure (71)
- # clojure-dev (9)
- # clojure-europe (4)
- # clojure-italy (2)
- # clojure-nl (19)
- # clojure-spec (97)
- # clojure-uk (103)
- # clojurescript (57)
- # core-logic (1)
- # cursive (15)
- # data-science (31)
- # datomic (24)
- # duct (1)
- # emacs (39)
- # events (7)
- # figwheel-main (14)
- # fulcro (44)
- # garden (7)
- # jobs (13)
- # juxt (1)
- # leiningen (29)
- # music (2)
- # nyc (4)
- # off-topic (37)
- # pathom (12)
- # re-frame (26)
- # ring (1)
- # ring-swagger (10)
- # shadow-cljs (35)
- # spacemacs (2)
- # specter (4)
- # test-check (67)
This was nice! https://www.youtube.com/watch?v=L3BIE5yOKQw
It's painful to see how hard it is to get started! @mseddon, that jack-in, we need to get it out!
I have a question
Why is it that no Clojure IDE/editor has a simple way to extract a method
It can’t be that hard, no?
Possibly. I am curious as to what the challenges are
For instance, Cursive has something that lets you extract to a let block
There’s some LSP stuff around that. I am sure it isn’t trivial
But, why is it impossible? at least the dumbest case
(let [x 2 y 4] (+ x y 7))
if I select the inner form, why can’t it be bound into a defn with all unknown/unresolved args supplied?
yeah not sure what the complexities are. I just kinda laughed at your wording. It’s not the best way to request features from people
This isn’t a feature request
I am genuinely curious
If it came off as a feature request, then I am sorry
it might just be that it hasn’t been prioritized over other things. there are multitudes of low-hanging fruit in every project that gets put aside for more critical things
maybe it is easy and could implement it in calva without much trouble. I know the devs are really focused on getting jack-in functionality figured out, new REPL, formatting, etc.
Thanks
In theory it should be enough to add clj-refactor
as a middleware and set up the appropriate menus/keybindings.
(defun cljr-extract-function ()
"Extract the form at (or above) point as a top-level defn.
See: "
(interactive)
(cljr--ensure-op-supported "find-used-locals")
(when (cljr--asts-y-or-n-p)
(save-buffer)
(cljr--goto-enclosing-sexp)
(let* ((unbound (cljr--call-middleware-to-find-used-locals
(buffer-file-name) (line-number-at-pos)
;; +1 because the middleware expects indexing from 1
;; +1 more because point has to be inside the sexp,
;; not on the opening paren
(+ (current-column) 2)))
(name (unless (cljr--use-multiple-cursors-p)
(let ((highlight (cljr--highlight-sexp)))
(unwind-protect
(cljr--prompt-user-for "Name: ")
(delete-overlay highlight)))))
(body (clojure-delete-and-extract-sexp)))
(save-excursion
(cljr--make-room-for-toplevel-form)
(insert (cljr--defn-str))
(if name
(insert name)
(mc/create-fake-cursor-at-point))
(newline)
(indent-according-to-mode)
(insert "[" unbound "]")
(newline-and-indent)
(insert body ")"))
(insert "(")
(when name (insert name))
(save-excursion
(unless (string-blank-p unbound)
(insert " " unbound))
(insert ")"))
(unless name
(mc/maybe-multiple-cursors-mode)))))
1) cljr-add-project-dependency, this is huge when greenfielding https://github.com/clojure-emacs/clj-refactor.el/blob/master/clj-refactor.el#L2261
2) cljr-add-missing-libspec https://github.com/clojure-emacs/clj-refactor.el/blob/master/clj-refactor.el#L2907 which is bound to /
, so when you type foo/
clj-refactor will search for previous aliases foo
and insert the appropriate :require
3) cljr-clean-ns https://github.com/clojure-emacs/clj-refactor.el/blob/master/clj-refactor.el#L2742
Thanks @U04V5VAUN! Is it possible you could add this as an issue on github? I'm worried it will suffer from the 10K slack death sooner than we can pick up things where you've left them here. I pinned it and starred it in the hope that I might be able to keep it somehow, but I think that might be naïve.
Just to be clear, the above isn’t a feature request
I am just wondering why extracting something into a defn
block is hard enough that no IDE/editor has a simple way around it