Fork me on GitHub

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: but no conclusion seems to be reached yet. there is also tonsky's radically simpler solution which can already been achieved via cursive's Default to Only indent + Force Only Indent for all forms setting ( 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: 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: and these settings - almost - worked for me:

$ cat .cljstyle                         
   {#"^:?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:

 '(cljstyle-mode :host github :type git :repo "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 ( 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.


in summary, please HELP! 😄 by sharing your experience and settings


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: ?


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)

🙏 1

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 found cljr--move-line-down that works perfectly


and cljr--move-line-up


probably a clojure-lsp command for that would be cool as well for other editors :)


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.


actually, cljr doesn't work quite well if the pair is on the end of the map :(


like moving up this:

{:a 1
 :b 2
|:c 3}
will result in
{:a 1
|:c 3}
 :b 2


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


mark-sexp x2, then sp-transpose-hybrid-sexp seems to work


For moving up from the end, anyway. I’m not sure how to generalise it though.


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!


I've had mixed results trying to integrate it into my workflow though, paxedit's conventions about cursor placement just aren't very intuitive when used with other structured editing modes - it probably works well if you adopt their entire editing paradigm


im using this feature too, often enough in cursive to really miss it from emacs 🙂 never heard about paxedit before, thanks for mentioning it!