Skip to content

Commit 0bdc3d6

Browse files
committed
Fixed bug for large columns (deep recursion).
Switched to iteration. Fixes #4
1 parent ea8ff3d commit 0bdc3d6

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

doc/textobj-word-column.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ CHANGELOG *textobj-word-column-changelog*
9898
abcdef omg abc|def |omg abcdef| |omg
9999
abc omg abc| |omg abc | |omg
100100

101+
2012/08/05: Bug fix: Switched recursive function with iteration.

plugin/textobj/word-column.vim

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function! TextObjWordBasedColumn(textobj)
88
let start_col = virtcol("'<")
99
let stop_col = virtcol("'>")
1010
let line_num = line(".")
11-
let indent_level = s:indent_levell(".")
11+
let indent_level = s:indent_level(".")
1212
let start_line = s:find_boundary_row(line_num, start_col, indent_level, -1)
1313
let stop_line = s:find_boundary_row(line_num, start_col, indent_level, 1)
1414
let whitespace_only = s:whitespace_column_wanted(start_line, stop_line, cursor_col)
@@ -84,18 +84,27 @@ function! s:whitespace_column_wanted(start_line, stop_line, cursor_col)
8484
return 1
8585
endfunction
8686

87-
function! s:find_boundary_row(line_num, start_col, indent_level, step)
88-
let non_blank = getline(a:line_num + a:step) =~ "[^ \t]"
89-
let same_indent = s:indent_levell(a:line_num + a:step) == a:indent_level
90-
let is_not_comment = ! s:is_comment(a:line_num + a:step, a:start_col)
91-
if same_indent && non_blank && is_not_comment
92-
return s:find_boundary_row(a:line_num + a:step, a:start_col, a:indent_level, a:step)
93-
else
94-
return a:line_num
87+
function! s:find_boundary_row(start_line, start_col, indent_level, step)
88+
let current_line = a:start_line
89+
let max_boundary = 0
90+
if a:step == 1
91+
let max_boundary = line("$")
9592
endif
93+
while current_line != max_boundary
94+
let next_line = current_line + a:step
95+
let non_blank = getline(next_line) =~ "[^ \t]"
96+
let same_indent = s:indent_level(next_line) == a:indent_level
97+
let is_not_comment = ! s:is_comment(next_line, a:start_col)
98+
if same_indent && non_blank && is_not_comment
99+
let current_line = next_line
100+
else
101+
return current_line
102+
endif
103+
endwhile
104+
return max_boundary
96105
endfunction
97106

98-
function! s:indent_levell(line_num)
107+
function! s:indent_level(line_num)
99108
let line = getline(a:line_num)
100109
return match(line, "[^ \t]")
101110
endfunction

0 commit comments

Comments
 (0)