Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions autoload/leaderf/Function.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,36 @@ function! leaderf#Function#Maps()
endif
endfunction

function! leaderf#Function#startExpl(win_pos, ...)
function! leaderf#Function#startExpl(win_pos, bang, ...)
if a:0 == 0
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."')")
if a:bang == 0
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."')")
else
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', bang = 1)")
endif
else
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."',"."1)")
if a:bang == 0
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."',"."1)")
else
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."',"."1, bang = 1)")
endif
endif
endfunction

function! leaderf#Function#startExplPattern(win_pos, all, pattern)
if a:all == 0
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', pattern='".a:pattern."')")
else
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', 1, pattern='".a:pattern."')")
endif
function! leaderf#Function#startExplPattern(win_pos, bang, all, pattern)
if a:all == 0
if a:bang == 0
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', pattern='".a:pattern."')")
else
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', pattern='".a:pattern."', bang = 1)")
endif
else
if a:bang == 0
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', 1, pattern='".a:pattern."')")
else
call leaderf#LfPy("functionExplManager.startExplorer('".a:win_pos."', 1, pattern='".a:pattern.", bang = 1')")
endif
endif
endfunction

function! leaderf#Function#removeCache(bufNum)
Expand Down
56 changes: 55 additions & 1 deletion autoload/leaderf/python/leaderf/functionExpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,32 @@ def _formatResult(self, buffer, result):
return []

func_list = []
sorted = True
lastln = -1

for _, item in enumerate(output):
bufname = buffer.name if vim.options["autochdir"] else lfRelpath(buffer.name)
try:
ln = int(item[2][:-2], 0)
except:
ln = -1
if lastln > ln:
sorted = False
else:
lastln = ln
line = "{}\t{}\t[{}:{} {}]".format(item[3],
buffer[int(item[2][:-2]) - 1].strip(),
bufname, # file
item[2][:-2], # line
buffer.number
)
func_list.append(line)

func_list.append((ln, line))

if not sorted:
func_list.sort()

func_list = [ line for ln, line in func_list ]
self._func_list[buffer.number] = func_list

return func_list
Expand Down Expand Up @@ -222,6 +238,42 @@ def _getDigest(self, line, mode):
else:
return line.rsplit("\t", 1)[1][1:-1]

def startExplorer(self, win_pos, *args, **kwargs):
super(FunctionExplManager, self).startExplorer(win_pos, *args, **kwargs)
if (not self._launched) or (len(args) > 0):
return
# a postfix bang sign, skip input() and locate cursor
if kwargs.get('bang', False):
self._relocateCursor()

def _pathEqual(self, p1, p2):
p1 = os.path.normcase(os.path.abspath(p1))
p2 = os.path.normcase(os.path.abspath(p2))
return (p1 == p2)

def _relocateCursor(self):
inst = self._getInstance()
orig_name = inst.getOriginalPos()[2].name
orig_line = inst.getOriginalCursor()[0]
tags = []
index = 0
for line in inst.buffer:
index += 1
line = line.rsplit("\t", 1)[1][1:-1]
filename = line.rsplit(':', 1)[0]
line_nr = int(line.rsplit(":", 1)[1].split()[0])
if self._pathEqual(lfDecode(orig_name), filename):
tags.append((index, filename, line_nr))
orig_line = int(orig_line)
last = len(tags) - 1
while last >= 0:
if tags[last][2] <= orig_line:
break
last -= 1
if last >= 0:
index = tags[last][0]
lfCmd(str(index))

def _getDigestStartPos(self, line, mode):
"""
return the start position of the digest returned by _getDigest()
Expand Down Expand Up @@ -300,3 +352,5 @@ def _previewResult(self, preview):
functionExplManager = FunctionExplManager()

__all__ = ['functionExplManager']

# vim: set ts=4 sw=4 tw=0 et :
6 changes: 6 additions & 0 deletions autoload/leaderf/python/leaderf/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def enterBuffer(self, win_pos):
return

self._orig_pos = (vim.current.tabpage, vim.current.window, vim.current.buffer)
self._orig_cursor = vim.current.window.cursor

self._before_enter()

Expand Down Expand Up @@ -284,3 +285,8 @@ def empty(self):

def getOriginalPos(self):
return self._orig_pos

def getOriginalCursor(self):
return self._orig_cursor

# vim: set ts=4 sw=4 tw=0 et :
6 changes: 5 additions & 1 deletion autoload/leaderf/python/leaderf/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,10 @@ def startExplorer(self, win_pos, *args, **kwargs):
pass
else:
self._getInstance().setBuffer(content)
self.input()
if not kwargs.get('bang', 0):
self.input()
else:
lfCmd("echo")
else:
if lfEval("g:Lf_CursorBlink") == '0':
self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent)
Expand Down Expand Up @@ -882,3 +885,4 @@ def input(self, content=None):
if self._cmdExtension(cmd):
break

# vim: set ts=4 sw=4 tw=0 et :
12 changes: 6 additions & 6 deletions plugin/leaderf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ command! -bar -nargs=0 LeaderfBufTagCword call leaderf#BufTag#startExplPattern(g
command! -bar -nargs=1 LeaderfBufTagAllPattern call leaderf#BufTag#startExplPattern(g:Lf_WindowPosition, 1, <q-args>)
command! -bar -nargs=0 LeaderfBufTagAllCword call leaderf#BufTag#startExplPattern(g:Lf_WindowPosition, 1, expand('<cword>'))

command! -bar -nargs=0 LeaderfFunction call leaderf#Function#startExpl(g:Lf_WindowPosition)
command! -bar -nargs=0 LeaderfFunctionAll call leaderf#Function#startExpl(g:Lf_WindowPosition, 1)
command! -bar -nargs=1 LeaderfFunctionPattern call leaderf#Function#startExplPattern(g:Lf_WindowPosition, 0, <q-args>)
command! -bar -nargs=0 LeaderfFunctionCword call leaderf#Function#startExplPattern(g:Lf_WindowPosition, 0, expand('<cword>'))
command! -bar -nargs=1 LeaderfFunctionAllPattern call leaderf#Function#startExplPattern(g:Lf_WindowPosition, 1, <q-args>)
command! -bar -nargs=0 LeaderfFunctionAllCword call leaderf#Function#startExplPattern(g:Lf_WindowPosition, 1, expand('<cword>'))
command! -bar -nargs=0 -bang LeaderfFunction call leaderf#Function#startExpl(g:Lf_WindowPosition, <bang>0)
command! -bar -nargs=0 -bang LeaderfFunctionAll call leaderf#Function#startExpl(g:Lf_WindowPosition, <bang>0, 1)
command! -bar -nargs=1 -bang LeaderfFunctionPattern call leaderf#Function#startExplPattern(g:Lf_WindowPosition, <bang>0, 0, <q-args>)
command! -bar -nargs=0 -bang LeaderfFunctionCword call leaderf#Function#startExplPattern(g:Lf_WindowPosition, <bang>0, 0, expand('<cword>'))
command! -bar -nargs=1 -bang LeaderfFunctionAllPattern call leaderf#Function#startExplPattern(g:Lf_WindowPosition, <bang>0, 1, <q-args>)
command! -bar -nargs=0 -bang LeaderfFunctionAllCword call leaderf#Function#startExplPattern(g:Lf_WindowPosition, <bang>0, 1, expand('<cword>'))

command! -bar -nargs=0 LeaderfLine call leaderf#Line#startExpl(g:Lf_WindowPosition)
command! -bar -nargs=0 LeaderfLineAll call leaderf#Line#startExpl(g:Lf_WindowPosition, 1)
Expand Down