Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 14318:1f46be4689ed
help: consolidate topic hooks in help.py
This removes loops like cmdutil->revset->help->extensions->cmdutil and
simplifies the code.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 13 May 2011 12:57:27 -0500 |
parents | 660b0c1b6196 |
children | 6ab8b17adc03 |
comparison
equal
deleted
inserted
replaced
14317:660b0c1b6196 | 14318:1f46be4689ed |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
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 sys, os |
10 import extensions | 10 import extensions, revset, templatekw, templatefilters |
11 import util | 11 import 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''' |
15 if not exts: | 15 if not exts: |
74 loaddoc('hgignore')), | 74 loaddoc('hgignore')), |
75 ]) | 75 ]) |
76 | 76 |
77 # Map topics to lists of callable taking the current topic help and | 77 # Map topics to lists of callable taking the current topic help and |
78 # returning the updated version | 78 # returning the updated version |
79 helphooks = { | 79 helphooks = {} |
80 } | |
81 | 80 |
82 def addtopichook(topic, rewriter): | 81 def addtopichook(topic, rewriter): |
83 helphooks.setdefault(topic, []).append(rewriter) | 82 helphooks.setdefault(topic, []).append(rewriter) |
84 | 83 |
85 def makeitemsdoc(topic, doc, marker, items): | 84 def makeitemsdoc(topic, doc, marker, items): |
95 lines = text.splitlines() | 94 lines = text.splitlines() |
96 lines[1:] = [(' ' + l.strip()) for l in lines[1:]] | 95 lines[1:] = [(' ' + l.strip()) for l in lines[1:]] |
97 entries.append('\n'.join(lines)) | 96 entries.append('\n'.join(lines)) |
98 entries = '\n\n'.join(entries) | 97 entries = '\n\n'.join(entries) |
99 return doc.replace(marker, entries) | 98 return doc.replace(marker, entries) |
99 | |
100 def addtopicsymbols(topic, marker, symbols): | |
101 def add(topic, doc): | |
102 return makeitemsdoc(topic, doc, marker, symbols) | |
103 addtopichook(topic, add) | |
104 | |
105 addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols) | |
106 addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords) | |
107 addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters) |