summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--cider-interaction.el11
2 files changed, 10 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3146ef9f..5dae4288 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
* [cider-nrepl#438](https://github.com/clojure-emacs/cider-nrepl/pull/438): Improve startup time by deferring loading CIDER's middleware until the first usage.
* [#2078](https://github.com/clojure-emacs/cider/pull/2078): Improve startup time by bundling together sync requests during startup.
* `cider-rotate-default-connection` will warn if you use it with only a single active connection.
+* `cider-format-buffer` preserves the point position.
### Bugs Fixed
diff --git a/cider-interaction.el b/cider-interaction.el
index af5195aa..0c0a1f15 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -1771,8 +1771,15 @@ of the buffer into a formatted string."
(let* ((original (substring-no-properties (buffer-string)))
(formatted (funcall formatter original)))
(unless (equal original formatted)
- (erase-buffer)
- (insert formatted))))
+ (let ((current-line (line-number-at-pos))
+ (current-column (current-column)))
+ (erase-buffer)
+ (insert formatted)
+ ;; we have to preserve our point location in the buffer,
+ ;; but save-excursion doesn't work, because of erase-buffer
+ (goto-char (point-min))
+ (forward-line (1- current-line))
+ (forward-char current-column)))))
(defun cider-format-buffer ()
"Format the Clojure code in the current buffer."