~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to runtime/autoload/man.vim

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
  " Ignore the error in restricted mode
12
12
endtry
13
13
 
 
14
" Load man page {page} from {section}
 
15
"   call man#get_page([{section}, ]{page})
14
16
function man#get_page(...) abort
15
17
  let invoked_from_man = (&filetype ==# 'man')
16
18
 
20
22
  elseif a:0 > 2
21
23
    echoerr 'too many arguments'
22
24
    return
23
 
  elseif a:0 == 2
24
 
    let [page, sect] = [a:2, 0 + a:1]
25
 
  elseif type(1) == type(a:1)
26
 
    let [page, sect] = ['<cword>', a:1]
27
 
  else
28
 
    let [page, sect] = [a:1, '']
29
25
  endif
30
26
 
31
 
  if page == '<cword>'
32
 
    let page = expand('<cword>')
33
 
  endif
 
27
  let sect = get(a:000, 0)
 
28
  let page = get(a:000, 1, sect)
34
29
 
35
30
  let [page, sect] = s:parse_page_and_section(sect, page)
36
31
 
37
 
  if 0 + sect > 0 && s:find_page(sect, page) == 0
 
32
  if !empty(sect) && s:find_page(sect, page) == 0
38
33
    let sect = ''
39
34
  endif
40
35
 
54
49
    let thiswin = winnr()
55
50
    wincmd b
56
51
    if winnr() > 1
57
 
      exe "norm! " . thiswin . "\<C-W>w"
 
52
      exec thiswin . 'wincmd w'
58
53
      while 1
59
 
        if &filetype == 'man'
 
54
        if &filetype ==# 'man'
60
55
          break
61
56
        endif
62
57
        wincmd w
80
75
  endif
81
76
  silent exec 'r!/usr/bin/man '.s:cmd(sect, page).' | col -b'
82
77
  " Remove blank lines from top and bottom.
83
 
  while getline(1) =~ '^\s*$'
84
 
    silent keepjumps norm! gg"_dd
 
78
  while getline(1) =~# '^\s*$'
 
79
    silent keepjumps 1delete _
85
80
  endwhile
86
 
  while getline('$') =~ '^\s*$'
87
 
    silent keepjumps norm! G"_dd
 
81
  while getline('$') =~# '^\s*$'
 
82
    silent keepjumps $delete _
88
83
  endwhile
89
84
  setlocal nomodified
90
85
  setlocal filetype=man
118
113
" Expects a string like 'access' or 'access(2)'.
119
114
function s:parse_page_and_section(sect, str) abort
120
115
  try
121
 
    let save_isk = &iskeyword
122
 
    setlocal iskeyword-=(,)
123
 
    let page = substitute(a:str, '(*\(\k\+\).*', '\1', '')
124
 
    let sect = substitute(a:str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
125
 
    if sect == page || -1 == match(sect, '^[0-9 ]\+$')
 
116
    let [page, sect] = matchlist(a:str, '\v\C([-.[:alnum:]_]+)%(\(([-.[:alnum:]_]+)\))?')[1:2]
 
117
    if empty(sect)
126
118
      let sect = a:sect
127
119
    endif
128
120
  catch
129
 
    let &l:iskeyword = save_isk
130
121
    echoerr 'man.vim: failed to parse: "'.a:str.'"'
131
122
  endtry
132
123
 
134
125
endfunction
135
126
 
136
127
function s:cmd(sect, page) abort
137
 
  if 0 + a:sect > 0
 
128
  if !empty(a:sect)
138
129
    return s:man_sect_arg.' '.a:sect.' '.a:page
139
130
  endif
140
131
  return a:page
142
133
 
143
134
function s:find_page(sect, page) abort
144
135
  let where = system('/usr/bin/man '.s:man_find_arg.' '.s:cmd(a:sect, a:page))
145
 
  if where !~ "^/"
146
 
    if matchstr(where, " [^ ]*$") !~ "^ /"
147
 
      return 0
148
 
    endif
149
 
  endif
150
 
  return 1
 
136
  return (where =~# '^ */')
151
137
endfunction