Skip to content

Commit 7138994

Browse files
committed
Fix mappings causing infinite loop in some cases
The `<Plug>` mappings in `plugin/man.vim` and some of the mappings specific to man page buffers (in fewer cases) can cause an infinite loop in the `remove_blank_lines_from_top_and_bottom` function. This can happen when `<cword` expands to the empty string inside `man#get_page_from_cword` or to anything else that will cause the function to call `man#get_page` with the empty strings as the last argument. E.g.: use `K` inside a man page buffer while the cursor is on an empty line. On my system, `manpage_exists` will return `1` because the output of `man -w` without extra arguments (`/usr/local/man:/usr/local/share/man:/usr/share/man` here) looks like a man page to it. `man#helpers#load_manpage_text` is then called with two empty strings and `r!/usr/bin/man 2>/dev/null | col -b` leaves the new buffer empty. Finally, `remove_blank_lines_from_top_and_bottom` goes into an infinite loop of trying to remove the only line in the buffer.
1 parent ed94a58 commit 7138994

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

autoload/man.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ function! man#get_page(split_type, ...)
4040
endfunction
4141

4242
function! s:manpage_exists(sect, page)
43+
if a:page ==# ''
44+
return 0
45+
endif
4346
let find_arg = man#helpers#find_arg()
4447
let where = system('/usr/bin/man '.find_arg.' '.man#helpers#get_cmd_arg(a:sect, a:page))
4548
if where !~# '^\s*/'

autoload/man/helpers.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ function! man#helpers#load_manpage_text(page, section)
7676
endfunction
7777

7878
function! s:remove_blank_lines_from_top_and_bottom()
79-
while getline(1) =~ '^\s*$'
79+
while line('$') > 1 && getline(1) =~ '^\s*$'
8080
silent keepj norm! ggdd
8181
endwhile
82-
while getline('$') =~ '^\s*$'
82+
while line('$') > 1 && getline('$') =~ '^\s*$'
8383
silent keepj norm! Gdd
8484
endwhile
8585
silent keepj norm! gg

0 commit comments

Comments
 (0)