On Wed, 14 Jan 2009 14:37:47 +0100 Jean-Marc Lasgouttes <lasgout...@lyx.org> wrote:
> Martin Vermeer <martin.verm...@tkk.fi> writes: > > + // leave autocorrect mode if necessary > > + if (autocorrectEnabled(cur) && c == ' ' && cur.autocorrect()) { > > Two questions (probably related) > - why do you pass cur to autocorrectEnabled, whereas it does not rely on > the cursor? Hrmf. > - why not put the cur.autocorrect() test into autocorrectEnabled, sicne > they are always used together? Or maybe move the lyxrc check into > Cursor::autocorrect. > > JMarc Eh, how do you handle this: if (autocorrectEnabled()) { if (!cur.autocorrect()) cur.message(_("Autocorrect Off ('!' to enter)")); else cur.message(_("Autocorrect On (<space> to exit)")); } - Martin
Index: LyXRC.h =================================================================== --- LyXRC.h (revision 28149) +++ LyXRC.h (working copy) @@ -38,6 +38,7 @@ enum LyXRCTags { RC_ACCEPT_COMPOUND = 1, RC_ALT_LANG, + RC_AUTOCORRECTION_MATH, RC_PLAINTEXT_LINELEN, RC_PLAINTEXT_ROFF_COMMAND, RC_AUTOREGIONDELETE, @@ -438,6 +439,8 @@ /// int completion_inline_dots; /// + bool autocorrection_math; + /// double completion_popup_delay; /// bool completion_popup_math; Index: mathed/InsetMathNest.cpp =================================================================== --- mathed/InsetMathNest.cpp (revision 28149) +++ mathed/InsetMathNest.cpp (working copy) @@ -10,8 +10,6 @@ #include <config.h> -//#define AUTOCORRECT - #include "InsetMathNest.h" #include "InsetMathArray.h" @@ -27,9 +25,7 @@ #include "InsetMathSpace.h" #include "InsetMathSymbol.h" #include "InsetMathUnknown.h" -#ifdef AUTOCORRECT #include "MathAutoCorrect.h" -#endif #include "MathCompletionList.h" #include "MathData.h" #include "MathFactory.h" @@ -1519,22 +1515,18 @@ return true; } - // This is annoying as one has to press <space> far too often. - // Disable it. -#ifdef AUTOCORRECT - // leave autocorrect mode if necessary - if (c == ' ' && cur.autocorrect()) { - cur.autocorrect() = false; - cur.message(_("Autocorrect Off ('!' to enter)")); - return true; - } - if (c == '!' && !cur.autocorrect()) { - cur.autocorrect() = true; - cur.message(_("Autocorrect On (<space> to exit)")); - return true; - } -#endif + // leave autocorrect mode if necessary + if (autocorrectEnabled() && c == ' ' && cur.autocorrect()) { + cur.autocorrect() = false; + cur.message(_("Autocorrect Off ('!' to enter)")); + return true; + } + if (autocorrectEnabled() && c == '!' && !cur.autocorrect()) { + cur.autocorrect() = true; + cur.message(_("Autocorrect On (<space> to exit)")); + return true; + } // just clear selection on pressing the space bar if (cur.selection() && c == ' ') { @@ -1631,20 +1623,18 @@ } -#ifdef AUTOCORRECT // try auto-correction - if (cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c)) + if (autocorrectEnabled() && cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c)) return true; -#endif // no special circumstances, so insert the character without any fuss cur.insert(c); -#ifdef AUTOCORRECT - if (!cur.autocorrect()) - cur.message(_("Autocorrect Off ('!' to enter)")); - else - cur.message(_("Autocorrect On (<space> to exit)")); -#endif + if (autocorrectEnabled()) { + if (!cur.autocorrect()) + cur.message(_("Autocorrect Off ('!' to enter)")); + else + cur.message(_("Autocorrect On (<space> to exit)")); + } return true; } @@ -1732,6 +1722,12 @@ } +bool InsetMathNest::autocorrectEnabled() const +{ + return lyxrc.autocorrection_math; +} + + bool InsetMathNest::completionSupported(Cursor const & cur) const { return cur.inMacroMode(); Index: mathed/InsetMathNest.h =================================================================== --- mathed/InsetMathNest.h (revision 28149) +++ mathed/InsetMathNest.h (working copy) @@ -112,6 +112,8 @@ bool mouseHovered() const { return mouse_hover_; } /// + bool autocorrectEnabled() const; + /// bool completionSupported(Cursor const &) const; /// bool inlineCompletionSupported(Cursor const & cur) const; Index: LyXRC.cpp =================================================================== --- LyXRC.cpp (revision 28149) +++ LyXRC.cpp (working copy) @@ -58,6 +58,7 @@ { "\\auto_number", LyXRC::RC_AUTO_NUMBER }, { "\\auto_region_delete", LyXRC::RC_AUTOREGIONDELETE }, { "\\auto_reset_options", LyXRC::RC_AUTORESET_OPTIONS }, + { "\\autocorrection_math", LyXRC::RC_AUTOCORRECTION_MATH }, { "\\autosave", LyXRC::RC_AUTOSAVE }, { "\\backupdir_path", LyXRC::RC_BACKUPDIR_PATH }, { "\\bibtex_command", LyXRC::RC_BIBTEX_COMMAND }, @@ -314,6 +315,7 @@ completion_popup_text = false; completion_popup_delay = 2.0; completion_popup_after_complete = true; + autocorrection_math = false; completion_inline_math = true; completion_inline_text = false; completion_inline_dots = -1; @@ -711,6 +713,10 @@ lexrc >> completion_inline_dots; break; + case RC_AUTOCORRECTION_MATH: + lexrc >> autocorrection_math; + break; + case RC_COMPLETION_POPUP_DELAY: lexrc >> completion_popup_delay; break; @@ -1968,6 +1974,14 @@ } if (tag != RC_LAST) break; + case RC_AUTOCORRECTION_MATH: + if (ignore_system_lyxrc || + autocorrection_math != system_lyxrc.autocorrection_math) { + os << "\\autocorrection_math " + << convert<string>(autocorrection_math) << '\n'; + } + if (tag != RC_LAST) + break; case RC_COMPLETION_POPUP_DELAY: if (ignore_system_lyxrc || completion_popup_delay != system_lyxrc.completion_popup_delay) { @@ -2652,6 +2666,10 @@ str = _("Use \"...\" to shorten long completions."); break; + case RC_AUTOCORRECTION_MATH: + str = _("Allow TeXMacs shorthand, like => converting to \Rightarrow."); + break; + case RC_NUMLASTFILES: str = bformat(_("Maximal number of lastfiles. Up to %1$d can appear in the file menu."), maxlastfiles);