Skip to content

Commit fe75732

Browse files
committed
[Fix #325] Fix indent for spliced reader conditionals
1 parent 84b752e commit fe75732

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

clojure-mode.el

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,18 @@ LAST-SEXP is the start of the previous sexp."
736736
(skip-chars-forward "[:blank:]")
737737
(current-column)))
738738

739+
(defun clojure--not-function-form-p ()
740+
"Non-nil if form at point doesn't represent a function call."
741+
(or (member (char-after) '(?\[ ?\{))
742+
(save-excursion ;; Catch #?@ (:cljs ...)
743+
(skip-chars-backward "\r\n[:blank:]")
744+
(when (eq (char-before) ?@)
745+
(forward-char -1))
746+
(and (eq (char-before) ?\?)
747+
(eq (char-before (1- (point))) ?\#)))
748+
;; Car of form is not a symbol.
749+
(not (looking-at ".\\(?:\\sw\\|\\s_\\)"))))
750+
739751
(defun clojure-indent-function (indent-point state)
740752
"When indenting a line within a function call, indent properly.
741753
@@ -763,12 +775,7 @@ This function also returns nil meaning don't specify the indentation."
763775
;; Goto to the open-paren.
764776
(goto-char (elt state 1))
765777
;; Maps, sets, vectors and reader conditionals.
766-
(if (or (member (char-after) '(?\[ ?\{))
767-
(and (eq (char-before) ?\?)
768-
(eq (char-before (1- (point))) ?\#))
769-
;; Car of form is not a symbol.
770-
(and (elt state 2)
771-
(not (looking-at ".\\sw\\|.\\s_"))))
778+
(if (clojure--not-function-form-p)
772779
(1+ (current-column))
773780
;; Function or macro call.
774781
(forward-char 1)

test/clojure-mode-indentation-test.el

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,45 @@ values of customisable variables."
262262
(x [_]
263263
1))")
264264

265+
(def-full-indent-test reader-conditionals
266+
"#?@ (:clj []
267+
:cljs [])")
268+
269+
270+
;;; Misc
271+
272+
(defun non-func (form-a form-b)
273+
(with-temp-buffer
274+
(clojure-mode)
275+
(insert form-a)
276+
(save-excursion (insert form-b))
277+
(clojure--not-function-form-p)))
278+
279+
(ert-deftest non-function-form ()
280+
(dolist (form '(("#?@ " "(c d)")
281+
("#?@" "(c d)")
282+
("#? " "(c d)")
283+
("#?" "(c d)")
284+
("" "[asda]")
285+
("" "{a b}")
286+
("#" "{a b}")
287+
("" "(~)")))
288+
(should (apply #'non-func form)))
289+
(dolist (form '("(c d)"
290+
"(.c d)"
291+
"(:c d)"
292+
"(c/a d)"
293+
"(.c/a d)"
294+
"(:c/a d)"
295+
"(c/a)"
296+
"(:c/a)"
297+
"(.c/a)"))
298+
(should-not (non-func "" form))
299+
(should-not (non-func "^hint" form))
300+
(should-not (non-func "#macro" form))
301+
(should-not (non-func "^hint " form))
302+
(should-not (non-func "#macro " form))))
303+
265304
(provide 'clojure-mode-indentation-test)
266305

267306
;; Local Variables:

0 commit comments

Comments
 (0)