File tree Expand file tree Collapse file tree 2 files changed +37
-15
lines changed Expand file tree Collapse file tree 2 files changed +37
-15
lines changed Original file line number Diff line number Diff line change 110110(defn- string-node? [zloc]
111111 (= (some-> zloc z/node type) (type (nd/string-node " " ))))
112112
113+ (defn- remove-right-sibs
114+ [zloc]
115+ (u/remove-right-while zloc (constantly true )))
116+
113117; ;*****************************
114118; ; Paredit functions
115119; ;*****************************
116120
117121(defn kill
118- " Kill all sibling nodes to the right of the current node in `zloc`.
122+ " Returns `zloc` with the current node and all sibling nodes to the right removed.
123+ Locates `zloc` to node left of deleted node, else if no left node removes current node via [[rewrite-clj.zip/remove*]].
124+
125+ Makes no automatic whitespace adjustments.
119126
120- - `[1 2| 3 4] => [1 2|]`"
127+ - `[1 |2 3 4] => [1| ]`
128+ - `[1 2 |3 4] => [1 2| ]`
129+ - `[|1 2 3 4] => |[]`
130+ - `[ |1 2 3 4] => [| ]`"
121131 [zloc]
122- (let [left (z/left* zloc)]
123- (-> zloc
124- (u/remove-right-while (constantly true ))
125- z/remove*
126- (#(if left
127- (global-find-by-node % (z/node left))
128- %)))))
132+ (let [zloc (remove-right-sibs zloc)]
133+ (or (u/remove-and-move-left zloc)
134+ (z/remove* zloc))))
129135
130136(defn- kill-in-string-node [zloc pos]
131137 (if (= (z/string zloc) " \"\" " )
Original file line number Diff line number Diff line change 1717 (doseq [opts zipper-opts]
1818 (testing (zipper-opts-desc opts)
1919 (doseq [[s expected]
20- [[" [1⊚ 2 3 4] " " [⊚1] " ]
21- [" [ 1 2]⊚ ; useless comment " " ⊚[1 2] " ]
20+ [[" ⊚1 2 3 4" " ◬ " ]
21+ [" ⊚ 1 2 3 4 " " ⊚ " ]
2222 [" [⊚1 2 3 4]" " ⊚[]" ]
23+ [" [ ⊚1 2 3 4]" " [⊚ ]" ] ; ; 3 spaces are parsed as one node
24+ [" ⊚[]" " ◬" ]
25+ [" [1⊚ 2 3 4]" " [⊚1]" ]
26+ [" [1 ⊚2 3 4]" " [1⊚ ]" ]
27+ [" [1 2 ⊚3 4]" " [1 2⊚ ]" ]
28+ [" [1 2 3 ⊚4]" " [1 2 3⊚ ]" ]
29+ [" [1 2]⊚ ; some comment" " ⊚[1 2]" ]
2330 [" [⊚[1 2 3 4]]" " ⊚[]" ]
2431 [" [1 2 3 4]⊚ 2" " ⊚[1 2 3 4]" ]
25- [" ⊚[1 2 3 4] 5" " ◬" ]]]
26- (let [zloc (th/of-locmarked-string s opts)]
27- (is (= s (th/root-locmarked-string zloc)) " (sanity) before changes" )
28- (is (= expected (-> zloc pe/kill th/root-locmarked-string))))))))
32+ [" ⊚[1 2 3 4] 5" " ◬" ]
33+ [" [1 [2 3]⊚ 4 5]" " [1 ⊚[2 3]]" ]
34+ [" [1 [2 [3 [4]]]⊚ 5 6]" " [1 ⊚[2 [3 [4]]]]" ]
35+ [" [1\n [2⊚\n [3\n 4]\n 5]]" " [1\n [⊚2]]" ]
36+ [" [1\n [2\n [3 \n ⊚ 4]\n 5]]" " [1\n [2\n [3 ⊚\n ]\n 5]]" ]
37+ [" [ \n \n \n ⊚1 2 3 4]" " [ \n \n \n ⊚ ]" ]
38+ [" [ ⊚\n \n 1 2 3 4]" " [⊚ ]" ]
39+ [" [ \n ⊚\n 1 2 3 4]" " [ \n ⊚ ]" ] ; ; multiple spaces are a single node
40+ [" [ \n ⊚ \n 1 2 3 4]" " [ ⊚\n ]" ]]]
41+ (testing s
42+ (let [zloc (th/of-locmarked-string s opts)]
43+ (is (= s (th/root-locmarked-string zloc)) " (sanity) before changes" )
44+ (is (= expected (-> zloc pe/kill th/root-locmarked-string)))))))))
2945
3046(deftest kill-at-pos-test
3147 ; ; for this pos fn test, ⊚ in `s` represents character row/col for the `pos`
You can’t perform that action at this time.
0 commit comments