diff --git a/doc/config.rst b/doc/config.rst index 8c9c12c14..126679d12 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -192,12 +192,17 @@ General configuration .. versionadded:: 1.0 -.. confval:: default_domain +.. confval:: primary_domain .. index:: default; domain + primary; domain The name of the default :ref:`domain `. Can also be ``None`` to - disable a default domain. The default is ``'py'``. + disable a default domain. The default is ``'py'``. Those objects in other + domains (whether the domain name is given explicitly, or selected by a + :dir:`default-domain` directive) will have the domain name explicitly + prepended when named (e.g., when the default domain is C, Python functions + will be named "Python function", not just "function"). .. versionadded:: 1.0 diff --git a/doc/domains.rst b/doc/domains.rst index 0f62f176b..161a81de3 100644 --- a/doc/domains.rst +++ b/doc/domains.rst @@ -69,11 +69,11 @@ directive name. To avoid having to writing the domain name all the time when you e.g. only describe Python objects, a default domain can be selected with either the config -value :confval:`default_domain` or this directive: +value :confval:`primary_domain` or this directive: .. rst:directive:: .. default-domain:: name - Select a new default domain. While the :confval:`default_domain` selects a + Select a new default domain. While the :confval:`primary_domain` selects a global default, this only has an effect within the same file. If no other default is selected, the Python domain (named ``py``) is the default diff --git a/sphinx/config.py b/sphinx/config.py index e9de29709..806025b9b 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -61,7 +61,7 @@ class Config(object): rst_epilog = (None, 'env'), rst_prolog = (None, 'env'), trim_doctest_flags = (True, 'env'), - default_domain = ('py', 'env'), + primary_domain = ('py', 'env'), needs_sphinx = (None, None), nitpicky = (False, 'env'), diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index 2119c0a8d..d133a8123 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -11,6 +11,7 @@ """ from sphinx.errors import SphinxError +from sphinx.locale import _ class ObjType(object): @@ -21,7 +22,7 @@ class ObjType(object): Constructor arguments: - - *lname*: localized name of the type + - *lname*: localized name of the type (do not include domain name) - *roles*: all the roles that can refer to an object of this type - *attrs*: object attributes -- currently only "searchprio" is known, which defines the object's priority in the full-text search index, @@ -243,6 +244,14 @@ class Domain(object): """ return [] + def get_type_name(self, type, primary=False): + """ + Return full name for given ObjType. + """ + if primary: + return type.lname + return _('%s %s') % (self.label, type.lname) + from sphinx.domains.c import CDomain from sphinx.domains.cpp import CPPDomain diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 0e85c809e..c49dc2843 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -168,11 +168,11 @@ class CDomain(Domain): name = 'c' label = 'C' object_types = { - 'function': ObjType(l_('C function'), 'func'), - 'member': ObjType(l_('C member'), 'member'), - 'macro': ObjType(l_('C macro'), 'macro'), - 'type': ObjType(l_('C type'), 'type'), - 'var': ObjType(l_('C variable'), 'data'), + 'function': ObjType(l_('function'), 'func'), + 'member': ObjType(l_('member'), 'member'), + 'macro': ObjType(l_('macro'), 'macro'), + 'type': ObjType(l_('type'), 'type'), + 'var': ObjType(l_('variable'), 'data'), } directives = { diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index b43517be5..62dec4ac8 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -10,7 +10,6 @@ """ import re -import string from copy import deepcopy from docutils import nodes @@ -22,7 +21,7 @@ from sphinx.domains import Domain, ObjType from sphinx.directives import ObjectDescription from sphinx.util.nodes import make_refnode from sphinx.util.compat import Directive -from sphinx.util.docfields import Field, TypedField +from sphinx.util.docfields import TypedField _identifier_re = re.compile(r'\b(~?[a-zA-Z_][a-zA-Z0-9_]*)\b') @@ -1028,10 +1027,10 @@ class CPPDomain(Domain): name = 'cpp' label = 'C++' object_types = { - 'class': ObjType(l_('C++ class'), 'class'), - 'function': ObjType(l_('C++ function'), 'func'), - 'member': ObjType(l_('C++ member'), 'member'), - 'type': ObjType(l_('C++ type'), 'type') + 'class': ObjType(l_('class'), 'class'), + 'function': ObjType(l_('function'), 'func'), + 'member': ObjType(l_('member'), 'member'), + 'type': ObjType(l_('type'), 'type') } directives = { diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index 51ff1da1c..31a769873 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -163,9 +163,9 @@ class JavaScriptDomain(Domain): label = 'JavaScript' # if you add a new object type make sure to edit JSObject.get_index_string object_types = { - 'function': ObjType(l_('JavaScript function'), 'func'), - 'data': ObjType(l_('JavaScript data'), 'data'), - 'attribute': ObjType(l_('JavaScript attribute'), 'attr'), + 'function': ObjType(l_('function'), 'func'), + 'data': ObjType(l_('data'), 'data'), + 'attribute': ObjType(l_('attribute'), 'attr'), } directives = { 'function': JSCallable, diff --git a/sphinx/domains/rst.py b/sphinx/domains/rst.py index 8b98c519d..5c25e085a 100644 --- a/sphinx/domains/rst.py +++ b/sphinx/domains/rst.py @@ -100,8 +100,8 @@ class ReSTDomain(Domain): label = 'reStructuredText' object_types = { - 'directive': ObjType(l_('reStructuredText directive'), 'dir'), - 'role': ObjType(l_('reStructuredText role'), 'role'), + 'directive': ObjType(l_('directive'), 'dir'), + 'role': ObjType(l_('role'), 'role'), } directives = { 'directive': ReSTDirective, diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 48c966402..3c8dff43e 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -495,3 +495,7 @@ class StandardDomain(Domain): self.object_types[type].attrs['searchprio']) for name, info in self.data['labels'].iteritems(): yield (name, info[2], 'label', info[0], info[1], -1) + + def get_type_name(self, type, primary=False): + # never prepend "Default" + return type.lname diff --git a/sphinx/environment.py b/sphinx/environment.py index 212fd6556..007616245 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -594,7 +594,7 @@ class BuildEnvironment: self.temp_data['docname'] = docname # defaults to the global default, but can be re-set in a document self.temp_data['default_domain'] = \ - self.domains.get(self.config.default_domain) + self.domains.get(self.config.primary_domain) self.settings['input_encoding'] = self.config.source_encoding self.settings['trim_footnote_reference_space'] = \ diff --git a/sphinx/search.py b/sphinx/search.py index f37d94029..0d07fd72f 100644 --- a/sphinx/search.py +++ b/sphinx/search.py @@ -170,7 +170,8 @@ class IndexBuilder(object): otypes[domainname, type] = i otype = domain.object_types.get(type) if otype: - onames[i] = str(otype.lname) # fire translation proxies + # use str() to fire translation proxies + onames[i] = str(domain.get_type_name(otype)) else: onames[i] = type pdict[name] = (fn2index[docname], i, prio)