@@ -1564,10 +1564,17 @@ current sexp."
1564
1564
:safe #'booleanp
1565
1565
:type 'boolean )
1566
1566
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
+
1567
1573
(defun clojure--unwind-last ()
1568
1574
(forward-sexp )
1569
1575
(save-excursion
1570
- (let ((contents (clojure-delete-and-extract-sexp)))
1576
+ (let ((beg (point ))
1577
+ (contents (clojure-delete-and-extract-sexp)))
1571
1578
(when (looking-at " *\n " )
1572
1579
(join-line 'following ))
1573
1580
(clojure--ensure-parens-around-function-names)
@@ -1576,11 +1583,14 @@ current sexp."
1576
1583
(line-number-at-pos )))
1577
1584
(multiline-sexp-p (not (= sexp-beg-line sexp-end-line))))
1578
1585
(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))
1581
1592
(insert contents)
1582
- (when multiline-sexp-p
1583
- (clojure-indent-line)))))
1593
+ (clojure-indent-region beg (point )))))
1584
1594
(forward-char ))
1585
1595
1586
1596
(defun clojure--ensure-parens-around-function-names ()
@@ -1682,7 +1692,9 @@ Return nil if there are no more levels to unwind."
1682
1692
(clojure--remove-superfluous-parens)
1683
1693
; ; cljr #255 Fix dangling parens
1684
1694
(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 ))
1686
1698
(join-line ))
1687
1699
t )))
1688
1700
0 commit comments