4
* Copyright (C) 2009-11 by RStudio, Inc.
6
* The Initial Developer of the Original Code is
8
* Portions created by the Initial Developer are Copyright (C) 2010
9
* the Initial Developer. All Rights Reserved.
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.
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) {
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;
28
var Mode = function(suppressHighlighting) {
29
if (suppressHighlighting)
30
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
32
this.$tokenizer = new Tokenizer(new TexHighlightRules().getRules());
33
this.$outdent = new MatchingBraceOutdent();
35
oop.inherits(Mode, TextMode);
38
this.getNextLineIndent = function(state, line, tab) {
39
return this.$getIndent(line);
42
this.allowAutoInsert = function() {
45
}).call(Mode.prototype);
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) {
52
var oop = require("../lib/oop");
53
var lang = require("../lib/lang");
54
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
56
var TexHighlightRules = function(textClass) {
67
token : textClass, // non-command
68
regex : "\\\\[$&%#\\{\\}]"
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",
74
token : "keyword", // command
75
regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
77
token : "paren.keyword.operator",
80
token : "paren.keyword.operator",
93
token : "nospell." + textClass, // non-command
94
regex : "\\\\[$&%#\\{\\}]"
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"
99
token : "keyword", // command
100
regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
103
token : "paren.keyword.operator",
106
token : "paren.keyword.operator",
109
token : "paren.keyword.operator",
113
token : "nospell." + textClass,
116
token : "nospell." + textClass,
123
oop.inherits(TexHighlightRules, TextHighlightRules);
125
exports.TexHighlightRules = TexHighlightRules;
128
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
131
var Range = require("../range").Range;
133
var MatchingBraceOutdent = function() {};
137
this.checkOutdent = function(line, input) {
138
if (! /^\s+$/.test(line))
141
return /^\s*\}/.test(input);
144
this.autoOutdent = function(doc, row) {
145
var line = doc.getLine(row);
146
var match = line.match(/^(\s*\})/);
148
if (!match) return 0;
150
var column = match[1].length;
151
var openBracePos = doc.findMatchingBracket({row: row, column: column});
153
if (!openBracePos || openBracePos.row == row) return 0;
155
var indent = this.$getIndent(doc.getLine(openBracePos.row));
156
doc.replace(new Range(row, 0, row, column-1), indent);
159
this.$getIndent = function(line) {
160
return line.match(/^\s*/)[0];
163
}).call(MatchingBraceOutdent.prototype);
165
exports.MatchingBraceOutdent = MatchingBraceOutdent;