Skip to content

Commit 7dddb5b

Browse files
committed
Add suppress-redisplay? optional arg to clojure-sort-ns
This avoids unwanted flicker when jumping from current location to ns form and back. Espeically useful when `clojure-sort-ns` is called from `before-save-hook`, and would otherwise distract the user.
1 parent 75c2889 commit 7dddb5b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* [#571](https://github.com/clojure-emacs/clojure-mode/issues/571): Remove `project.el` integration.
88
* [#574](https://github.com/clojure-emacs/clojure-mode/issues/574): Remove `clojure-view-grimoire` command.
9+
* `clojure-sort-ns` now takes an optional `suppress-redispaly?` arg to prevent jumping to ns form and back
910

1011
## 5.12.0 (2020-08-13)
1112

clojure-mode.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,14 +1820,15 @@ content) are considered part of the preceding sexp."
18201820
(when (nth 4 (parse-partial-sexp (point-min) (point)))
18211821
(insert "\n"))))
18221822

1823-
(defun clojure-sort-ns ()
1824-
"Internally sort each sexp inside the ns form."
1823+
(defun clojure-sort-ns (&optional suppress-redisplay?)
1824+
"Internally sort each sexp inside the ns form.
1825+
Jump to the ns form and back if SUPPRESS-REDISPLAY? is nil"
18251826
(interactive)
18261827
(comment-normalize-vars)
18271828
(if (clojure-find-ns)
18281829
(save-excursion
18291830
(goto-char (match-beginning 0))
1830-
(redisplay)
1831+
(unless suppress-redisplay? (redisplay))
18311832
(let ((beg (point))
18321833
(ns))
18331834
(forward-sexp 1)
@@ -1843,7 +1844,7 @@ content) are considered part of the preceding sexp."
18431844
(if (looking-at (regexp-quote ns))
18441845
(message "ns form is already sorted")
18451846
(sleep-for 0.1)
1846-
(redisplay)
1847+
(unless suppress-redisplay? (redisplay))
18471848
(message "ns form has been sorted")
18481849
(sleep-for 0.1))))
18491850
(user-error "Can't find ns form")))

0 commit comments

Comments
 (0)