mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Add cprotection support for paragraph layouts.
This commit is contained in:
parent
e11bda2cea
commit
ef359f58b5
@ -14762,6 +14762,76 @@ protect
|
|||||||
not
|
not
|
||||||
\emph default
|
\emph default
|
||||||
whether this command should itself be protected.)
|
whether this command should itself be protected.)
|
||||||
|
\change_inserted -712698321 1523696949
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Description
|
||||||
|
|
||||||
|
\change_inserted -712698321 1523696969
|
||||||
|
\begin_inset Flex Code
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\change_inserted -712698321 1523696950
|
||||||
|
NeedCProtect
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
[
|
||||||
|
\begin_inset Flex Code
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\change_inserted -712698321 1523696950
|
||||||
|
|
||||||
|
\emph on
|
||||||
|
0
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
,
|
||||||
|
\begin_inset space \thinspace{}
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Flex Code
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\change_inserted -712698321 1523696950
|
||||||
|
1
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
] This causes macros that contain this layout to be protected with
|
||||||
|
\begin_inset Flex Code
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\change_inserted -712698321 1523696950
|
||||||
|
|
||||||
|
\backslash
|
||||||
|
cprotect
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
(cf.
|
||||||
|
package
|
||||||
|
\family sans
|
||||||
|
cprotect
|
||||||
|
\family default
|
||||||
|
) if necessary and thus allows (some) verbatim stuff in macros.
|
||||||
|
\change_unchanged
|
||||||
|
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Description
|
\begin_layout Description
|
||||||
|
@ -81,6 +81,7 @@ Style Verbatim
|
|||||||
ParbreakIsNewline 1
|
ParbreakIsNewline 1
|
||||||
FreeSpacing 1
|
FreeSpacing 1
|
||||||
PassThru 1
|
PassThru 1
|
||||||
|
NeedCProtect 1
|
||||||
KeepEmpty 1
|
KeepEmpty 1
|
||||||
NewLine 0
|
NewLine 0
|
||||||
TopSep 0.7
|
TopSep 0.7
|
||||||
|
@ -74,6 +74,7 @@ enum LayoutTags {
|
|||||||
LT_LATEXTYPE,
|
LT_LATEXTYPE,
|
||||||
LT_LEFTDELIM,
|
LT_LEFTDELIM,
|
||||||
LT_LEFTMARGIN,
|
LT_LEFTMARGIN,
|
||||||
|
LT_NEED_CPROTECT,
|
||||||
LT_NEED_PROTECT,
|
LT_NEED_PROTECT,
|
||||||
LT_NEWLINE,
|
LT_NEWLINE,
|
||||||
LT_NEXTNOINDENT,
|
LT_NEXTNOINDENT,
|
||||||
@ -130,6 +131,7 @@ Layout::Layout()
|
|||||||
intitle = false;
|
intitle = false;
|
||||||
inpreamble = false;
|
inpreamble = false;
|
||||||
needprotect = false;
|
needprotect = false;
|
||||||
|
needcprotect = false;
|
||||||
keepempty = false;
|
keepempty = false;
|
||||||
font = inherit_font;
|
font = inherit_font;
|
||||||
labelfont = inherit_font;
|
labelfont = inherit_font;
|
||||||
@ -242,6 +244,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
|
|||||||
{ "leftdelim", LT_LEFTDELIM },
|
{ "leftdelim", LT_LEFTDELIM },
|
||||||
{ "leftmargin", LT_LEFTMARGIN },
|
{ "leftmargin", LT_LEFTMARGIN },
|
||||||
{ "margin", LT_MARGIN },
|
{ "margin", LT_MARGIN },
|
||||||
|
{ "needcprotect", LT_NEED_CPROTECT },
|
||||||
{ "needprotect", LT_NEED_PROTECT },
|
{ "needprotect", LT_NEED_PROTECT },
|
||||||
{ "newline", LT_NEWLINE },
|
{ "newline", LT_NEWLINE },
|
||||||
{ "nextnoindent", LT_NEXTNOINDENT },
|
{ "nextnoindent", LT_NEXTNOINDENT },
|
||||||
@ -393,6 +396,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
|
|||||||
lex >> needprotect;
|
lex >> needprotect;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LT_NEED_CPROTECT:
|
||||||
|
lex >> needcprotect;
|
||||||
|
break;
|
||||||
|
|
||||||
case LT_KEEPEMPTY:
|
case LT_KEEPEMPTY:
|
||||||
lex >> keepempty;
|
lex >> keepempty;
|
||||||
break;
|
break;
|
||||||
@ -1212,6 +1219,7 @@ void Layout::write(ostream & os) const
|
|||||||
it != postcommandargs_.end(); ++it)
|
it != postcommandargs_.end(); ++it)
|
||||||
writeArgument(os, it->first, it->second);
|
writeArgument(os, it->first, it->second);
|
||||||
os << "\tNeedProtect " << needprotect << "\n"
|
os << "\tNeedProtect " << needprotect << "\n"
|
||||||
|
"\tNeedCProtect " << needcprotect << "\n"
|
||||||
"\tKeepEmpty " << keepempty << '\n';
|
"\tKeepEmpty " << keepempty << '\n';
|
||||||
if (labelfont == font)
|
if (labelfont == font)
|
||||||
lyxWrite(os, font, "Font", 1);
|
lyxWrite(os, font, "Font", 1);
|
||||||
|
@ -311,6 +311,9 @@ public:
|
|||||||
/** true when the fragile commands in the paragraph need to be
|
/** true when the fragile commands in the paragraph need to be
|
||||||
\protect'ed. */
|
\protect'ed. */
|
||||||
bool needprotect;
|
bool needprotect;
|
||||||
|
/** true when the verbatim stuff of this layout needs to ce
|
||||||
|
\cprotect'ed. */
|
||||||
|
bool needcprotect;
|
||||||
/// true when empty paragraphs should be kept.
|
/// true when empty paragraphs should be kept.
|
||||||
bool keepempty;
|
bool keepempty;
|
||||||
/// Type of LaTeX object
|
/// Type of LaTeX object
|
||||||
|
@ -3380,6 +3380,25 @@ bool Paragraph::isHardHyphenOrApostrophe(pos_type pos) const
|
|||||||
|
|
||||||
bool Paragraph::needsCProtection() const
|
bool Paragraph::needsCProtection() const
|
||||||
{
|
{
|
||||||
|
// first check the layout of the paragraph
|
||||||
|
if (layout().needcprotect) {
|
||||||
|
// Environments need cprotection regardless the content
|
||||||
|
if (layout().latextype == LATEX_ENVIRONMENT)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Commands need cprotection if they contain specific chars
|
||||||
|
int const nchars_escape = 9;
|
||||||
|
static char_type const chars_escape[nchars_escape] = {
|
||||||
|
'&', '_', '$', '%', '#', '^', '{', '}', '\\'};
|
||||||
|
|
||||||
|
docstring const pars = asString();
|
||||||
|
for (int k = 0; k < nchars_escape; k++) {
|
||||||
|
if (contains(pars, chars_escape[k]))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now check whether we have insets that need cprotection
|
||||||
pos_type size = d->text_.size();
|
pos_type size = d->text_.size();
|
||||||
for (pos_type i = 0; i < size; ++i)
|
for (pos_type i = 0; i < size; ++i)
|
||||||
if (isInset(i))
|
if (isInset(i))
|
||||||
|
Loading…
Reference in New Issue
Block a user