This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-06
Channels
- # announcements (1)
- # babashka (118)
- # beginners (108)
- # calva (20)
- # chlorine-clover (3)
- # clara (10)
- # clj-kondo (47)
- # cljsrn (10)
- # clojure (144)
- # clojure-australia (5)
- # clojure-czech (2)
- # clojure-dev (11)
- # clojure-europe (94)
- # clojure-france (4)
- # clojure-nl (5)
- # clojure-spec (3)
- # clojure-sweden (2)
- # clojure-uk (11)
- # clojuredesign-podcast (5)
- # clojurescript (56)
- # cloverage (1)
- # code-reviews (6)
- # conjure (1)
- # cursive (13)
- # datascript (1)
- # datomic (16)
- # defnpodcast (1)
- # emacs (1)
- # etaoin (1)
- # events (7)
- # fulcro (21)
- # graalvm (3)
- # helix (17)
- # jackdaw (3)
- # jobs-discuss (2)
- # lambdaisland (2)
- # london-clojurians (2)
- # meander (2)
- # mid-cities-meetup (2)
- # midje (1)
- # off-topic (1)
- # pathom (3)
- # pedestal (12)
- # reagent (7)
- # reitit (15)
- # reveal (12)
- # shadow-cljs (6)
- # sql (14)
- # test-check (3)
- # vim (13)
What do you guys use to format large EDN blobs, on a single line, in vim? Something like passing it through pprint
Concrete example: I have a big Ring request, logged by timbre, so it's all on one long line
I have a socket REPL with cljfmt dependency on port 5353 and filter lines through a hacky oneliner shell script
echo "(do (require 'cljfmt.core)(print (cljfmt.core/reformat-string \"$(sed 's/\\/\\\\\\\\/g;s/"/\\"/g')\" $opts)))" | nc -N localhost 5353 | awk 'BEGIN{RS="\n?(nil\n)?user=> (nil\n)?"} $0'
Actually as it is this probably woudln't help for individual EDN values, cljfmt doesn't break them up in lines, I use it for misformatted code
yeah, the vim clojure mode already knows how to indent correctly (using =
) the question is where to put the line breaks
you do have to tweak settings a bit to make it agree with cljfmt
Closest I got is :%s/, /<C-v><CR>/g<CR>==
... but that replaces commas in strings too 🤷
Mine isn’t pretty either …
nnoremap <leader>e :call FormatEDN()<CR>1G=G<CR>
function! FormatEDN()
if search('" "')
execute '%s/" "/"\r"/g'
endif
" Break lists of maps onto separate lines.
if search('} {')
execute '%s/} {/}\r{/g'
endif
" Convert commas into newlines in maps.
if search(', :')
execute '%s/, :/\r:/g'
endif
endfunction
Better than what I got. Thanks, @defndaines!