/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
1
/*
2
 * tex.js
3
 *
4
 * Copyright (C) 2009-11 by RStudio, Inc.
5
 *
6
 * The Initial Developer of the Original Code is
7
 * Ajax.org B.V.
8
 * Portions created by the Initial Developer are Copyright (C) 2010
9
 * the Initial Developer. All Rights Reserved.
10
 *
11
 * This program is licensed to you under the terms of version 3 of the
12
 * GNU Affero General Public License. This program is distributed WITHOUT
13
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
14
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
15
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
16
 *
17
 */
18
define('ace/mode/tex', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/text_highlight_rules', 'ace/mode/tex_highlight_rules', 'ace/mode/matching_brace_outdent'], function(require, exports, module) {
19
20
21
var oop = require("../lib/oop");
22
var TextMode = require("./text").Mode;
23
var Tokenizer = require("../tokenizer").Tokenizer;
24
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
25
var TexHighlightRules = require("./tex_highlight_rules").TexHighlightRules;
26
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
27
28
var Mode = function(suppressHighlighting) {
29
	if (suppressHighlighting)
30
    	this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
31
	else
32
    	this.$tokenizer = new Tokenizer(new TexHighlightRules().getRules());
33
    this.$outdent = new MatchingBraceOutdent();
34
};
35
oop.inherits(Mode, TextMode);
36
37
(function() {
38
   this.getNextLineIndent = function(state, line, tab) {
39
      return this.$getIndent(line);
40
   };
41
42
   this.allowAutoInsert = function() {
43
      return false;
44
   };
45
}).call(Mode.prototype);
46
47
exports.Mode = Mode;
48
});
49
define('ace/mode/tex_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
50
51
52
var oop = require("../lib/oop");
53
var lang = require("../lib/lang");
54
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
55
56
var TexHighlightRules = function(textClass) {
57
58
    if (!textClass)
59
        textClass = "text";
60
61
    this.$rules = {
62
        "start" : [
63
	        {
64
	            token : "comment",
65
	            regex : "%.*$"
66
	        }, {
67
	            token : textClass, // non-command
68
	            regex : "\\\\[$&%#\\{\\}]"
69
	        }, {
70
	            token : "keyword", // command
71
	            regex : "\\\\(?:documentclass|usepackage|newcounter|setcounter|addtocounter|value|arabic|stepcounter|newenvironment|renewenvironment|ref|vref|eqref|pageref|label|cite[a-zA-Z]*|tag|begin|end|bibitem)\\b",
72
               next : "nospell"
73
	        }, {
74
	            token : "keyword", // command
75
	            regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
76
	        }, {
77
               token : "paren.keyword.operator",
78
	            regex : "[[({]"
79
	        }, {
80
               token : "paren.keyword.operator",
81
	            regex : "[\\])}]"
82
	        }, {
83
	            token : textClass,
84
	            regex : "\\s+"
85
	        }
86
        ],
87
        "nospell" : [
88
           {
89
               token : "comment",
90
               regex : "%.*$",
91
               next : "start"
92
           }, {
93
               token : "nospell." + textClass, // non-command
94
               regex : "\\\\[$&%#\\{\\}]"
95
           }, {
96
               token : "keyword", // command
97
               regex : "\\\\(?:documentclass|usepackage|newcounter|setcounter|addtocounter|value|arabic|stepcounter|newenvironment|renewenvironment|ref|vref|eqref|pageref|label|cite[a-zA-Z]*|tag|begin|end|bibitem)\\b"
98
           }, {
99
               token : "keyword", // command
100
               regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
101
               next : "start"
102
           }, {
103
               token : "paren.keyword.operator",
104
               regex : "[[({]"
105
           }, {
106
               token : "paren.keyword.operator",
107
               regex : "[\\])]"
108
           }, {
109
               token : "paren.keyword.operator",
110
               regex : "}",
111
               next : "start"
112
           }, {
113
               token : "nospell." + textClass,
114
               regex : "\\s+"
115
           }, {
116
               token : "nospell." + textClass,
117
               regex : "\\w+"
118
           }
119
        ]
120
    };
121
};
122
123
oop.inherits(TexHighlightRules, TextHighlightRules);
124
125
exports.TexHighlightRules = TexHighlightRules;
126
});
127
128
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
129
130
131
var Range = require("../range").Range;
132
133
var MatchingBraceOutdent = function() {};
134
135
(function() {
136
137
    this.checkOutdent = function(line, input) {
138
        if (! /^\s+$/.test(line))
139
            return false;
140
141
        return /^\s*\}/.test(input);
142
    };
143
144
    this.autoOutdent = function(doc, row) {
145
        var line = doc.getLine(row);
146
        var match = line.match(/^(\s*\})/);
147
148
        if (!match) return 0;
149
150
        var column = match[1].length;
151
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
152
153
        if (!openBracePos || openBracePos.row == row) return 0;
154
155
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
156
        doc.replace(new Range(row, 0, row, column-1), indent);
157
    };
158
159
    this.$getIndent = function(line) {
160
        return line.match(/^\s*/)[0];
161
    };
162
163
}).call(MatchingBraceOutdent.prototype);
164
165
exports.MatchingBraceOutdent = MatchingBraceOutdent;
166
});