added search-tags, abc for tag commands, and fixed auto-initialization of TAGS

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2010-08-17 07:47:52 -04:00
parent 2f67f708cd
commit 0fc98f894a
4 changed files with 73 additions and 16 deletions

View File

@ -1089,7 +1089,7 @@ class Application(object):
def get_minibuffer_lines(self):
lines2 = []
if self.error_string:
if self.error_string and False:
maxlen = self.config['max_error_len']
if len(self.error_string) < maxlen:
s = self.error_string

View File

@ -30,6 +30,9 @@ class TagManager(object):
def get(self, name):
return self.etags.tag_map.get(name, [])
def list(self):
return self.etags.record_list
def update(self):
if self.is_outdated():
self.run()

View File

@ -4,16 +4,71 @@ import completer
from etags import TagManager
import default
class FindTag(Method):
args = [arg('tag', p='Tag name: ', dv=default.current_token, ld=True, h='Search for a tag')]
class TagBase(Method):
_is_method = False
def _setup(self, w, vargs):
InitTags().execute(w)
if 'tag-base' in w.buffer.settings[w.mode.name]:
base = w.buffer.settings[w.mode.name].get('tag-base')
manager = w.application.state['tags'][base]
return base, manager
else:
w.application.mini_buffer.add_callback(self._resume)
self._old_window = w
self._old_vargs = vargs
return None, None
def _resume(self, s):
self._execute(self._old_window, **self._old_vargs)
def _goto_record(self, w, r):
b = w.application.open_path(r.path)
w.application.switch_buffer(b)
b.windows[0].goto_line(r.line)
def _display_records(self, records):
cwd = os.getcwd()
if not cwd.endswith('/'):
cwd += '/'
tpls = [(r.path.replace(cwd, ''), r.line, r.defn) for r in records]
data = '\n'.join(['%s:%d:%s' % tpl for tpl in tpls]) + '\n'
return data
class SearchTags(TagBase):
_is_method = True
args = [arg('query', p='Query: ', h='Search all tags')]
def _execute(self, w, **vargs):
query = vargs['query']
b = w.buffer
a = w.application
base, m = self._setup(w, vargs)
if base is None:
return
records = [r for r in m.etags.record_list if query in r.name]
if len(records) == 0:
w.set_error('no records matched query %r' % query)
return
data = self._display_records(records)
a.data_buffer("*Tag-Records*", data, switch_to=True, modename='error')
w.set_error('found %d records for query %r' % (len(records), query))
class FindTag(TagBase):
_is_method = True
args = [arg('tag', p='Tag name: ', dv=default.current_token, ld=True,
h='Search for a tag')]
def _execute(self, w, **vargs):
tag = vargs['tag']
b = w.buffer
a = w.application
InitTags().execute(w)
base = b.settings[w.mode.name].get('tag-base')
m = a.state['tags'][base]
base, m = self._setup(w, vargs)
if base is None:
return
records = m.get(tag)
if not records:
@ -21,19 +76,11 @@ class FindTag(Method):
return
if len(records) == 1:
b = a.open_path(records[0].path)
a.switch_buffer(b)
b.windows[0].goto_line(records[0].line)
self._goto_record(w, records[0])
w.set_error('found one record for tag %r' % tag)
return
cwd = os.getcwd()
if not cwd.endswith('/'):
cwd += '/'
tpls = [(r.path.replace(cwd, ''), r.line, r.defn) for r in records]
data = '\n'.join(['%s:%d:%s' % tpl for tpl in tpls]) + '\n'
data = self._display_records(records)
a.data_buffer("*Tag-Records*", data, switch_to=True, modename='error')
w.set_error('found %d records for tag %r' % (len(records), tag))
@ -83,6 +130,7 @@ class InitTags(Method):
self._prompt = "Enter source directory: "
c = completer.get_completer('path')
d = os.path.dirname(w.buffer.path)
a.clear_error() #xyz
a.open_mini_buffer(self._prompt, self._cb, tabber=c, startvalue=d)
def _cb(self, v):

View File

@ -26,6 +26,12 @@ class MiniBuffer(buffer.Buffer):
def name(self):
return "*Minibuffer*"
def add_callback(self, f):
cb = self.callback
def newcb(s):
cb(s)
f(s)
self.callback = newcb
def do_callback(self):
self.callback(self.make_string())
def close(self):