Retrieve ns for arbitrary buffer

This commit is contained in:
Tim Pope 2014-01-10 23:31:47 -05:00
parent 56d667b7d5
commit cf094f970f

View File

@ -1068,7 +1068,7 @@ augroup END
" Documentation {{{1 " Documentation {{{1
function! s:buffer_path(...) abort function! s:buffer_path(...) abort
let buffer = a:0 ? a:1 : exists('s:input') ? s:input : '%' let buffer = a:0 ? a:1 : s:buf()
if getbufvar(buffer, '&buftype') =~# '^no' if getbufvar(buffer, '&buftype') =~# '^no'
return '' return ''
endif endif
@ -1083,16 +1083,16 @@ function! s:buffer_path(...) abort
return '' return ''
endfunction endfunction
function! fireplace#ns() abort function! fireplace#ns(...) abort
if exists('b:fireplace_ns') let buffer = a:0 ? a:1 : s:buf()
return b:fireplace_ns if getbufvar(buffer, 'fireplace_ns')
return getbufvar(buffer, 'fireplace_ns')
endif endif
let lnum = 1 let head = getbufline(buffer, 1, 500)
while lnum < line('$') && getline(lnum) =~# '^\s*\%(;.*\)\=$' let blank = '^\s*\%(;.*\)\=$'
let lnum += 1 call filter(head, 'v:val !~# blank')
endwhile
let keyword_group = '[A-Za-z0-9_?*!+/=<>.-]' let keyword_group = '[A-Za-z0-9_?*!+/=<>.-]'
let lines = join(getline(lnum, lnum+50), ' ') let lines = join(head[0:49], ' ')
let lines = substitute(lines, '"\%(\\.\|[^"]\)*"\|\\.', '', 'g') let lines = substitute(lines, '"\%(\\.\|[^"]\)*"\|\\.', '', 'g')
let lines = substitute(lines, '\^\={[^{}]*}', '', '') let lines = substitute(lines, '\^\={[^{}]*}', '', '')
let lines = substitute(lines, '\^:'.keyword_group.'\+', '', 'g') let lines = substitute(lines, '\^:'.keyword_group.'\+', '', 'g')
@ -1100,11 +1100,8 @@ function! fireplace#ns() abort
if ns !=# '' if ns !=# ''
return ns return ns
endif endif
if has_key(s:qffiles, expand('%:p')) let path = s:buffer_path(buffer)
return s:qffiles[expand('%:p')].ns return s:to_ns(path ==# '' ? fireplace#client(buffer).user_ns() : path)
endif
let path = s:buffer_path()
return s:to_ns(path ==# '' ? fireplace#client().user_ns() : path)
endfunction endfunction
function! s:Lookup(ns, macro, arg) abort function! s:Lookup(ns, macro, arg) abort