]> git.lyx.org Git - features.git/commitdiff
Make autocorrect configurable in preferences file
authorMartin Vermeer <martin.vermeer@hut.fi>
Thu, 15 Jan 2009 09:48:00 +0000 (09:48 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Thu, 15 Jan 2009 09:48:00 +0000 (09:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28171 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXRC.cpp
src/LyXRC.h
src/mathed/InsetMathNest.cpp

index 5750607a1f8193abe354f5a13edbff4c2fd83433..1fd1bd249e83ad626ccd676a6b3854301f20fad4 100644 (file)
@@ -58,6 +58,7 @@ LexerKeyword lyxrcTags[] = {
        { "\\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 @@ void LyXRC::setDefaults()
        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 @@ int LyXRC::read(Lexer & lexrc)
                        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 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                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 @@ string const LyXRC::getDescription(LyXRCTags tag)
                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);
index a23f3d79aa4003522929c0c0e648d16022d1257a..3e513e350066d4e96770672209e5973d0a51a1db 100644 (file)
@@ -38,6 +38,7 @@ public:
        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 @@ public:
        ///
        int completion_inline_dots;
        ///
+       bool autocorrection_math;
+       ///
        double completion_popup_delay;
        ///
        bool completion_popup_math;
index efd473ba04bdc8850a92a4daa3928e232674fa29..2aad5c93edfcfbd7ce9ef2820a758bac8dfd322e 100644 (file)
@@ -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 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
                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 (lyxrc.autocorrection_math && c == ' ' && cur.autocorrect()) {
+               cur.autocorrect() = false;
+               cur.message(_("Autocorrect Off ('!' to enter)"));
+               return true;
+       } 
+       if (lyxrc.autocorrection_math && 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 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
        }
 
 
-#ifdef AUTOCORRECT
        // try auto-correction
-       if (cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c))
+       if (lyxrc.autocorrection_math && 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 (lyxrc.autocorrection_math) {
+               if (!cur.autocorrect())
+                       cur.message(_("Autocorrect Off ('!' to enter)"));
+               else
+                       cur.message(_("Autocorrect On (<space> to exit)"));
+       }
        return true;
 }