clojure-mode icon indicating copy to clipboard operation
clojure-mode copied to clipboard

cond-> indenting incompatible with common nested -> use case

Open aengelberg opened this issue 8 years ago • 4 comments

Expected behavior

(-> obj
    (cond->
      pred1
      (do-a-thing)
      pred2
      (do-another-thing)))

Actual behavior

(-> obj
    (cond->
        pred1
      (do-a-thing)
      pred2
      (do-another-thing)))

Environment & Version information

clojure-mode version information

clojure-mode (version 5.5.2)

Emacs version

24.5.1

Operating system

Mac OS X El Capitan 10.11.3

aengelberg avatar Dec 13 '16 22:12 aengelberg

autogenerated with https://github.com/MalloZup/doghub: issue inactive since 450 days. Please update the issue or close it

MalloZup avatar Aug 05 '19 21:08 MalloZup

I guess this is basically the same as https://github.com/clojure-emacs/clojure-mode/issues/433

kommen avatar Aug 05 '19 21:08 kommen

Setting its indent spec to 'defun solves the problem:

  • (define-clojure-indent (cond-> 1)) ; default:
(-> obj
    (cond->
         pred1
      (do-a-thing)
      pred2
      (do-another-thing)))

(cond-> obj
  pred1
  (do-a-thing)
  pred2
  (do-another-thing)) 
  • (define-clojure-indent (cond-> 'defun)):
(-> obj
    (cond->
      pred1
      (do-a-thing)
      pred2
      (do-another-thing)))

(cond-> obj
  pred1
  (do-a-thing)
  pred2
  (do-another-thing))

j-cr avatar Dec 25 '19 16:12 j-cr

Doing (define-clojure-indent (as-> 'defun)) also sort of fixes #433:

(as-> 42 x
  (+ x 1))

(as-> (very-very-very-long-expr-prob-shouldnt-be-here)
  x
  (+ x 1))

(-> 123
    (+ 1)
    (as-> x
      (+ x 1)
      (- 1 x)))

j-cr avatar Dec 25 '19 16:12 j-cr