Fork me on GitHub
#vim
<
2019-06-11
>
dharrigan08:06:36

The obsessive complusive is getting the better of me 🙂 Does anyone know of a plugin (or way?) to sort alphabetically the (:require [......]) block in vim?

❤️ 4
dave13:06:49

I also obsessively do this :D

dharrigan07:06:39

I wonder if there is a way to plug it into conjure?

lxsli09:06:22

clojure-lsp does this I believe, with crcn. In fact it's the only thing its crcn impl can do, so perfect for you 🙂

Olical08:06:31

Although not a plugin.

dharrigan08:06:42

there is a vim-slamhound

dharrigan08:06:01

checking it out...will report back

Olical08:06:15

👍 another possible Conjure candidate too tbh.

Olical08:06:29

(although ideally hooked up via a plugin so it's not default)

dharrigan08:06:49

presently, I just whack whatever I require into the require block as I'm working on it, and it gets messy 🙂

Olical08:06:20

I usually sort by: Clojure core stuff, 3rd party, my own things.

Olical08:06:27

¯\(ツ)

dharrigan08:06:13

I like things to be alphabetical 🙂

Olical09:06:20

Someone made me sort JavaScript imports by line length once for no other reason than "it looked nice". Each to their own, I just prefer some grouping based on how they're related.

12
dharrigan09:06:13

I'm afraid I'm in that category too 🙂 In Java/Kotlin I usually sort my annoations from smallest to biggest, like a pyramid 🙂

samoleary09:06:34

clojure-lsp has this feature, though i think it's experimental https://github.com/snoe/dotfiles/blob/master/home/.vimrc#L270

Olical09:06:19

Maybe define

(defn sort-require [req]
  (concat (list (first req))
          (sort-by first (rest req))))
in some util namespace then eval your (:require ...) with it quoted :thinking_face:

Olical09:06:30

The output will be the data of the require sorted.

Olical09:06:44

Might be able to totally automate it under a mapping somehow.

dave13:06:47

My dream is to have a way to not only alphabetize my requires, but also vertically align the :as / :refer

dave13:06:25

I always feel compelled to do this manually, and it's tedious

lxsli10:06:48

You could see if vim-tabulate will do it

uochan13:06:41

I'm using clean-ns feature in refactor-nrepl via vim-iced. https://liquidz.github.io/vim-iced/vim-iced.html#%3AIcedCleanNs

benedek16:06:51

i did write a sorting function (pluggable) for clj-refactor ages ago. sorry for mentioning this here 😉

benedek16:06:58

for requires ofc

benedek16:06:46

not even sure it is still there

dominicm17:06:38

I think it is @benedek, I'm using it

benedek17:06:56

i even had a semantic sort that put the project internal deps on top. don't use it anymore