Skip to content

Commit 42ed507

Browse files
committed
Fix namespace buffer-local variable
Avoids name clashes with other plugins by renaming `b:root` to `b:stw_root`.
1 parent aeb68fa commit 42ed507

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
66
build:
@@ -12,7 +12,7 @@ jobs:
1212
vim: [vim, nvim]
1313

1414
steps:
15-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v2
1616
- name: Install Vim
1717
run: |
1818
case ${{ matrix.vim }} in

plugin/strip_trailing_whitespace.vim

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -78,85 +78,85 @@ function s:Splay(n, key) abort
7878
endfunction
7979

8080
function s:Put(key) abort
81-
if b:root is s:null
81+
if b:stw_root is s:null
8282
" Splay key to root
83-
let b:root = {'key': a:key, 'left': s:null, 'right': s:null}
83+
let b:stw_root = {'key': a:key, 'left': s:null, 'right': s:null}
8484
return
8585
endif
8686

87-
let b:root = s:Splay(b:root, a:key)
87+
let b:stw_root = s:Splay(b:stw_root, a:key)
8888

8989
" Insert new node at root
90-
let cmp = a:key - b:root.key
90+
let cmp = a:key - b:stw_root.key
9191
if cmp < 0
92-
let n = {'key': a:key, 'left': b:root.left, 'right': b:root}
93-
let b:root.left = s:null
94-
if n.left isnot s:null | let n.left.key += b:root.key - n.key | endif
92+
let n = {'key': a:key, 'left': b:stw_root.left, 'right': b:stw_root}
93+
let b:stw_root.left = s:null
94+
if n.left isnot s:null | let n.left.key += b:stw_root.key - n.key | endif
9595
let n.right.key -= n.key
96-
let b:root = n
96+
let b:stw_root = n
9797
elseif cmp > 0
98-
let n = {'key': a:key, 'left': b:root, 'right': b:root.right}
99-
let b:root.right = s:null
100-
if n.right isnot s:null | let n.right.key += b:root.key - n.key | endif
98+
let n = {'key': a:key, 'left': b:stw_root, 'right': b:stw_root.right}
99+
let b:stw_root.right = s:null
100+
if n.right isnot s:null | let n.right.key += b:stw_root.key - n.key | endif
101101
let n.left.key -= n.key
102-
let b:root = n
102+
let b:stw_root = n
103103
else
104104
" Duplicate key
105105
endif
106106
endfunction
107107

108108
function s:Remove(key) abort
109-
if b:root is s:null | return | endif " Empty tree
110-
let b:root = s:Splay(b:root, a:key)
109+
if b:stw_root is s:null | return | endif " Empty tree
110+
let b:stw_root = s:Splay(b:stw_root, a:key)
111111
" Check if key was in the tree
112-
if a:key != b:root.key | return | endif
112+
if a:key != b:stw_root.key | return | endif
113113

114-
if b:root.left is s:null
115-
let b:root = b:root.right
116-
if b:root isnot s:null | let b:root.key += a:key | endif
114+
if b:stw_root.left is s:null
115+
let b:stw_root = b:stw_root.right
116+
if b:stw_root isnot s:null | let b:stw_root.key += a:key | endif
117117
else
118-
let x = b:root.right
119-
let b:root = b:root.left
120-
if x isnot s:null | let x.key -= b:root.key | endif
121-
call s:Splay(b:root, a:key)
122-
let b:root.key += a:key
123-
let b:root.right = x
118+
let x = b:stw_root.right
119+
let b:stw_root = b:stw_root.left
120+
if x isnot s:null | let x.key -= b:stw_root.key | endif
121+
call s:Splay(b:stw_root, a:key)
122+
let b:stw_root.key += a:key
123+
let b:stw_root.right = x
124124
endif
125125
endfunction
126126

127127
" Removes the specified range of keys from the tree.
128128
"
129129
" {min} and {max} are inclusive line numbers defining the range to delete
130130
function s:RemoveRange(min, max) abort
131-
if b:root is s:null | return | endif
132-
let b:root = s:Splay(b:root, a:min)
131+
if b:stw_root is s:null | return | endif
132+
let b:stw_root = s:Splay(b:stw_root, a:min)
133133

134-
if b:root.right is s:null
135-
if b:root.key >= a:min && b:root.key <= a:max
136-
if b:root.left isnot s:null | let b:root.left.key += b:root.key | endif
137-
let b:root = b:root.left
134+
if b:stw_root.right is s:null
135+
if b:stw_root.key >= a:min && b:stw_root.key <= a:max
136+
if b:stw_root.left isnot s:null | let b:stw_root.left.key += b:stw_root.key | endif
137+
let b:stw_root = b:stw_root.left
138138
endif
139139
else
140140
" Do modified Hibbard deletion
141-
if b:root.key >= a:min && b:root.key <= a:max " Should remove root node but keep left subtree
142-
let rootkey = b:root.key
143-
let x = b:root.left
144-
let b:root = s:Splay(b:root.right, a:max - rootkey + 1)
145-
let b:root.left = x
141+
if b:stw_root.key >= a:min && b:stw_root.key <= a:max " Should remove root node but keep left subtree
142+
let rootkey = b:stw_root.key
143+
let x = b:stw_root.left
144+
let b:stw_root = s:Splay(b:stw_root.right, a:max - rootkey + 1)
145+
let b:stw_root.left = x
146146

147-
if x isnot s:null | let x.key -= b:root.key | endif
148-
let b:root.key += rootkey
147+
if x isnot s:null | let x.key -= b:stw_root.key | endif
148+
let b:stw_root.key += rootkey
149149

150150
call s:Remove(a:max) " Root could still be less than max
151151
else " Should keep root node and left subtree
152-
let b:root.right = s:Splay(b:root.right, a:max - b:root.key + 1)
153-
if b:root.right.key < a:max
154-
let b:root.right.left = s:null
152+
let b:stw_root.right = s:Splay(b:stw_root.right, a:max - b:stw_root.key + 1)
153+
if b:stw_root.right.key < a:max
154+
let b:stw_root.right.left = s:null
155155
else
156-
if b:root.right.right isnot s:null
157-
let b:root.right.right.key += b:root.right.key
156+
if b:stw_root.right.right isnot s:null
157+
let b:stw_root.right.right.key += b:stw_root.right.key
158158
endif
159-
let b:root.right = b:root.right.right
159+
let b:stw_root.right = b:stw_root.right.right
160160
endif
161161
endif
162162
endif
@@ -176,13 +176,13 @@ function StripTrailingWhitespaceListener(bufnr, start, end, added, changes) abor
176176
endif
177177

178178
" Adjust line numbers
179-
let b:root = s:Splay(b:root, a:start)
180-
if b:root isnot s:null
181-
if b:root.key >= a:start
182-
let b:root.key += a:added
183-
if b:root.left isnot s:null | let b:root.left.key -= a:added | endif
184-
elseif b:root.right isnot s:null
185-
let b:root.right.key += a:added
179+
let b:stw_root = s:Splay(b:stw_root, a:start)
180+
if b:stw_root isnot s:null
181+
if b:stw_root.key >= a:start
182+
let b:stw_root.key += a:added
183+
if b:stw_root.left isnot s:null | let b:stw_root.left.key -= a:added | endif
184+
elseif b:stw_root.right isnot s:null
185+
let b:stw_root.right.key += a:added
186186
endif
187187
endif
188188

@@ -196,9 +196,9 @@ function StripTrailingWhitespaceListener(bufnr, start, end, added, changes) abor
196196
endfunction
197197

198198
function s:OnBufEnter() abort
199-
if exists('b:root') | return | endif
199+
if exists('b:stw_root') | return | endif
200200

201-
let b:root = s:null
201+
let b:stw_root = s:null
202202
if has('nvim')
203203
lua vim.api.nvim_buf_attach(0, false, {
204204
\ on_lines = function(_, bufnr, _, firstline, lastline, new_lastline)
@@ -225,11 +225,11 @@ function s:OnWrite() abort
225225
let s:is_stripping = 1
226226
let save_cursor = getcurpos()
227227
try
228-
if b:root isnot s:null | call s:StripTree(b:root, 0) | endif
228+
if b:stw_root isnot s:null | call s:StripTree(b:stw_root, 0) | endif
229229
finally
230230
call setpos('.', save_cursor)
231231
let s:is_stripping = 0
232-
let b:root = s:null
232+
let b:stw_root = s:null
233233
endtry
234234
endfunction
235235

0 commit comments

Comments
 (0)