From f3b89e4c72d881f522c3e3223d20b7c44d1f1e3f Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 29 Dec 2017 10:36:03 +0100 Subject: [PATCH] Add IsAutoNestedBy This is complementary to AutoNests: Styles can determine which other style should auto-nest them. This is particularly useful for modules that add new styles which should be auto-nested in a given context. --- lib/doc/Customization.lyx | 77 +++++++++++++++++++++++++++++++++++- lib/scripts/layout2layout.py | 3 +- src/Layout.cpp | 24 +++++++++++ src/Layout.h | 4 ++ src/Text3.cpp | 5 ++- 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index cf6d7bab74..33a9735ca8 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -12163,7 +12163,7 @@ Argument item:1 \end_deeper \begin_layout Description -\change_inserted -712698321 1514534780 +\change_inserted -712698321 1514539256 \begin_inset Flex Code status collapsed @@ -12177,7 +12177,8 @@ AutoNests Includes a comma-separated list of layout names that should be nested in and after the current one. - Only makes sense for nestable layouts (such as environments) + Only makes sense for nestable layouts (such as environments). + Must be ended by \begin_inset Quotes eld \end_inset @@ -12197,6 +12198,21 @@ EndAutoNests \begin_inset Quotes erd \end_inset +. + See also +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1514539161 +IsAutoNestedBy +\change_unchanged + +\end_layout + +\end_inset + . \end_layout @@ -12929,6 +12945,63 @@ TitleLatexName \end_inset global entries). +\change_inserted -712698321 1514539171 + +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1514539282 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1514539190 +IsAutoNestedBy +\end_layout + +\end_inset + + Includes a comma-separated list of layout names after which this one should + be nested. + Only makes sense with regard to nestable layouts (such as environments). + Must be ended by +\begin_inset Quotes eld +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1514539279 +EndIsAutoNestedBy +\end_layout + +\end_inset + + +\begin_inset Quotes erd +\end_inset + +. + See also +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1514539172 +AutoNest +\end_layout + +\end_inset + +. +\change_unchanged + \end_layout \begin_layout Description diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index a5b00e10bf..d13f8bf105 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -221,7 +221,8 @@ currentFormat = 66 # Color collapsable -> collapsible # Incremented to format 66, 28 December 2017 by spitz -# New Layout tag "AutoNests ... EndAutoNests" +# New Layout tags "AutoNests ... EndAutoNests" and +# "IsAutoNestedBy ... EndIsAutoNestedBy" # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). diff --git a/src/Layout.cpp b/src/Layout.cpp index 1dcd7dd2bc..0a783d0aad 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -41,6 +41,7 @@ enum LayoutTags { LT_ALIGNPOSSIBLE, LT_ARGUMENT, LT_AUTONESTS, + LT_AUTONESTEDBY, LT_MARGIN, LT_BOTTOMSEP, LT_CATEGORY, @@ -219,6 +220,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass) { "innertag", LT_INNERTAG }, { "inpreamble", LT_INPREAMBLE }, { "intitle", LT_INTITLE }, + { "isautonestedby", LT_AUTONESTEDBY }, { "istoccaption", LT_ISTOCCAPTION }, { "itemcommand", LT_ITEMCOMMAND }, { "itemsep", LT_ITEMSEP }, @@ -606,6 +608,18 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass) break; } + case LT_AUTONESTEDBY: { + docstring const autonest = + subst(subst(subst(lex.getLongString(from_ascii("EndIsAutoNestedBy")), + from_ascii("\n"), docstring()), + from_ascii(" "), docstring()), + from_ascii("\t"), docstring()); + vector const autonests = + getVectorFromString(autonest); + autonested_by_.insert(autonests.begin(), autonests.end()); + break; + } + case LT_REFPREFIX: { docstring arg; lex >> arg; @@ -1411,6 +1425,16 @@ void Layout::write(ostream & os) const } os << "\n\tEndAutoNests\n"; } + if (!autonested_by_.empty()) { + os << "\tIsAutoNestedBy\n\t"; + for (set::const_iterator it = autonested_by_.begin(); + it != autonested_by_.end(); ++it) { + if (it != autonested_by_.begin()) + os << ','; + os << to_utf8(*it); + } + os << "\n\tIsAutoNestedBy\n"; + } if (refprefix.empty()) os << "\tRefPrefix OFF\n"; else diff --git a/src/Layout.h b/src/Layout.h index 4dc635c08b..04f184f3a4 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -151,6 +151,8 @@ public: /// std::set const & autonests() const { return autonests_; } /// + std::set const & isAutonestedBy() const { return autonested_by_; } + /// std::string const & latexparam() const { return latexparam_; } /// docstring leftdelim() const { return leftdelim_; } @@ -472,6 +474,8 @@ private: std::set requires_; /// Layouts that are by default nested after this one std::set autonests_; + /// Layouts that by auto-nest this one + std::set autonested_by_; /// LaTeXArgMap latexargs_; /// diff --git a/src/Text3.cpp b/src/Text3.cpp index aa519d39ab..e8a401c551 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1478,11 +1478,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) setLayout(cur, layout); bool do_nest = false; set autonests; + set autonested; if (cur.pit() > 0) { autonests = pars_[cur.pit() - 1].layout().autonests(); + autonested = pars_[cur.pit()].layout().isAutonestedBy(); do_nest = !ignoreautonests; } - if (do_nest && autonests.find(layout) != autonests.end()) + if (do_nest && (autonests.find(layout) != autonests.end() + || autonested.find(old_layout) != autonested.end())) lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT)); } -- 2.39.5