Skip to content

Commit ff80efb

Browse files
author
Yannick Scherer
committed
deprecate/rename whitespace append/prepend functions (closes #36).
1 parent 1964353 commit ff80efb

File tree

2 files changed

+66
-22
lines changed

2 files changed

+66
-22
lines changed

src/rewrite_clj/zip/whitespace.clj

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,68 @@
4040

4141
;; ## Insertion
4242

43-
(defn prepend-space
44-
"Prepend a whitespace node representing the given number of spaces (default: 1)."
45-
([zloc] (prepend-space zloc 1))
43+
(defn ^{:added "0.5.0"} insert-space-left
44+
"Insert a whitespace node before the given one, representing the given
45+
number of spaces (default: 1)."
46+
([zloc] (insert-space-left zloc 1))
4647
([zloc n]
4748
{:pre [(>= n 0)]}
4849
(if (pos? n)
4950
(z/insert-left zloc (node/spaces n))
5051
zloc)))
5152

52-
(defn append-space
53-
"Append a whitespace node representing the given number of spaces (default: 1)."
54-
([zloc] (append-space zloc 1))
53+
(defn ^{:added "0.5.0"} insert-space-right
54+
"Insert a whitespace node after the given one, representing the given number
55+
of spaces (default: 1)."
56+
([zloc] (insert-space-right zloc 1))
5557
([zloc n]
5658
{:pre [(>= n 0)]}
5759
(if (pos? n)
5860
(z/insert-right zloc (node/spaces n))
5961
zloc)))
6062

61-
(defn prepend-newline
62-
"Prepend a whitespace node representing the given number of spaces (default: 1)."
63-
([zloc] (prepend-newline zloc 1))
63+
(defn ^{:added "0.5.0"} insert-newline-left
64+
"Insert a newline node before the given one, representing the given number of
65+
spaces (default: 1)."
66+
([zloc] (insert-newline-left zloc 1))
6467
([zloc n]
6568
(z/insert-left zloc (node/newlines n))))
6669

67-
(defn append-newline
68-
"Append a whitespace node representing the given number of spaces (default: 1)."
69-
([zloc] (append-newline zloc 1))
70+
(defn ^{:added "0.5.0"} insert-newline-right
71+
"Insert a newline node after the given one, representing the given number of
72+
linebreaks (default: 1)."
73+
([zloc] (insert-newline-right zloc 1))
7074
([zloc n]
7175
(z/insert-right zloc (node/newlines n))))
76+
77+
;; ## Deprecated Functions
78+
79+
(defn ^{:deprecated "0.5.0"} prepend-space
80+
"Prepend a whitespace node representing the given number of spaces (default: 1).
81+
82+
DEPRECATED: use 'insert-space-left' instead."
83+
[zloc & [n]]
84+
(insert-space-left zloc (or n 1)))
85+
86+
(defn ^{:deprecated "0.5.0"} append-space
87+
"Append a whitespace node representing the given number of spaces (default: 1).
88+
89+
DEPRECATED: use 'insert-space-right' instead."
90+
[zloc & [n]]
91+
(insert-space-right zloc (or n 1)))
92+
93+
(defn ^{:deprecated "0.5.0"} prepend-newline
94+
"Prepend a newline node representing the given number of linebreaks (default:
95+
1).
96+
97+
DEPRECATED: use 'insert-newline-left' instead."
98+
[zloc & [n]]
99+
(insert-newline-left zloc (or n 1)))
100+
101+
(defn ^{:deprecated "0.5.0"} append-newline
102+
"Append a newline node representing the given number of linebreaks (default:
103+
1).
104+
105+
DEPRECATED: use 'insert-newline-right' instead."
106+
[zloc & [n]]
107+
(insert-newline-right zloc (or n 1)))

test/rewrite_clj/zip/whitespace_test.clj

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@
2727
(let [n (->> loc z/down (skip-whitespace z/next) z/node)]
2828
(node/tag n) => :token
2929
(node/sexpr n) => 0))
30-
(fact "about prepending/appending spaces."
31-
(let [n (-> loc z/down z/rightmost (prepend-space 3))]
32-
(base/root-string n) => " \n0 1 ;comment")
33-
(let [n (-> loc z/down z/rightmost (append-space 3))]
34-
(base/root-string n) => " \n0 1;comment "))
35-
(fact "about prepending/appending linebreaks."
36-
(let [n (-> loc z/down z/rightmost (prepend-newline 3))]
37-
(base/root-string n) => " \n0 1\n\n\n;comment")
38-
(let [n (-> loc z/down z/rightmost (append-newline 3))]
39-
(base/root-string n) => " \n0 1;comment\n\n\n")))
30+
(tabular
31+
(fact "about prepending/appending spaces."
32+
(let [n (-> loc z/down z/rightmost (?left-fn 3))]
33+
(base/root-string n) => " \n0 1 ;comment")
34+
(let [n (-> loc z/down z/rightmost (?right-fn 3))]
35+
(base/root-string n) => " \n0 1;comment "))
36+
?left-fn ?right-fn
37+
prepend-space append-space
38+
insert-space-left insert-space-right)
39+
(tabular
40+
(fact "about prepending/appending linebreaks."
41+
(let [n (-> loc z/down z/rightmost (prepend-newline 3))]
42+
(base/root-string n) => " \n0 1\n\n\n;comment")
43+
(let [n (-> loc z/down z/rightmost (append-newline 3))]
44+
(base/root-string n) => " \n0 1;comment\n\n\n"))
45+
?left-fn ?right-fn
46+
prepend-newline append-newline
47+
insert-newline-left insert-newline-right))

0 commit comments

Comments
 (0)