From 678630a59beab3310d208322fd3f8587dae9e5f2 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sat, 6 Aug 2016 00:53:50 +0200 Subject: [PATCH] C++, add support for removing index text prefixes Closes sphinx-doc/sphinx#1958. --- CHANGES | 2 ++ doc/config.rst | 7 +++++++ sphinx/domains/cpp.py | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 6458458e3..dd15abab0 100644 --- a/CHANGES +++ b/CHANGES @@ -90,6 +90,8 @@ Features added * #2682: C++, basic support for attributes (C++11 style and GNU style). The new configuration variables 'cpp_id_attributes' and 'cpp_paren_attributes' can be used to introduce custom attributes. +* #1958: C++, add configuration variable 'cpp_index_common_prefix' for removing + prefixes from the index text of C++ objects. Bugs fixed ---------- diff --git a/doc/config.rst b/doc/config.rst index 7457fe928..66d4b9da6 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -2006,6 +2006,13 @@ Options for the XML builder Options for the C++ domain -------------------------- +.. confval:: cpp_index_common_prefix + + A list of prefixes that will be ignored when sorting C++ objects in the global index. + For example ``['awesome_lib::']``. + + .. versionadded:: 1.5 + .. confval:: cpp_id_attributes A list of strings that the parser additionally should accept as attributes. diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index f9fa8c277..145610b6d 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -3919,7 +3919,12 @@ class CPPObject(ObjectDescription): 'report as bug (id=%s).' % (text_type(ast), newestId)) name = text_type(ast.symbol.get_full_nested_name()).lstrip(':') - indexText = self.get_index_text(name) + strippedName = name + for prefix in self.env.config.cpp_index_common_prefix: + if name.startswith(prefix): + strippedName = strippedName[len(prefix):] + break + indexText = self.get_index_text(strippedName) self.indexnode['entries'].append(('single', indexText, newestId, '', None)) if newestId not in self.state.document.ids: @@ -4364,5 +4369,6 @@ class CPPDomain(Domain): def setup(app): app.add_domain(CPPDomain) + app.add_config_value("cpp_index_common_prefix", [], 'env') app.add_config_value("cpp_id_attributes", [], 'env') app.add_config_value("cpp_paren_attributes", [], 'env')