4 var WORD = /[\w$]+/, RANGE = 500;
6 CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
7 var word = options && options.word || WORD;
8 var range = options && options.range || RANGE;
9 var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
10 var start = cur.ch, end = start;
11 while (end < curLine.length && word.test(curLine.charAt(end))) ++end;
12 while (start && word.test(curLine.charAt(start - 1))) --start;
13 var curWord = start != end && curLine.slice(start, end);
15 var list = [], seen = {};
17 var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
18 for (; line != end; line += dir) {
19 var text = editor.getLine(line), m;
20 var re = new RegExp(word.source, "g");
21 while (m = re.exec(text)) {
22 if (line == cur.line && m[0] === curWord) continue;
23 if ((!curWord || m[0].indexOf(curWord) == 0) && !seen.hasOwnProperty(m[0])) {
32 return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};