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