AndrewRadev / splitjoin.vim

Switch between single-line and multiline forms of code
http://www.vim.org/scripts/script.php?script_id=3613
MIT License
1.93k stars 90 forks source link

Clojure / general lisp support #183

Open hoclun-rigsep opened 2 years ago

hoclun-rigsep commented 2 years ago

Any plans for supporting Clojure and/or lisps generally?

AndrewRadev commented 2 years ago

I would be happy to support lisp-like filetypes, but I don't have practical experience with them, so I don't know what kinds of splits and joins would make sense, what settings to provide, etc. If you use a lisp yourself, do you have any specific transformations you do often that the plugin could support? Maybe a few before/after examples of code snippets?

hoclun-rigsep commented 2 years ago

Absolutely. My only experience is as a novice Clojure/ClojureScript user. Source consists of "forms" which are delimited by () [] and {}. Even a function call is just a (fn arg1 arg2) which means the syntax is extremely general.

Simple examples, this calls the function +:

(+ 2 3 4 5)
(+
  2
  3
  4
  5)

guns/vim-sexp provides indentation.

From my project, this is properly indented and the brackets appear where they should:

(dispatch [::events/insert-staff-entry
            day-ord
            shift
            unit
            @why
            @who])

Would be nice to go to this, and back:

(dispatch [::events/insert-staff-entry day-ord shift unit @why @who])

If you need more discussion/research, I will help.

AndrewRadev commented 2 years ago

I've added some basic support to the main branch -- could you pull and try it out? If it works well for some of your real code, I'll write up some documentation, and if there's edge cases I haven't considered, I'll see what I can do to work them out.

hoclun-rigsep commented 2 years ago

Thanks, very cool. I'll play with it at work next week and collect my experience.

hoclun-rigsep commented 2 years ago

Still working on my report, thanks again

hoclun-rigsep commented 2 years ago

Want to thank you for this, I had to move away from using Clojure at work for a while but I still intend to report back here.

hoclun-rigsep commented 2 years ago

This is already useful as is—thank you.

Here's an issue:

(map (fn [[d s u i]] ^{:key i}
       [:tr
        [:td
         [row d s u i]
         "DOG"]])
     staff-keys)

If I position the cursor on :td (the form here is a "vector', vector literals [look like this]) and press gJ here is what I would expect: the :td form on one line, trailing delimiters from enclosing forms also on that line.

(map (fn [[d s u i]] ^{:key i}
       [:tr
        [:td [row d s u i] "DOG"]])
     staff-keys)

What I get is:

(map (fn [[d s u i]] ^{:key i}
  [:tr
   [:td [row d s u i] "DOG"]])           staff-keys)
AndrewRadev commented 2 years ago

It's funny, I was just fixing a very similar bug for a separate problem 😅. So at least I know what the issue is -- it should be fixed now.

hoclun-rigsep commented 2 years ago

It does look fixed. I'll let you know what else I come across this week as I'm back at my Clojure/Script projects.