From 9448d33d75bbd14fbaca8814b721df93e3360957 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 6 Jan 2011 18:41:44 +0100 Subject: [PATCH 1/4] Remove odd margin calculation in verbatim command that leads to overfull hbox warnings and inconsistent indentation of literal blocks within lists and quotes. --- sphinx/texinputs/sphinx.sty | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index bc8df37b8..7d2820822 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -138,15 +138,11 @@ % Play with vspace to be able to keep the indentation. \newlength\distancetoright -\newlength\leftsidespace \def\mycolorbox#1{% - \setlength\leftsidespace{\@totalleftmargin}% \setlength\distancetoright{\linewidth}% \advance\distancetoright -\@totalleftmargin % - \noindent\hspace*{\@totalleftmargin}% \fcolorbox{VerbatimBorderColor}{VerbatimColor}{% \begin{minipage}{\distancetoright}% - \noindent\hspace*{-\leftsidespace}% #1 \end{minipage}% }% @@ -480,4 +476,4 @@ \raggedright } {\endlist} -}{} \ No newline at end of file +}{} From 8a3598ff8e5b17e8108ae85960c0976ef8ddbaa9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 6 Jan 2011 20:44:55 +0100 Subject: [PATCH 2/4] Cross-reference to role docs. --- doc/domains.rst | 11 +++++++++++ doc/markup/inline.rst | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/doc/domains.rst b/doc/domains.rst index 04fef38a5..6e6a9b26a 100644 --- a/doc/domains.rst +++ b/doc/domains.rst @@ -308,6 +308,8 @@ single word, like this:: :param integer limit: maximum number of stack frames to show +.. _python-roles: + Cross-referencing Python objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -438,6 +440,8 @@ The C domain (name **c**) is suited for documentation of C API. .. c:var:: PyObject* PyClass_Type +.. _c-roles: + Cross-referencing C constructs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -522,6 +526,9 @@ The following directives are available: Select the current C++ namespace for the following objects. + +.. _cpp-roles: + These roles link to the given object types: .. rst:role:: cpp:class @@ -689,6 +696,8 @@ The JavaScript domain (name **js**) provides the following directives: Describes the attribute *name* of *object*. +.. _js-roles: + These roles are provided to refer to the described objects: .. rst:role:: js:func @@ -740,6 +749,8 @@ The reStructuredText domain (name **rst**) provides the following directives: Foo description. +.. _rst-roles: + These roles are provided to refer to the described objects: .. rst:role:: rst:dir diff --git a/doc/markup/inline.rst b/doc/markup/inline.rst index 35981edc2..4f90a6a73 100644 --- a/doc/markup/inline.rst +++ b/doc/markup/inline.rst @@ -44,6 +44,18 @@ more versatile: tool-tip on mouse-hover) will always be the full target name. +Cross-referencing objects +------------------------- + +These roles are described with their respective domains: + +* :ref:`Python ` +* :ref:`C ` +* :ref:`C++ ` +* :ref:`JavaScript ` +* :ref:`ReST ` + + .. _ref-role: Cross-referencing arbitrary locations From 7ef806ffb0841db5b30cbeb5a972be77a3536d9a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 6 Jan 2011 20:48:52 +0100 Subject: [PATCH 3/4] #571: Implement ``~`` cross-reference prefix for the C domain. --- CHANGES | 2 ++ sphinx/domains/c.py | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 9205b49ac..fbeaf0763 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Release 1.0.7 (in development) ============================== +* #571: Implement ``~`` cross-reference prefix for the C domain. + * Fix regression of LaTeX output with the fix of #556. * #568: Fix lookup of class attribute documentation on descriptors diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 7368a195f..5c40a5976 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -164,6 +164,20 @@ class CObject(ObjectDescription): self.indexnode['entries'].append(('single', indextext, name, name)) +class CXRefRole(XRefRole): + def process_link(self, env, refnode, has_explicit_title, title, target): + if not has_explicit_title: + target = target.lstrip('~') # only has a meaning for the title + # if the first character is a tilde, don't display the module/class + # parts of the contents + if title[0:1] == '~': + title = title[1:] + dot = title.rfind('.') + if dot != -1: + title = title[dot+1:] + return title, target + + class CDomain(Domain): """C language domain.""" name = 'c' @@ -184,11 +198,11 @@ class CDomain(Domain): 'var': CObject, } roles = { - 'func' : XRefRole(fix_parens=True), - 'member': XRefRole(), - 'macro': XRefRole(), - 'data': XRefRole(), - 'type': XRefRole(), + 'func' : CXRefRole(fix_parens=True), + 'member': CXRefRole(), + 'macro': CXRefRole(), + 'data': CXRefRole(), + 'type': CXRefRole(), } initial_data = { 'objects': {}, # fullname -> docname, objtype From 52ab6c99bec78340de113f25348096b9f48a064a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 6 Jan 2011 20:59:20 +0100 Subject: [PATCH 4/4] Enable documenting C members inside C type directive. --- sphinx/domains/c.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 5c40a5976..48fbb36f2 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -99,13 +99,20 @@ class CObject(ObjectDescription): m = c_funcptr_name_re.match(name) if m: name = m.group(1) + + typename = self.env.temp_data.get('c:type') + if self.name == 'c:member' and typename: + fullname = typename + '.' + name + else: + fullname = name + if not arglist: if self.objtype == 'function': # for functions, add an empty parameter list signode += addnodes.desc_parameterlist() if const: signode += addnodes.desc_addname(const, const) - return name + return fullname paramlist = addnodes.desc_parameterlist() arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup @@ -127,7 +134,7 @@ class CObject(ObjectDescription): signode += paramlist if const: signode += addnodes.desc_addname(const, const) - return name + return fullname def get_index_text(self, name): if self.objtype == 'function': @@ -163,6 +170,17 @@ class CObject(ObjectDescription): if indextext: self.indexnode['entries'].append(('single', indextext, name, name)) + def before_content(self): + self.typename_set = False + if self.name == 'c:type': + if self.names: + self.env.temp_data['c:type'] = self.names[0] + self.typename_set = True + + def after_content(self): + if self.typename_set: + self.env.temp_data['c:type'] = None + class CXRefRole(XRefRole): def process_link(self, env, refnode, has_explicit_title, title, target):