You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: is there a way to configure Tonsky's indentation rule? #21
changed the title [-]Question: is there a way to configure Tonsky's indent rule?[/-][+]Question: is there a way to configure Tonsky's indentation rule?[/+]on Dec 21, 2021
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:
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 listpwordsby using:
let g:clojure_fuzzy_indent_patterns = ['^\S\+']
This works in most cases but sometimes doesn't. I haven't figured out why yet.
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.
Looks like the (+<CR>...) issue is due to s:current_word calling searchpos('\v>'...) when it's on the symbol in question. This search fails when the symbol is a single character. Potentially making it move back a character before searching would be sufficient?
RE: clojure_fuzzy_indent_patterns, I've been using this pattern which I adapted from the tree-sitter grammar
localsuffixonly=":#'0-9\\/" -- not allowed as first characterlocalforbidden= {
[[\[\]\n\r\t \\]], -- brackets, whitespace, slashes'(){}"@~^;`,', -- parens, braces, special characterssuffixonly,
}
localprefix=string.format("[^%s]", table.concat(forbidden))
localsuffix=string.format([[\(%s\|[%s]\)*]], prefix, suffixonly)
localsymbol=prefix..suffixvim.g["clojure_fuzzy_indent_patterns"] = { symbol }
It's slightly more accurate than relying on \k in the pattern. Still, I don't think there's an easy userland fix for the single character symbols.
Edit: Ha, just saw #31; wish I'd looked closer before spending time looking into this. 😆
Activity
[-]Question: is there a way to configure Tonsky's indent rule?[/-][+]Question: is there a way to configure Tonsky's indentation rule?[/+]axvr commentedon Dec 21, 2021
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
formatprglike this:This will set the program used by the
gqoperator. So to format the entire file using clojurefmt you would typegggqGin 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.
markx commentedon Dec 23, 2021
Thanks for the tip about
formatprg. With it I can use external tools likecljstylesto 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
lispwordsbasically works in my setting (I think mostly justset shiftwidth=2), so I just add everything tolistpwordsby using:This works in most cases but sometimes doesn't. I haven't figured out why yet.
Is there a better to achieve this?
axvr commentedon Dec 23, 2021
Oh, OK I think I understand now.
Do you have an example of where your
g:clojure_fuzzy_indent_patternsvalue isn't working properly?Maybe you could try this one (it should be slightly more accurate):
markx commentedon Dec 24, 2021
E.g. for this sometimes it doesn't work. (Sometimes it does work. Not sure why. )
Desired result would be:
Also
let g:clojure_fuzzy_indent_patterns = ['^[\k\d]\+']doesn't seem to work for me :(What does
\kmatch?axvr commentedon Dec 27, 2021
Thanks for the example. I'll look into this when I get a chance (hopefully soon).
(The
\kmatches characters in theiskeywordoption. This value lists (most of) the characters allowed in Clojure symbols.)Deraen commentedon Feb 4, 2022
g:clojure_align_subformsoption 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.Begin rewrite of indentation code
garrett-hopper commentedon May 8, 2025
Looks like the
(+<CR>...)issue is due tos:current_wordcallingsearchpos('\v>'...)when it's on the symbol in question. This search fails when the symbol is a single character. Potentially making it move back a character before searching would be sufficient?RE:
clojure_fuzzy_indent_patterns, I've been using this pattern which I adapted from the tree-sitter grammarIt's slightly more accurate than relying on
\kin the pattern. Still, I don't think there's an easy userland fix for the single character symbols.Edit: Ha, just saw #31; wish I'd looked closer before spending time looking into this. 😆