Fork me on GitHub
#vim
<
2021-07-29
>
walterl14:07:30

If you use Conjure and/or run your REPL in a vim terminal, how do you handle (scan/read) very long lines? E.g. logging keys of an initialized Duct system: (log/info "initialized system" {:system (keys system)}). I have a log line of that that's 1536 characters long, and obviously not that easy to read through. How would you "consume" a line like that in vim? Currently I yank and paste the list of keys into a :new buffer, :set ft=clojure, and use my mapping to <Cmd>%!jet --pretty<CR>. Feels like there should be an easier way, and set wrap isn't it. 😝

emilaasa18:07:08

I think I use Vgq most often for that.

walterl20:07:30

That's usually my first port of call too, and certainly easier to navigate than a single, massive line, but quite similar in result to set wrap.

Olical15:08:42

Or <prefix>e! to eval in place and replace the original code / data with a clojure.pprint formatted result 😄

🪄 6
dave15:08:14

Awesome! I forgot about that feature! wizard

Olical15:08:50

I use that a looooot and it only rarely lets me down when there's a reader macro that Clojure barfs on.

dave14:07:04

%!jet --pretty
I'm totally stealing this!

Noah Bogart14:07:06

the goal is to manually verify, you mean?

walterl14:07:05

@nbtheduke In this specific case I was just looking to see if a specific key was there, but I'm thinking about the general problem of looking for something in very long output lines. Like Ring requests/responses.

dave14:07:15

I think the Conjure log buffer is writable, so couldn't you just highlight the long line in the Conjure buffer and use %!jet --pretty to write it back to the buffer, prettified?

walterl14:07:47

Doesn't work on actual log lines, because the log prefixes makes it invalid EDN 😕

walterl14:07:59

Good idea though (I just tried it 🙂)

dave14:07:17

I guess %!jet --pretty would do the whole buffer, actually. You would want to use !jet --pretty if you have something highlighted.

dave14:07:45

I have similar bindings set up to prettify/minify JSON and write it back to the buffer:

""""""""""""""""""""""""""""""
" => JSON
"""""""""""""""""""""""""""""""
" magically format/minify json in the current buffer
nnoremap <leader>jf :%!jq -S '.'<CR>
nnoremap <leader>jm :%!jq -c '.'<CR>
" or just the current visual selection
vnoremap <leader>jf :!jq -S '.'<CR>
vnoremap <leader>jm :!jq -c '.'<CR>

dave14:07:39

Hmm, the equivalent doesn't seem to work for jet. I think maybe jet doesn't work quite like jq?

dave14:07:45

Oh, it works if you don't have a bunch of non-EDN stuff on the same line.

dave14:07:51

Which is what you were saying 🙂

dave14:07:15

I set up some simple mappings to pipe selected text (or the whole buffer) through jet, either to prettify it or to compact it. I like it! One caveat is that you have to put the EDN on its own line. Note how here in this fake log line, I have to go into insert mode and press enter to push the EDN down to the next line.

dave14:07:26

If I end up doing this enough, I'll probably add another mapping to automate the part where I go into insert mode and press enter to push it down onto the next line, and then select til the end of the line.

dave14:07:01

It would be something like nmap <leader>EF i<CR>v$<leader>Ef

dave14:07:01

That isn't quite working, but something like that 😄

walterl15:07:57

I like the direction you (and @U8QBZBHGD) are going. Will have to play around with it a bit more.

walterl15:07:48

Yeah, I tried :'<,'>!jet --pretty, but jet still received the whole line

walterl20:07:24

If all else fails, macro it up 😎 :vmap <leader>E y:vnew<CR>P:set ft=clojure <Bar> %!jet --pretty<CR>zR

partywombat 2
dave13:07:30

@UJY23QLS1 ^I just tried this and it's awesome. Thank you!

bubblebobble 4
dave13:07:53

Result of tinkering with this a bit:

" "If all else fails, macro it up 8-)" - @walterl
"
" Adapted from @walterl's macro:
" :vmap <leader>E y:vnew<CR>P:set ft=clojure <Bar> %!jet --pretty<CR>zR
"
" Opens a new clojure buffer in a split containing the prettified EDN
function! PrettyJetSplit() abort
  vnew
  normal! p
  set ft=clojure
  nnoremap <buffer> q :bdel!<CR>
  %!jet --pretty
  normal! zR
endfunction

vnoremap <silent> <leader>EF y:call PrettyJetSplit()<CR>

" Shortcut: in normal mode, placing your cursor inside the top level of an EDN
" map and using this mapping results in visually selecting the EDN map and doing
" the PrettyJetSplit thing above.
nnoremap <silent> <leader>EF va}y:call PrettyJetSplit()<CR>

dave13:07:21

I like to map q to close certain buffers like this one because I'm weird like that. 🙂

walterl13:07:00

That's pretty cool!

walterl14:07:46

OK, I'm stealing your updates 🙂

walterl14:07:07

I was wondering whether this is a good use case for a scratch buffer, but it's probably better as-is, so it can be :written to a file if necessary

sheluchin17:07:33

Is anyone using vim-iced with Fulcro (or at least shadow-cljs)? I'm running into troubles connecting to my editor and suspect it's got something to do with iced, but I can't find any docs that really cover my use case. Some brief discussion/details on my issue: https://clojurians.slack.com/archives/C68M60S4F/p1627572500148900

pablore19:07:04

a question for conjure vimmers: What mappings do you use for comfortable clojure development?

walterl20:07:20

Besides the Conjure defaults, of which I use quite a few, I also use these: https://github.com/walterl/dotfiles/blob/master/_config/nvim/ftplugin/clojure/clojure.vim

👍 2
schmee21:07:59

(I stick to the default ones)

dharrigan06:07:40

Great find! Added to my config too! 🙂