Has anyone figured out a good workflow for cljfmt's new abilities to align maps and let forms, etc.?
:aligned-forms - a map of symbols to indexes that tell cljfmt where to expect forms it should align. For example, {'let #{0}} indicates that the first argument of let (the binding vector) should be aligned. This option will replace the default aligned forms. Used by :align-form-columns?. Experimental.
:align-form-columns? - true if cljfmt should align the symbols and values within certain forms (such as let) so that they line up in columns. The forms are defined via the :aligned-forms and :extra-aligned-forms options. Defaults to false. Experimental.
:align-map-columns? - true if cljfmt should align the keys and values of maps such that they line up in columns. Defaults to false. Experimental.
:extra-aligned-forms - the same as :aligned-forms, except that this will append to the default aligned forms. Experimental.
I know a lot of vimmers have been wanting these capabilities for a long time. Emacs and intellij have had the ability to do so and I think it can be on the s expression level or the whole file, etc. so I would like to build out some keybindings to do the same.https://github.com/clojure-lsp/clojure-lsp/blob/master/CHANGELOG.md#unreleased cljfmt bump still unreleased
My current attempt is like so:
At the root of my practice repo I have:
.lsp/config.edn
{:cljfmt-config-path ".cljfmt.edn"}
.cljfmt.edn
{:indentation? true
:remove-surrounding-whitespace? true
:remove-trailing-whitespace? true
:insert-missing-whitespace? true
:remove-consecutive-blank-lines? false
:align-map-columns? true
:align-form-columns? true}
and then in my init.lua
-- in lsp settings
if lsp == "clojure_lsp" then
opts.root_dir = util.root_pattern(".git")
opts.settings = {
["clojure-lsp"] = {
format = { enabled = true },
["cljfmt-config-path"] = ".cljfmt.edn"
}
}
-- in keybindings
{ 'n', 'f', function() vim.lsp.buf.format({ async = false }) end }, -- Format buffer with cljfmt
{ 'v', 'f', function() vim.lsp.buf.format({ async = false }) end }, -- Format selection It seems to work for all kinds of formatting except for the new align hashmaps and such. But when I run cljfmt fix from the command line it does align my hashmaps, etc. and I can see the setting is getting picked up properly:
λ ~ : cljfmt
Usage:
cljfmt (check | fix) [PATHS...]
Config:
/home/chaselambert/projects/clojure/practice/.cljfmt.edn
Options:
-h, --help
--version
-q, --quiet
-v, --verbose
--[no-]align-form-columns true
--[no-]align-map-columns true
--[no-]ansi true
--config CONFIG_FILE
--file-pattern FILE_PATTERN \.clj[csx]?$
--function-arguments-indentation STYLE community STYLE may be community, cursive, or zprint
--[no-]indentation true
--[no-]indent-line-comments false
--[no-]insert-missing-whitespace true
--[no-]parallel false
--project-root PROJECT_ROOT .
--[no-]remove-consecutive-blank-lines false
--[no-]remove-multiple-non-indenting-spaces false
--[no-]remove-surrounding-whitespace true
--[no-]remove-trailing-whitespace true
--[no-]sort-ns-references false
--[no-]split-keypairs-over-multiple-lines falseI'm wondering if clojure-lsp has an earlier version of cljfmt bundled and is using that one versus my system installed version (which is 0.15.5 )
While I sort that out I just have a bb.edn file (at project root level) with this:
{:tasks
{fmt
{:extra-deps {dev.weavejester/cljfmt {:mvn/version "0.15.5"}}
:task (shell "cljfmt fix")}}}
and that gets the job done with bb fmt for nowProbably just need to either try nightly or open a pr.
It does bundle cljfmt afaik