File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ non-functioning `cider-test-jump` from test reports.
32
32
` user ` namespace when using ` cider-interactive-eval ` .
33
33
* [ #954 ] ( https://github.com/clojure-emacs/cider/issues/954 ) : Detect properly a project's root
34
34
when in buffer that's not visiting a file (e.g. a REPL buffer).
35
+ * [ #977 ] ( https://github.com/clojure-emacs/cider/issues/977 ) : ` cider-format-region ` now respects indentation of the region start position
35
36
36
37
## 0.8.2 / 2014-12-21
37
38
Original file line number Diff line number Diff line change @@ -1794,17 +1794,24 @@ of the buffer into a formatted string."
1794
1794
(cider--format-buffer (lambda (edn )
1795
1795
(cider-sync-request:format-edn edn fill-column))))
1796
1796
1797
+ (defun cider--format-reindent (formatted start )
1798
+ " Reindent FORMATTED to align with buffer position START."
1799
+ (let* ((start-column (save-excursion (goto-char start) (current-column )))
1800
+ (indent-line (concat " \n " (make-string start-column ? ))))
1801
+ (replace-regexp-in-string " \n " indent-line formatted)))
1802
+
1797
1803
(defun cider--format-region (start end formatter )
1798
1804
" Format the contents of the given region.
1799
1805
1800
1806
START and END are the character positions of the start and end of the
1801
1807
region. FORMATTER is a function of one argument which is used to convert
1802
1808
the string contents of the region into a formatted string."
1803
1809
(let* ((original (buffer-substring-no-properties start end))
1804
- (formatted (funcall formatter original)))
1810
+ (formatted (funcall formatter original))
1811
+ (indented (cider--format-reindent formatted start)))
1805
1812
(unless (equal original indented)
1806
1813
(delete-region start end)
1807
- (insert formatted ))))
1814
+ (insert indented ))))
1808
1815
1809
1816
(defun cider-format-region (start end )
1810
1817
" Format the Clojure code in the current region."
You can’t perform that action at this time.
0 commit comments