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 110
110
(defn- string-node? [zloc]
111
111
(= (some-> zloc z/node type) (type (nd/string-node " " ))))
112
112
113
+ (defn- remove-right-sibs
114
+ [zloc]
115
+ (u/remove-right-while zloc (constantly true )))
116
+
113
117
; ;*****************************
114
118
; ; Paredit functions
115
119
; ;*****************************
116
120
117
121
(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.
119
126
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] => [| ]`"
121
131
[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))))
129
135
130
136
(defn- kill-in-string-node [zloc pos]
131
137
(if (= (z/string zloc) " \"\" " )
Original file line number Diff line number Diff line change 17
17
(doseq [opts zipper-opts]
18
18
(testing (zipper-opts-desc opts)
19
19
(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 " " ⊚ " ]
22
22
[" [⊚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]" ]
23
30
[" [⊚[1 2 3 4]]" " ⊚[]" ]
24
31
[" [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)))))))))
29
45
30
46
(deftest kill-at-pos-test
31
47
; ; 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