+ if (cur.pit() > 0 && !ignoreautonests) {
+ set<docstring> const & autonests =
+ pars_[cur.pit() - 1].layout().autonests();
+ set<docstring> const & autonested =
+ pars_[cur.pit()].layout().isAutonestedBy();
+ if (autonests.find(layout) != autonests.end()
+ || autonested.find(old_layout) != autonested.end())
+ lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
+ }
+ }
+
+ Layout::LaTeXArgMap args = tclass[layout].args();
+ Layout::LaTeXArgMap::const_iterator lait = args.begin();
+ Layout::LaTeXArgMap::const_iterator const laend = args.end();
+ for (; lait != laend; ++lait) {
+ Layout::latexarg arg = (*lait).second;
+ if (arg.autoinsert) {
+ FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
+ lyx::dispatch(cmd);
+ }
+ }
+
+ break;
+ }
+
+ case LFUN_ENVIRONMENT_SPLIT: {
+ bool const outer = cmd.argument() == "outer";
+ bool const previous = cmd.argument() == "previous";
+ bool const before = cmd.argument() == "before";
+ bool const normal = cmd.argument().empty();
+ Paragraph const & para = cur.paragraph();
+ docstring layout;
+ if (para.layout().isEnvironment())
+ layout = para.layout().name();
+ depth_type split_depth = cur.paragraph().params().depth();
+ depth_type nextpar_depth = 0;
+ if (outer || previous) {
+ // check if we have an environment in our scope
+ pit_type pit = cur.pit();
+ Paragraph cpar = pars_[pit];
+ while (true) {
+ if (pit == 0)
+ break;
+ --pit;
+ cpar = pars_[pit];
+ if (layout.empty() && previous
+ && cpar.layout().isEnvironment()
+ && cpar.params().depth() <= split_depth)
+ layout = cpar.layout().name();
+ if (cpar.params().depth() < split_depth
+ && cpar.layout().isEnvironment()) {
+ if (!previous)
+ layout = cpar.layout().name();
+ split_depth = cpar.params().depth();
+ }
+ if (cpar.params().depth() == 0)
+ break;
+ }
+ }
+ if ((outer || normal) && cur.pit() < cur.lastpit()) {
+ // save nesting of following paragraph
+ Paragraph cpar = pars_[cur.pit() + 1];
+ nextpar_depth = cpar.params().depth();
+ }
+ if (before)
+ cur.top().setPitPos(cur.pit(), 0);
+ if (before || cur.pos() > 0)
+ lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
+ else if (previous && cur.nextInset() && cur.nextInset()->lyxCode() == SEPARATOR_CODE)
+ lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
+ if (outer) {
+ while (cur.paragraph().params().depth() > split_depth)
+ lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
+ }
+ DocumentClass const & tc = bv->buffer().params().documentClass();
+ lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
+ + from_ascii("\" ignoreautonests")));
+ lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
+ if (before) {
+ cur.backwardPos();
+ lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
+ while (cur.paragraph().params().depth() < split_depth)
+ lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
+ }
+ else
+ lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
+ lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
+ if ((outer || normal) && nextpar_depth > 0) {
+ // restore nesting of following paragraph
+ DocIterator scur = cur;
+ depth_type const max_depth = cur.paragraph().params().depth() + 1;
+ cur.forwardPar();
+ while (cur.paragraph().params().depth() < min(nextpar_depth, max_depth))
+ lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
+ cur.setCursor(scur);
+ }