-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
173 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,6 @@ def supportsMulti(self): | |
def supportsNameOnly(self): | ||
return False | ||
|
||
def isFilePath(self): | ||
return True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,6 @@ def supportsMulti(self): | |
def supportsNameOnly(self): | ||
return False | ||
|
||
def isFilePath(self): | ||
return True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import vim | ||
import re | ||
import os | ||
import os.path | ||
from functools import wraps | ||
from leaderf.utils import * | ||
from leaderf.explorer import * | ||
from leaderf.manager import * | ||
from leaderf.mru import * | ||
|
||
|
||
#***************************************************** | ||
# TagExplorer | ||
#***************************************************** | ||
class TagExplorer(Explorer): | ||
def __init__(self): | ||
self._tag_list = [] | ||
|
||
def getContent(self, *args, **kwargs): | ||
if self._tag_list: | ||
return self._tag_list | ||
else: | ||
return self.getFreshContent() | ||
|
||
def getFreshContent(self, *args, **kwargs): | ||
self._tag_list = [] | ||
for tagfile in vim.eval("tagfiles()"): | ||
with lfOpen(os.path.abspath(tagfile), 'r', errors='ignore') as f: | ||
taglist = f.readlines() | ||
self._tag_list.extend(taglist[6:]) | ||
return self._tag_list | ||
|
||
def getStlCategory(self): | ||
return 'Tag' | ||
|
||
def getStlCurDir(self): | ||
return escQuote(lfEncode(os.getcwd())) | ||
|
||
def isFilePath(self): | ||
return False | ||
|
||
|
||
#***************************************************** | ||
# TagExplManager | ||
#***************************************************** | ||
class TagExplManager(Manager): | ||
def __init__(self): | ||
super(TagExplManager, self).__init__() | ||
self._match_ids = [] | ||
|
||
def _getExplClass(self): | ||
return TagExplorer | ||
|
||
def _defineMaps(self): | ||
lfCmd("call leaderf#tagExplMaps()") | ||
|
||
def _acceptSelection(self, *args, **kwargs): | ||
if len(args) == 0: | ||
return | ||
line = args[0] | ||
# {tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..] | ||
tagfile, right = line.split('\t', 2)[1:] | ||
tagaddress, tagfield = right.split(';"\t', 1) | ||
lfCmd("hide edit %s" % escSpecial(tagfile)) | ||
if tagaddress[0] != '/': | ||
lfCmd(tagaddress) | ||
else: | ||
lfCmd("norm! gg") | ||
pattern = "\M" + tagaddress[1:-1] | ||
lfCmd("call search('%s', 'w')" % escQuote(pattern)) | ||
lfCmd("norm! ^") | ||
|
||
def _getDigest(self, line, mode): | ||
""" | ||
specify what part in the line to be processed and highlighted | ||
Args: | ||
mode: 0, return the full path | ||
1, return the name only | ||
2, return the directory name | ||
""" | ||
if not line: | ||
return '' | ||
return line.split('\t', 1)[0] | ||
|
||
def _getDigestStartPos(self, line, mode): | ||
""" | ||
return the start position of the digest returned by _getDigest() | ||
Args: | ||
mode: 0, return the start postion of full path | ||
1, return the start postion of name only | ||
2, return the start postion of directory name | ||
""" | ||
return 0 | ||
|
||
def _createHelp(self): | ||
help = [] | ||
help.append('" <CR>/<double-click>/o : open file under cursor') | ||
help.append('" x : open file under cursor in a horizontally split window') | ||
help.append('" v : open file under cursor in a vertically split window') | ||
help.append('" t : open file under cursor in a new tabpage') | ||
help.append('" i : switch to input mode') | ||
help.append('" q : quit') | ||
help.append('" <F5> : refresh the cache') | ||
help.append('" <F1> : toggle this help') | ||
help.append('" ---------------------------------------------------------') | ||
return help | ||
|
||
def _afterEnter(self): | ||
super(TagExplManager, self)._afterEnter() | ||
id = int(lfEval('''matchadd('Lf_hl_tagFile', '^.\{-}\t\zs.\{-}\ze\t')''')) | ||
self._match_ids.append(id) | ||
id = int(lfEval('''matchadd('Lf_hl_tagType', ';"\t\zs[cdefFgmpstuv]\ze\(\t\|$\)')''')) | ||
self._match_ids.append(id) | ||
keyword = "\(class\|enum\|file\|function\|kind\|struct\|union\)" | ||
id = int(lfEval('''matchadd('Lf_hl_tagKeyword', ';"\t.\{-}\zs%s:\ze')''' % keyword)) | ||
self._match_ids.append(id) | ||
|
||
def _beforeExit(self): | ||
super(TagExplManager, self)._beforeExit() | ||
for i in self._match_ids: | ||
lfCmd("silent! call matchdelete(%d)" % i) | ||
self._match_ids = [] | ||
|
||
|
||
#***************************************************** | ||
# tagExplManager is a singleton | ||
#***************************************************** | ||
tagExplManager = TagExplManager() | ||
|
||
__all__ = ['tagExplManager'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters