Fork me on GitHub
#emacs
<
2019-01-14
>
Bravi10:01:30

hi everyone. I’m trying to create a custom indentation in clojure mode, in my spacemacs. basically, I want to indent this

(rum/defc some-component
  < rum/static
  some/other-thing
  []
  ...)
like so
(rum/defc some-component
  < rum/static
    some/other-thing
  []
  ...)

Bravi10:01:59

can’t figure out how to. I keep fiddling with define-clojure-indent, but I’m not entirely sure how it works

Bravi10:01:13

maybe there’s an indentation master out there that could help me 😄

vemv12:01:17

Not familiar with Rum. Could the following...

< rum/static
    some/other-thing
hypothetically have this other syntax instead?
[< rum/static
    some/other-thing]
Would that make sense? If so, a version with delimiters would be easier to specify with define-clojure-indent

Bravi12:01:44

would you mind showing me an example of how to specify a delimiter please?

vemv12:01:58

One doesn't specify delimiters, but forms.

[< rum/static
    some/other-thing]
(with "delimiters") is 1 form, while
< rum/static
    some/other-thing
is 3 forms, which makes clojure-mode's work harder So my question is, would it make sense if Rum used [] syntax?

Bravi14:01:09

ah right I see. no, Rum doesn’t use that syntax unfortunately

vemv14:01:50

ok it doesn't, but does it have those semantics? I really don't know that < means in your original snippet

Bravi14:01:51

oh its Rum’s syntax. basically you define a component like so

(rum/defc hello-world [] [:div "hi])
and then you can add so called macros to it with this syntax
(rum/defc hello-world < some-macro []
  [:div "hi])

vemv14:01:13

Is the following valid?

(rum/defc hello-world < some-macro another-macro awesome-macro cosmic-macro []
  [:div "hi])

Bravi14:01:54

yes it is 🙂

Bravi14:01:18

if not that, perhaps you’d know how I can indent reagent’s with-let bindings. this is the code

(reagent/with-let [some-variable 1
                   other 2]
  (do-something "Hello world"))

Bravi14:01:18

and I want to align key value pairs inside [] basically

Bravi14:01:48

so for this to become

(reagent/with-let [some-variable 1
                   other 2]
  (do-something "Hello world"))

(reagent/with-let [some-variable 1
                   other         2]
  (do-something "Hello world"))

vemv14:01:37

> yes it is 🙂 so, I advice to create your own defc macro wrapper, which invokes the original but adds a [] syntax

vemv14:01:14

(bravi/defc hello-world [< some-macro another-macro awesome-macro cosmic-macro []]
  [:div "hi])
with that your original goal will become easier

Bravi14:01:44

ah got ya! thank you so much 🙂 I’ll play around with that now

Bravi15:01:13

this wouldn’t work, would it?

(defun clojurescript-indentations ()
  (append clojure-align-binding-forms
          '("reagent/with-let" "r/with-let")))


(add-hook 'clojurescript-mode-hook #'clojurescript-indentations)

vemv15:01:02

it should work you can also run (append clojure-align-binding-forms '("reagent/with-let" "r/with-let")) in an elisp repl to ensure that the code has run check that regular let is being aligned too, obviously if regular let isn't, others won't either

Bravi15:01:33

nice, thank you so much! 🙂 it works

🙌 5
mpenet11:01:55

any thoughts about use-package?

mpenet11:01:27

seems super neat to keep things organized and given who's the author I suspect it's probably quite cleanly done

theeternalpulse18:01:47

I used it mainly from the suggestions of this thread https://sam217pa.github.io/2016/09/02/how-to-build-your-own-spacemacs/ it's used extensively in spacemacs and I used it to follow the guide on my way to my own config

vemv12:01:19

also has the nice side-effect of speeding up Emacs startup 🙂 I don't happen to use it, but I'd say it wraps patterns that advanced Emacs users end up implementing themselves anyway.

mpenet12:01:12

I think my conf already does most of these optimisations

mpenet12:01:24

but still, for organisations sake it seems quite good

mpenet12:01:29

grouping stuff together

vemv12:01:34

I agree, would migrate my handcrafted stuff to u-p if I had the time or a strong reason (other than "tidying up")

mpenet12:01:11

yeah I am clearly looking for a yak to shave

😜 5
enn15:01:31

I love use-package. It makes it so much easier to set up a new machine too.