Commits

Georg Brandl committed b55999c Merge

merge with 1.0

  • Participants
  • Parent commits 32c4f57, 436e3bd

Comments (0)

Files changed (5)

 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
    :param integer limit: maximum number of stack frames to show
 
 
+.. _python-roles:
+
 Cross-referencing Python objects
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
       .. c:var:: PyObject* PyClass_Type
 
 
+.. _c-roles:
+
 Cross-referencing C constructs
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
    Select the current C++ namespace for the following objects.
 
+
+.. _cpp-roles:
+
 These roles link to the given object types:
 
 .. rst:role:: cpp:class
 
    Describes the attribute *name* of *object*.
 
+.. _js-roles:
+
 These roles are provided to refer to the described objects:
 
 .. rst:role:: js:func
 
          Foo description.
 
+.. _rst-roles:
+
 These roles are provided to refer to the described objects:
 
 .. rst:role:: rst:dir

doc/markup/inline.rst

   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 <python-roles>`
+* :ref:`C <c-roles>`
+* :ref:`C++ <cpp-roles>`
+* :ref:`JavaScript <js-roles>`
+* :ref:`ReST <rst-roles>`
+
+
 .. _ref-role:
 
 Cross-referencing arbitrary locations

sphinx/domains/c.py

         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
         signode += paramlist
         if const:
             signode += addnodes.desc_addname(const, const)
-        return name
+        return fullname
 
     def get_index_text(self, name):
         if self.objtype == 'function':
         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):
+        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."""
         '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

sphinx/texinputs/sphinx.sty

 
 % 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}%
   }%
     \raggedright
   }
   {\endlist}
-}{}
+}{}