This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-08
Channels
- # announcements (20)
- # aws (16)
- # babashka (63)
- # beginners (75)
- # calva (35)
- # cider (2)
- # clj-commons (5)
- # clj-kondo (2)
- # cljs-dev (1)
- # clojure (90)
- # clojure-australia (3)
- # clojure-europe (16)
- # clojure-france (1)
- # clojure-nl (4)
- # clojure-uk (5)
- # clojurescript (7)
- # data-science (2)
- # datahike (1)
- # datomic (39)
- # emacs (31)
- # events (2)
- # figwheel-main (1)
- # fulcro (15)
- # gratitude (8)
- # helix (17)
- # holy-lambda (1)
- # introduce-yourself (1)
- # jobs (3)
- # kaocha (2)
- # liquid (1)
- # malli (1)
- # nrepl (2)
- # other-languages (1)
- # portal (76)
- # react (19)
- # reagent (9)
- # remote-jobs (1)
- # rewrite-clj (9)
- # shadow-cljs (31)
- # tools-deps (5)
- # xtdb (11)
can anyone recommend me clojure source code formatting/indentation settings for mixed intellij/cursive and emacs/cider(/clojure-mode) teams?
lot of discussions has happened about it here: https://github.com/bbatsov/clojure-style-guide/issues/126
but no conclusion seems to be reached yet.
there is also tonsky's radically simpler solution https://tonsky.me/blog/clojurefmt/
which can already been achieved via cursive's Default to Only indent
+ Force Only Indent for all forms
setting (https://twitter.com/CursiveIDE/status/1070984513163997189)
i couldn't reproduce this simplified indentation in emacs, but i would be happy with any kind of auto-format-setting combinations, which yield equivalent results across these 2 specific environments.
i've considered using some external auto-formatter, like cljstyle
tried it with the options recommended here: https://bogoyavlensky.com/blog/clojure-formatting-cljstyle/
but it was not completely adhering to the simple tonsky-style, so i had to tweak it, which was a pain because it's based on cljfmt, but diverged from it.
anyway, the options are summarized here: https://github.com/greglook/cljstyle/blob/main/doc/configuration.md
and these settings - almost - worked for me:
$ cat .cljstyle
{:rules
{:indentation
{:indents
{#"^:?require$" [[:block 0]],
#"^:?import$" [[:block 0]],
#"^:?use$" [[:block 0]],
#"^[^ \[]" [[:inner 0]]}},
:vars {:enabled? false},
:functions {:enabled? false},
:namespaces {:enabled? false},
:blank-lines {:trim-consecutive? false
:insert-padding? false}}}
(:time-consecutive? and :insert-padding? r my additions)btw, cljstyle can be integrated with this small package:
(straight-use-package
'(cljstyle-mode :host github :type git :repo "jstokes/cljstyle-mode"))
and here is a direct link to it: https://github.com/jstokes/cljstyle-mode
Finally, I also realized that one thing is the full document (or only lines changed compared to version control) formatting but there is an other formatting, which is happening in a more localized way, during editing, which only affects the current or next line or the current lisp form.
this latter feature is commanded by completely different code, with different rules. think of stuff like tab-always-indent
, Electric Indent (https://www.gnu.org/software/emacs/manual/html_node/emacs/Indent-Convenience.html) minor mode, C-M-q (`indent-sexp`, or indent-pp-sexp
), indent-region
, indent-code-rigidly
, clojure-align
, clojure-indent-region
, etc. These features are exposed in different places in the different Emacs "distros", so i've noticed that users are not even aware of what package is providing the underlying functionality.
cljfmt
very nearly matches emacs (clojure-mode) and is actually used by cider (cider-format)
One certainly can make Cursive like cljfmt-like natively
Both emacs and cursive will need the occasional tweak to satisfy cljfmt. I think that's normal - it's bit of a fool's errand to try independent parties/technologies to agree on the same exact formatting rules
So an external process such as cljfmt is a simple 'arbiter' :)
cljfmt has a native image if you're into that sort of thing. You can also invoke it from a repl for avoiding startup time. cljstyle is a fork of cljfmt, IMO that wasn't classy and whatever it provides should be created as PRs against cljfmt if we want to keep the community simple instead of more fragmented.
(dubious) source: I help out maintaining cider, have contributed to cljfmt and also have authored a little framework for running formatters.
thank you for the insights! what formatter framework are you referring to? this one: https://github.com/nedap/formatting-stack/ ?
haha, yes when I authored it we had a mixed Cursive - Emacs team. worked well for us, it remains in use at that company and a few others. I'm not exactly promoting it yet though, there are things that could be made easier (@UHJH8MG6S is adding a plugin-like system to it, inspired by Kaocha)
Is there any command or something that move a pair or key and value of a map up and down? 🧵
Considering |
the cursor, running the command moving down for:
{:a 1
|:b 2
:c 3}
would result on:
{:a 1
:c 3
|:b 2}
I was going to suggest move-text-line-down
(and up) from the move-text
package. Not Clojure-aware, but I often find cljr slow and/or surprising. Great if it works well for this though.
Oh, sorry, move-text-up
is line or region, so probably works better than the line version
yeah, I was searching for something that doesn't need a region, just get the current cursor
I tried using mark-sexp
a couple of times, followed by move-text-up
, and the result wasn’t pretty - both pairs ended up on the same line, with the closing } on the line below.
I wonder if there’s a way to figure out how many sexps end on the current line, and slurp that many times
that looks easier to do with rewrite-clj, that's why I think adding that support for clojure-lsp would be useful
Yeah, it works, thanks for the help :) I'll probably implement that on clojure-lsp later anyway
Paxedit has a command paxedit-transpose-forward
/ backward
that implements this in maps and let bindings
good to know thks @UCPS050BV!