Fork me on GitHub
Yehonathan Sharvit06:04:21

Sometimes, I need to require a namespace for its side-effects (e.g. defmethod declarations).

(ns foo
  (:require bar))
But cider-refactor removes `bar` from the require list, as it “Remove any unused libspec vectors”. Does anyone know a way to tell clj-refactor to keep `bar`?


I don't know how to instruct clj-refactor to do this but I tend to write a comment why it's supposed to be there and check diffs before I commit the changes (+ extra code review step which should catch that too).

Yehonathan Sharvit07:04:48

That’s what I did. But I missed it during code review. And boom! My lib was corrupted.

Yehonathan Sharvit07:04:22

It’s also hard to catch with unit tests because the namespace is loaded by some tests.


The other thing is that I don't really encounter this issue much - which specific function from clj-refactor triggers this behavior? I mostly use cljr-add-require-to-ns and that seems to work fine (that is doesn't touch the other, even unused, requires; just sorts them)


For unused requires I simply remove them manually after quick inspection - relying on "linter errors" reported by clj-kondo


Yeah, I never use that.


(comment bar/keep-me)


We do this a lot at work

Yehonathan Sharvit12:04:45

You really call the function keep-me ?


Yeah it doesn’t need to resolve, just show up as a use of the namespace. The keep-me makes it clear what it’s purpose is


What I normally do is placing a require below the ns form. There's no difference to the compiler - ns is just standardized syntax sugar over require It's fairly easy to see why a top-level require is there so I generally don't even attach an explanatory comment to them

👍 9

Yes, many many times a day


I always use C-x C-e or C-c C-p but I might start using C-c C-e now that I know it exists. Is it an upgrade from C-c C-v? it would be for me on dvorak but seems worse for qwerty


Whether it's easier to press it debatable, but it seems like a better mnemonic to me, as it (e)val in its name.


Also the keybinding in quesiton won't change much - it will become C-c C-e (C)-e.


The only reason why C-c C-e and C-x C-e both are both mapped to the same command is to mimic SLIME - early on it seemed like a good idea, but as CIDER has way more commands than SLIME at some point I started to regret wasting keybindings in this fashion.


Anyways, I don't feel strongly about this, I was just wondering how attached people are to this. I've never used C-c C-e myself.


I won't mind if it's changed


I too use C-c C-e a lot, but I also don’t mind if it’s changed


More context - I was considering to use C-c C-e for the eval keymap, as it'd be more convenient than C-c C-v.


(or at least it will be easier to remember)