Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bugs fixed

* [#551](https://github.com/clojure-emacs/clojure-mode/issues/551): Indent `clojure-align` region before aligning.
* [#520](https://github.com/clojure-emacs/clojure-mode/issues/508): Fix allow `clojure-align-cond-forms` to recognize qualified forms.
* Enhance add arity refactoring to support a defn inside a reader conditional.
* [#404](https://github.com/clojure-emacs/clojure-mode/issues/404)/[#528]((https://github.com/clojure-emacs/clojure-mode/issues/528)) Fix syntax highlighting for multiple consecutive comment reader macros (`#_#_`)
Expand Down
7 changes: 4 additions & 3 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1268,15 +1268,16 @@ When called from lisp code align everything between BEG and END."
(save-excursion
(while (search-forward-regexp "^ *\n" sexp-end 'noerror)
(cl-incf count)))
;; Pre-indent the region to avoid aligning to improperly indented
;; contents (#551). Also fixes #360.
(indent-region (point) sexp-end)
(dotimes (_ count)
(align-region (point) sexp-end nil
`((clojure-align (regexp . clojure--search-whitespace-after-next-sexp)
(group . 1)
(separate . ,clojure-align-separator)
(repeat . t)))
nil))
;; Reindent after aligning because of #360.
(indent-region (point) sexp-end)))))
nil))))))

;;; Indentation
(defun clojure-indent-region (beg end)
Expand Down
7 changes: 7 additions & 0 deletions test/clojure-mode-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ x
"#?@(:clj [2]
:cljs [2])")

(it "should handle improperly indented content"
(let ((content "(let [a-long-name 10\nb 20])")
(aligned-content "(let [a-long-name 10\n b 20])"))
(with-clojure-buffer content
(call-interactively #'clojure-align)
(expect (buffer-string) :to-equal aligned-content))))

(it "should not align reader conditionals by default"
(let ((content "#?(:clj 2\n :cljs 2)"))
(with-clojure-buffer content
Expand Down