@@ -1564,10 +1564,17 @@ current sexp."
15641564 :safe #'booleanp
15651565 :type 'boolean )
15661566
1567+ (defun clojure--maybe-unjoin-line ()
1568+ " Undo a `join-line' done by a threading command."
1569+ (when (get-text-property (point ) 'clojure-thread-line-joined )
1570+ (remove-text-properties (point ) (1+ (point )) '(clojure-thread-line-joined t ))
1571+ (newline-and-indent )))
1572+
15671573(defun clojure--unwind-last ()
15681574 (forward-sexp )
15691575 (save-excursion
1570- (let ((contents (clojure-delete-and-extract-sexp)))
1576+ (let ((beg (point ))
1577+ (contents (clojure-delete-and-extract-sexp)))
15711578 (when (looking-at " *\n " )
15721579 (join-line 'following ))
15731580 (clojure--ensure-parens-around-function-names)
@@ -1576,11 +1583,14 @@ current sexp."
15761583 (line-number-at-pos )))
15771584 (multiline-sexp-p (not (= sexp-beg-line sexp-end-line))))
15781585 (down-list -1 )
1579- (when multiline-sexp-p
1580- (newline ))
1586+ (if multiline-sexp-p
1587+ (newline )
1588+ ; ; `clojure--maybe-unjoin-line' only works when unwinding sexps that were
1589+ ; ; threaded in the same Emacs session, but it also catches cases that
1590+ ; ; `multiline-sexp-p' doesn't.
1591+ (clojure--maybe-unjoin-line))
15811592 (insert contents)
1582- (when multiline-sexp-p
1583- (clojure-indent-line)))))
1593+ (clojure-indent-region beg (point )))))
15841594 (forward-char ))
15851595
15861596(defun clojure--ensure-parens-around-function-names ()
@@ -1682,7 +1692,9 @@ Return nil if there are no more levels to unwind."
16821692 (clojure--remove-superfluous-parens)
16831693 ; ; cljr #255 Fix dangling parens
16841694 (forward-sexp )
1685- (when (looking-back " ^\\ s-*)+\\ s-*" (line-beginning-position ))
1695+ (when (looking-back " ^\\ s-*\\ ()+\\ )\\ s-*" (line-beginning-position ))
1696+ (let ((pos (match-beginning 1 )))
1697+ (put-text-property pos (1+ pos) 'clojure-thread-line-joined t ))
16861698 (join-line ))
16871699 t )))
16881700
0 commit comments