Fork me on GitHub
#calva
<
2019-02-26
>
pez13:02:31

It's painful to see how hard it is to get started! @mseddon, that jack-in, we need to get it out!

parrot 10
craftybones16:02:26

I have a question

craftybones16:02:40

Why is it that no Clojure IDE/editor has a simple way to extract a method

craftybones16:02:47

It can’t be that hard, no?

lilactown16:02:40

famous last words lol

craftybones16:02:34

Possibly. I am curious as to what the challenges are

craftybones16:02:51

For instance, Cursive has something that lets you extract to a let block

craftybones16:02:49

There’s some LSP stuff around that. I am sure it isn’t trivial

craftybones16:02:58

But, why is it impossible? at least the dumbest case

craftybones16:02:21

(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?

lilactown16:02:37

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

craftybones16:02:47

This isn’t a feature request

craftybones16:02:50

I am genuinely curious

craftybones16:02:57

If it came off as a feature request, then I am sorry

lilactown16:02:15

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

lilactown16:02:37

I see that clj-refactor.el for Emacs supports extract function

lilactown16:02:12

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.

dominicm17:02:30

It's possible to implement using the middleware

pez17:02:21

I'd love me some pull requests for refactorings. ❤️

slipset09:02:03

In theory it should be enough to add clj-refactor as a middleware and set up the appropriate menus/keybindings.

slipset09:02:18

And then for one of my favourite jokes:

slipset09:02:34

What’s the difference between theory and practice? In theory, none.

slipset09:02:42

Yes, there seems to be a difference between theory and practice here.

slipset09:02:46

(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)))))

slipset09:02:05

So it’s a mix between middle-ware and elisp 🙂

slipset09:02:55

FWIW, the functionality I use the most from clj-refactor is:

slipset09:02:06

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

pez11:02:44

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.

pez11:02:28

Wonderful. Greatly appreciated!

slipset12:02:43

No worries 🙂

slipset12:02:55

It’s a hobby of mine to follow this project 🙂

❤️ 5
craftybones16:02:14

Just to be clear, the above isn’t a feature request

craftybones16:02:37

I am just wondering why extracting something into a defn block is hard enough that no IDE/editor has a simple way around it