Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is there a way to configure Tonsky's indentation rule? #21

Open
markx opened this issue Dec 21, 2021 · 6 comments · May be fixed by #31
Open

Question: is there a way to configure Tonsky's indentation rule? #21

markx opened this issue Dec 21, 2021 · 6 comments · May be fixed by #31
Assignees
Labels
indentation Affects indentation

Comments

@markx
Copy link

markx commented Dec 21, 2021

Context: https://tonsky.me/blog/clojurefmt/

@markx markx 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? Dec 21, 2021
@axvr
Copy link
Member

axvr commented 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:

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.

@axvr axvr closed this as completed Dec 22, 2021
@markx
Copy link
Author

markx commented Dec 23, 2021

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.

Is there a better to achieve this?

@axvr
Copy link
Member

axvr commented Dec 23, 2021

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]\+']

@axvr axvr reopened this Dec 23, 2021
@markx
Copy link
Author

markx commented Dec 24, 2021

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?

@axvr
Copy link
Member

axvr commented Dec 27, 2021

Thanks for the example. I'll look into this when I get a chance (hopefully soon).

(The \k matches characters in the iskeyword option. This value lists (most of) the characters allowed in Clojure symbols.)

@axvr axvr self-assigned this Dec 27, 2021
@Deraen
Copy link
Member

Deraen commented Feb 4, 2022

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.

axvr added a commit that referenced this issue Apr 27, 2023
The objectives are:

    1. Simplify the indentation code; previous implementation has become
       so complex it is impossible to maintain,

    2. Significantly improve performance; previous indentation code was
       painfully slow, (see issue #6)

    3. Maximum configurability; should be configured similarly to cljfmt
       and make previously impossible things possible (e.g. issue #21).

As of this commit, objectives 1 and 2 have been met, but work on
objective 3 has not yet begun.  There will continue to be further
improvements, particularly around performance and the "what if syntax
highlighting is disabled?" scenario.

These changes will unfortunately be backwards incompatible, but
hopefully the improved performance and API will make up for it.
@axvr axvr linked a pull request Apr 27, 2023 that will close this issue
14 tasks
@axvr axvr added the indentation Affects indentation label Jun 23, 2023
@axvr axvr linked a pull request Jun 23, 2023 that will close this issue
14 tasks
@axvr axvr added this to the Indentation overhaul milestone Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
indentation Affects indentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants