Open markx opened 2 years ago
From a quick scan of that page, it looks like clojurefmt doesn’t exist (yet?). But if it does exist, you can tell Vim to use it by setting formatprg
like this:
autocmd! FileType clojure setlocal formatprg=clojurefmt
This will set the program used by the gq
operator. So to format the entire file using clojurefmt you would type gggqG
in normal mode.
The downside to this is that formatting won’t happen automatically, but you could write a little Vim script to auto-format on file save.
Thanks for the tip about formatprg
. With it I can use external tools like cljstyles
to format the file.
However this is not what I was looking for originally. I was looking for a way to adjust the vim indent config so that it auto-indents following Tonsky's indentation rule. This way the indentation would be correct while I type, so I don't need to save the file constantly.
After some exploring, I found the indentation for lispwords
basically works in my setting (I think mostly just set shiftwidth=2
), so I just add everything to listpwords
by using:
let g:clojure_fuzzy_indent_patterns = ['^\S\+']
This works in most cases but sometimes doesn't. I haven't figured out why yet.
Is there a better to achieve this?
Oh, OK I think I understand now.
Do you have an example of where your g:clojure_fuzzy_indent_patterns
value isn't working properly?
Maybe you could try this one (it should be slightly more accurate):
let g:clojure_fuzzy_indent_patterns = ['^[\k\d]\+']
E.g. for this sometimes it doesn't work. (Sometimes it does work. Not sure why. )
(+
1
1)
Desired result would be:
(+
1
1)
Also let g:clojure_fuzzy_indent_patterns = ['^[\k\d]\+']
doesn't seem to work for me :(
What does \k
match?
g:clojure_align_subforms
option controls whether to indent function calls with one (tonsky's post) or two spaces ("emacs"/clojure-style-guide). The first, two spaces, is the default.
If you haven't changed the option, check your indentexpr
, formatexpr
, formatprg
, you might another plugin which is indenting function call forms with one space.
Context: https://tonsky.me/blog/clojurefmt/