corrade-nucleus-nucleons – Blame information for rev 20
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | define("ace/ext/whitespace",["require","exports","module","ace/lib/lang"], function(require, exports, module) { |
2 | "use strict"; |
||
3 | |||
4 | var lang = require("../lib/lang"); |
||
5 | exports.$detectIndentation = function(lines, fallback) { |
||
6 | var stats = []; |
||
7 | var changes = []; |
||
8 | var tabIndents = 0; |
||
9 | var prevSpaces = 0; |
||
10 | var max = Math.min(lines.length, 1000); |
||
11 | for (var i = 0; i < max; i++) { |
||
12 | var line = lines[i]; |
||
13 | if (!/^\s*[^*+\-\s]/.test(line)) |
||
14 | continue; |
||
15 | |||
16 | if (line[0] == "\t") { |
||
17 | tabIndents++; |
||
18 | prevSpaces = -Number.MAX_VALUE; |
||
19 | } else { |
||
20 | var spaces = line.match(/^ */)[0].length; |
||
21 | if (spaces && line[spaces] != "\t") { |
||
22 | var diff = spaces - prevSpaces; |
||
23 | if (diff > 0 && !(prevSpaces%diff) && !(spaces%diff)) |
||
24 | changes[diff] = (changes[diff] || 0) + 1; |
||
25 | |||
26 | stats[spaces] = (stats[spaces] || 0) + 1; |
||
27 | } |
||
28 | prevSpaces = spaces; |
||
29 | } |
||
30 | while (i < max && line[line.length - 1] == "\\") |
||
31 | line = lines[i++]; |
||
32 | } |
||
33 | |||
34 | function getScore(indent) { |
||
35 | var score = 0; |
||
36 | for (var i = indent; i < stats.length; i += indent) |
||
37 | score += stats[i] || 0; |
||
38 | return score; |
||
39 | } |
||
40 | |||
41 | var changesTotal = changes.reduce(function(a,b){return a+b}, 0); |
||
42 | |||
43 | var first = {score: 0, length: 0}; |
||
44 | var spaceIndents = 0; |
||
45 | for (var i = 1; i < 12; i++) { |
||
46 | var score = getScore(i); |
||
47 | if (i == 1) { |
||
48 | spaceIndents = score; |
||
49 | score = stats[1] ? 0.9 : 0.8; |
||
50 | if (!stats.length) |
||
51 | score = 0; |
||
52 | } else |
||
53 | score /= spaceIndents; |
||
54 | |||
55 | if (changes[i]) |
||
56 | score += changes[i] / changesTotal; |
||
57 | |||
58 | if (score > first.score) |
||
59 | first = {score: score, length: i}; |
||
60 | } |
||
61 | |||
62 | if (first.score && first.score > 1.4) |
||
63 | var tabLength = first.length; |
||
64 | |||
65 | if (tabIndents > spaceIndents + 1) { |
||
66 | if (tabLength == 1 || spaceIndents < tabIndents / 4 || first.score < 1.8)> |
||
67 | < 1.8) tabLength = undefined;> |
||
68 | < 1.8) return {ch: "\t", length: tabLength};> |
||
69 | < 1.8) }> |
||
70 | < 1.8) if (spaceIndents > tabIndents + 1)> |
||
71 | < 1.8) return {ch: " ", length: tabLength};> |
||
72 | < 1.8)};> |
||
73 | |||
74 | < 1.8)exports.detectIndentation = function(session) {> |
||
75 | < 1.8) var lines = session.getLines(0, 1000);> |
||
76 | < 1.8) var indent = exports.$detectIndentation(lines) || {};> |
||
77 | |||
78 | < 1.8) if (indent.ch)> |
||
79 | < 1.8) session.setUseSoftTabs(indent.ch == " ");> |
||
80 | |||
81 | < 1.8) if (indent.length)> |
||
82 | < 1.8) session.setTabSize(indent.length);> |
||
83 | < 1.8) return indent;> |
||
84 | < 1.8)};> |
||
85 | |||
86 | < 1.8)exports.trimTrailingSpace = function(session, trimEmpty) {> |
||
87 | < 1.8) var doc = session.getDocument();> |
||
88 | < 1.8) var lines = doc.getAllLines();> |
||
89 | |||
90 | < 1.8) var min = trimEmpty ? -1 : 0;> |
||
91 | |||
92 | < 1.8) for (var i = 0, l=lines.length; i < l; i++) {>> |
||
93 | < 1.8)< l; i++) { var line = lines[i];>> |
||
94 | < 1.8)< l; i++) { var index = line.search(/\s+$/);>> |
||
95 | |||
96 | < 1.8)< l; i++) { if (index > min)>> |
||
97 | < 1.8)< l; i++) { doc.removeInLine(i, index, line.length);>> |
||
98 | < 1.8)< l; i++) { }>> |
||
99 | < 1.8)< l; i++) {};>> |
||
100 | |||
101 | < 1.8)< l; i++) {exports.convertIndentation = function(session, ch, len) {>> |
||
102 | < 1.8)< l; i++) { var oldCh = session.getTabString()[0];>> |
||
103 | < 1.8)< l; i++) { var oldLen = session.getTabSize();>> |
||
104 | < 1.8)< l; i++) { if (!len) len = oldLen;>> |
||
105 | < 1.8)< l; i++) { if (!ch) ch = oldCh;>> |
||
106 | |||
107 | < 1.8)< l; i++) { var tab = ch == "\t" ? ch: lang.stringRepeat(ch, len);>> |
||
108 | |||
109 | < 1.8)< l; i++) { var doc = session.doc;>> |
||
110 | < 1.8)< l; i++) { var lines = doc.getAllLines();>> |
||
111 | |||
112 | < 1.8)< l; i++) { var cache = {};>> |
||
113 | < 1.8)< l; i++) { var spaceCache = {};>> |
||
114 | < 1.8)< l; i++) { for (var i = 0, l=lines.length; i < l; i++) {>>> |
||
115 | < 1.8)< l; i++) {< l; i++) { var line = lines[i];>>> |
||
116 | < 1.8)< l; i++) {< l; i++) { var match = line.match(/^\s*/)[0];>>> |
||
117 | < 1.8)< l; i++) {< l; i++) { if (match) {>>> |
||
118 | < 1.8)< l; i++) {< l; i++) { var w = session.$getStringScreenWidth(match)[0];>>> |
||
119 | < 1.8)< l; i++) {< l; i++) { var tabCount = Math.floor(w/oldLen);>>> |
||
120 | < 1.8)< l; i++) {< l; i++) { var reminder = w%oldLen;>>> |
||
121 | < 1.8)< l; i++) {< l; i++) { var toInsert = cache[tabCount] || (cache[tabCount] = lang.stringRepeat(tab, tabCount));>>> |
||
122 | < 1.8)< l; i++) {< l; i++) { toInsert += spaceCache[reminder] || (spaceCache[reminder] = lang.stringRepeat(" ", reminder));>>> |
||
123 | |||
124 | < 1.8)< l; i++) {< l; i++) { if (toInsert != match) {>>> |
||
125 | < 1.8)< l; i++) {< l; i++) { doc.removeInLine(i, 0, match.length);>>> |
||
126 | < 1.8)< l; i++) {< l; i++) { doc.insertInLine({row: i, column: 0}, toInsert);>>> |
||
127 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
128 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
129 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
130 | < 1.8)< l; i++) {< l; i++) { session.setTabSize(len);>>> |
||
131 | < 1.8)< l; i++) {< l; i++) { session.setUseSoftTabs(ch == " ");>>> |
||
132 | < 1.8)< l; i++) {< l; i++) {};>>> |
||
133 | |||
134 | < 1.8)< l; i++) {< l; i++) {exports.$parseStringArg = function(text) {>>> |
||
135 | < 1.8)< l; i++) {< l; i++) { var indent = {};>>> |
||
136 | < 1.8)< l; i++) {< l; i++) { if (/t/.test(text))>>> |
||
137 | < 1.8)< l; i++) {< l; i++) { indent.ch = "\t";>>> |
||
138 | < 1.8)< l; i++) {< l; i++) { else if (/s/.test(text))>>> |
||
139 | < 1.8)< l; i++) {< l; i++) { indent.ch = " ";>>> |
||
140 | < 1.8)< l; i++) {< l; i++) { var m = text.match(/\d+/);>>> |
||
141 | < 1.8)< l; i++) {< l; i++) { if (m)>>> |
||
142 | < 1.8)< l; i++) {< l; i++) { indent.length = parseInt(m[0], 10);>>> |
||
143 | < 1.8)< l; i++) {< l; i++) { return indent;>>> |
||
144 | < 1.8)< l; i++) {< l; i++) {};>>> |
||
145 | |||
146 | < 1.8)< l; i++) {< l; i++) {exports.$parseArg = function(arg) {>>> |
||
147 | < 1.8)< l; i++) {< l; i++) { if (!arg)>>> |
||
148 | < 1.8)< l; i++) {< l; i++) { return {};>>> |
||
149 | < 1.8)< l; i++) {< l; i++) { if (typeof arg == "string")>>> |
||
150 | < 1.8)< l; i++) {< l; i++) { return exports.$parseStringArg(arg);>>> |
||
151 | < 1.8)< l; i++) {< l; i++) { if (typeof arg.text == "string")>>> |
||
152 | < 1.8)< l; i++) {< l; i++) { return exports.$parseStringArg(arg.text);>>> |
||
153 | < 1.8)< l; i++) {< l; i++) { return arg;>>> |
||
154 | < 1.8)< l; i++) {< l; i++) {};>>> |
||
155 | |||
156 | < 1.8)< l; i++) {< l; i++) {exports.commands = [{>>> |
||
157 | < 1.8)< l; i++) {< l; i++) { name: "detectIndentation",>>> |
||
158 | < 1.8)< l; i++) {< l; i++) { exec: function(editor) {>>> |
||
159 | < 1.8)< l; i++) {< l; i++) { exports.detectIndentation(editor.session);>>> |
||
160 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
161 | < 1.8)< l; i++) {< l; i++) {}, {>>> |
||
162 | < 1.8)< l; i++) {< l; i++) { name: "trimTrailingSpace",>>> |
||
163 | < 1.8)< l; i++) {< l; i++) { exec: function(editor) {>>> |
||
164 | < 1.8)< l; i++) {< l; i++) { exports.trimTrailingSpace(editor.session);>>> |
||
165 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
166 | < 1.8)< l; i++) {< l; i++) {}, {>>> |
||
167 | < 1.8)< l; i++) {< l; i++) { name: "convertIndentation",>>> |
||
168 | < 1.8)< l; i++) {< l; i++) { exec: function(editor, arg) {>>> |
||
169 | < 1.8)< l; i++) {< l; i++) { var indent = exports.$parseArg(arg);>>> |
||
170 | < 1.8)< l; i++) {< l; i++) { exports.convertIndentation(editor.session, indent.ch, indent.length);>>> |
||
171 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
172 | < 1.8)< l; i++) {< l; i++) {}, {>>> |
||
173 | < 1.8)< l; i++) {< l; i++) { name: "setIndentation",>>> |
||
174 | < 1.8)< l; i++) {< l; i++) { exec: function(editor, arg) {>>> |
||
175 | < 1.8)< l; i++) {< l; i++) { var indent = exports.$parseArg(arg);>>> |
||
176 | < 1.8)< l; i++) {< l; i++) { indent.length && editor.session.setTabSize(indent.length);>>> |
||
177 | < 1.8)< l; i++) {< l; i++) { indent.ch && editor.session.setUseSoftTabs(indent.ch == " ");>>> |
||
178 | < 1.8)< l; i++) {< l; i++) { }>>> |
||
179 | < 1.8)< l; i++) {< l; i++) {}];>>> |
||
180 | |||
181 | < 1.8)< l; i++) {< l; i++) {});>>> |
||
182 | < 1.8)< l; i++) {< l; i++) { (function() {>>> |
||
183 | < 1.8)< l; i++) {< l; i++) { window.require(["ace/ext/whitespace"], function() {});>>> |
||
184 | < 1.8)< l; i++) {< l; i++) { })();>>> |
||
185 |