##// END OF EJS Templates
help: introduce topicmatch for finding topics matching a keyword
Augie Fackler -
r16710:a1798368 default
parent child Browse files
Show More
@@ -6,9 +6,9 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import gettext, _
8 from i18n import gettext, _
9 import sys, os
9 import itertools, sys, os
10 import extensions, revset, fileset, templatekw, templatefilters, filemerge
10 import extensions, revset, fileset, templatekw, templatefilters, filemerge
11 import util
11 import encoding, util
12
12
13 def listexts(header, exts, indent=1):
13 def listexts(header, exts, indent=1):
14 '''return a text listing of the given extensions'''
14 '''return a text listing of the given extensions'''
@@ -27,6 +27,54 b' def extshelp():'
27 doc += listexts(_('disabled extensions:'), extensions.disabled())
27 doc += listexts(_('disabled extensions:'), extensions.disabled())
28 return doc
28 return doc
29
29
30 def topicmatch(kw):
31 """Return help topics matching kw.
32
33 Returns {'section': [(name, summary), ...], ...} where section is
34 one of topics, commands, extensions, or extensioncommands.
35 """
36 kw = encoding.lower(kw)
37 def lowercontains(container):
38 return kw in encoding.lower(_(container))
39 results = {'topics': [],
40 'commands': [],
41 'extensions': [],
42 'extensioncommands': [],
43 }
44 for names, header, doc in helptable:
45 if (sum(map(lowercontains, names))
46 or lowercontains(header)
47 or lowercontains(doc())):
48 results['topics'].append((names[0], header))
49 import commands # avoid cycle
50 for cmd, entry in commands.table.iteritems():
51 if cmd.startswith('debug'):
52 continue
53 if len(entry) == 3:
54 summary = entry[2]
55 else:
56 summary = ''
57 docs = getattr(entry[0], '__doc__', None) or ''
58 if kw in cmd or lowercontains(summary) or lowercontains(docs):
59 doclines = _(docs).splitlines()
60 if doclines:
61 summary = doclines[0]
62 cmdname = cmd.split('|')[0].lstrip('^')
63 results['commands'].append((cmdname, summary))
64 for name, docs in itertools.chain(
65 extensions.enabled().iteritems(),
66 extensions.disabled().iteritems()):
67 # extensions.load ignores the UI argument
68 mod = extensions.load(None, name, '')
69 if lowercontains(name) or lowercontains(docs):
70 results['extensions'].append((name, _(docs).splitlines()[0]))
71 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
72 if kw in cmd or lowercontains(entry[2]):
73 cmdname = cmd.split('|')[0].lstrip('^')
74 results['extensioncommands'].append(
75 (cmdname, _(getattr(cmd, '__doc__', ''))))
76 return results
77
30 def loaddoc(topic):
78 def loaddoc(topic):
31 """Return a delayed loader for help/topic.txt."""
79 """Return a delayed loader for help/topic.txt."""
32
80
General Comments 0
You need to be logged in to leave comments. Login now