Fork me on GitHub
#vim
<
2021-10-05
>
nate16:10:29

anyone have solutions that they like to the "format this file or this section via an external command like cljfmt" problem?

nbardiuk16:10:10

I will not say I like it but this works https://github.com/nbardiuk/dotfiles/blob/50d8044614981626143091bbea15dd45c5ea5f29/nix/.config/nixpkgs/home/init.vim#L219-L231 I've added cljfmt to ale which I use for other languages. Also it requires external cljfmt in path, lein native-image builds it using graalvm https://github.com/weavejester/cljfmt/blob/master/cljfmt/project.clj#L24 . What I like in this is integration with Ale and that it is native (reasonably fast)

noisesmith17:10:14

I might be missing something, but if you :set formatprg=cljfmt it will literally call cljfmt for gqq etc.

rwstauner19:10:58

i've been fairly happy with this simple

setl formatprg=cljstyle\ pipe
which is basically the same as noisesmith's

rwstauner19:10:00

i used to use a vim cljfmt plugin that would auto-format based on the project config but now i mostly work in repos that aren't consistent so i just use gq<motion> myself

rwstauner19:10:53

i think i used to use venantius/vim-cljfmt

nate20:10:30

Thank you all for your feedback. I will check them all out.

Proctor21:10:21

I have an autocmd for :BufWritePre that calls the lsp formatting_sync in neovim’s lsp provider

Proctor21:10:19

or could do it with a mapping (buffer or global)m but both just call vim.lsp.buf.formatting_sync()

dominicm18:10:27

If I'm doing a one-off, I use ! (`:help !`)

walterl20:10:28

Related to that: is there a way to have coc.nvim format code with the connected clojure-lsp, via equalprg?

ericdallo20:10:44

you mean calling clojure-lsp format which uses cljfmt under the hood? what is equalprg?

walterl20:10:48

equalprg the vim option which defines the external program to run for formatting.

walterl20:10:51

I'm assuming that it would be faster to use the running clojure-lsp for formatting, rather than starting up cljfmt/`clojure-lsp format`

walterl20:10:42

I have a slight preference for not installing cljfmt separately (I don't have it installed now), in order to minimize the set of tools in use.

walterl20:10:02

Maybe I want too many things 😝

ericdallo21:10:19

Yeah, certainly call clojure-lsp format of the running clojure-lsp would be way faster

ericdallo21:10:46

I don't think you want that much, I have the same preferences but on emacs :)

walterl22:10:36

Can you/how would you do this in emacs?

ericdallo22:10:25

With lsp-mode, which gives you commands to all LSP methods, and since format is a official LSP method, there is a lsp-format-buffer function and a lsp-format-region one as well

ericdallo22:10:43

Which just request clojure-lsp running session

walterl00:10:37

Looks like we can setl formatexpr=CocAction('formatSelected') with coc.nvim to format selections/ranges with gq, or :call CocAction('format') to format the entire buffer. https://github.com/neoclide/coc.nvim/

👍 3
walterl00:10:11

It's not quite equalprg/`indentexpr`, but it'll do 🙂

walterl00:10:15

Thanks for the explanation, @UKFSJSM38. It nudged me to search in the right direction 👍

sheluchin21:10:18

Is there some way to get more information about what iced repl is doing in the background? I am trying to do a simple require. When I do it through just clj, it works fine. When I do it through my vim-iced editor integration, I get a missing namespace exception.

nbardiuk21:10:08

As far as I can read bash, the iced repl discovers type of project and starts corresponding repl with extra nrepl middleware to support editor integration https://github.com/liquidz/vim-iced/blob/main/bin/iced

nbardiuk21:10:43

maybe you need to provide extra arguments to iced repl to enable some alias from your deps.edn https://liquidz.github.io/vim-iced/#iced_usage

sheluchin21:10:53

I've been launching my project the same way for a while:

iced repl :main --force-shadow-cljs -A:dev
Made a couple of upgrades to my deps - both project and tooling - and now the same old command is throwing up an error when I :IcedConnect like I always have. I'm trying to narrow down what may have broken it. Nothing in that iced code you linked, as far as I can understand it, really jumps out at me. The main observation so far is that the require works in plain clj but not when done through iced.

nbardiuk21:10:58

If it used to work and now not, maybe it worth opening an issue in github, usually author is very helpful.

sheluchin22:10:50

Thanks @U076FM90B, I'll try that if I can't figure it out soon.

sheluchin13:10:13

I don't understand why, but it appears to work again after `$ rm -rf ~/.m2/repository/juxt`, recompiling, and restarting my tooling. Just leaving this here for posterity.

1
walterl00:10:37

Looks like we can setl formatexpr=CocAction('formatSelected') with coc.nvim to format selections/ranges with gq, or :call CocAction('format') to format the entire buffer. https://github.com/neoclide/coc.nvim/

👍 3