Get the word under the cursor returning the start and end positions.
771057
def word_at_position(self, position):
        """"""
        if position['line'] >= len(self.lines):
            return ''

        line = self.lines[position['line']]
        i = position['character']
        # Split word in two
        start = line[:i]
        end = line[i:]

        # Take end of start and start of end to find word
        # These are guaranteed to match, even if they match the empty string
        m_start = RE_START_WORD.findall(start)
        m_end = RE_END_WORD.findall(end)

        return m_start[0] + m_end[-1]
1257924
function findWord(cm, lineNum, pos, dir, regexps) {
    var line = cm.getLine(lineNum);
    while (true) {
      var stop = (dir > 0) ? line.length : -1;
      var wordStart = stop, wordEnd = stop;
      // Find bounds of next word.
      for (; pos != stop; pos += dir) {
        for (var i = 0; i < regexps.length; ++i) {
          if (regexps[i].test(line.charAt(pos))) {
            wordStart = pos;
            // Advance to end of word.
            for (; pos != stop && regexps[i].test(line.charAt(pos)); pos += dir) {}
            wordEnd = (dir > 0) ? pos : pos + 1;
            return {
                from: Math.min(wordStart, wordEnd),
                to: Math.max(wordStart, wordEnd),
                line: lineNum};
          }
        }
      }
      // Advance to next/prev line.
      lineNum += dir;
      if (!isLine(cm, lineNum)) return null;
      line = cm.getLine(lineNum);
      pos = (dir > 0) ? 0 : line.length;
    }
  }
348048
def find_start_of_previous_word(self, count=1, WORD=False):
        
        # Reverse the text before the cursor, in order to do an efficient
        # backwards search.
        text_before_cursor = self.text_before_cursor[::-1]

        regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE
        iterator = regex.finditer(text_before_cursor)

        try:
            for i, match in enumerate(iterator):
                if i + 1 == count:
                    return - match.end(1)
        except StopIteration:
            pass
218513
private int findCodeBlockEnd(TextCursor cursor, int blockStart) {
        int offset = blockStart + 3;
        int index;
        while ((index = cursor.text.indexOf(CODE_BLOCK, offset)) >= 0) {
            if (isGoodAnchor(cursor.text, index + 3)) {
                return index + 3;
            }
            offset = index + 1;
        }
        return -1;
    }
1372955
def get_position(self, subject):
        """"""
        cursor = self.textCursor()
        if subject == 'cursor':
            pass
        elif subject == 'sol':
            cursor.movePosition(QTextCursor.StartOfBlock)
        elif subject == 'eol':
            cursor.movePosition(QTextCursor.EndOfBlock)
        elif subject == 'eof':
            cursor.movePosition(QTextCursor.End)
        elif subject == 'sof':
            cursor.movePosition(QTextCursor.Start)
        else:
            # Assuming that input argument was already a position
            return subject
        return cursor.position()
342482
def current_position(self):
        """"""
        token = self.tokenizer.peek(0)
        if token:
            return token.start, token.end

        return self.tokenizer.position, self.tokenizer.position + 1
1276589
def getobj(txt, last=False):
    """"""
    txt_end = ""
    for startchar, endchar in ["[]", "()"]:
        if txt.endswith(endchar):
            pos = txt.rfind(startchar)
            if pos:
                txt_end = txt[pos:]
                txt = txt[:pos]
    tokens = re.split(SYMBOLS, txt)
    token = None
    try:
        while token is None or re.match(SYMBOLS, token):
            token = tokens.pop()
        if token.endswith('.'):
            token = token[:-1]
        if token.startswith('.'):
            # Invalid object name
            return None
        if last:
            #XXX: remove this statement as well as the "last" argument
            token += txt[ txt.rfind(token) + len(token) ]
        token += txt_end
        if token:
            return token
    except IndexError:
        return None
687351
def _mid(string, start, end=None):
    
    if end is None:
        end = len(string)
    return string[start:start + end]
327356
def beginning_of_line(event):
    "  "
    buff = event.current_buffer
    buff.cursor_position += buff.document.get_start_of_line_position(after_whitespace=False)
826862
def positions(self, word):
        
        right = len(word) - self.right
        return [i for i in self.hd.positions(word) if self.left <= i <= right]
1263552
def word_under_cursor line=text(), pos=@curpos, delim=" "
      line ||= text()
      pos ||= @curpos
      # if pressed on a space, try to go to next word to make easier 2013-03-24
      if line[pos,1] == delim
        while line[pos,1] == delim
          pos += 1
        end
      end
      finish = line.index(delim, pos)
      start = line.rindex(delim,pos)
      finish = -1 if finish.nil?
      start = 0 if start.nil?
      return line[start..finish]
    end
836196
def find_boundaries_of_current_word(self, WORD=False, include_leading_whitespace=False,
                                        include_trailing_whitespace=False):
        
        text_before_cursor = self.current_line_before_cursor[::-1]
        text_after_cursor = self.current_line_after_cursor

        def get_regex(include_whitespace):
            return {
                (False, False): _FIND_CURRENT_WORD_RE,
                (False, True): _FIND_CURRENT_WORD_INCLUDE_TRAILING_WHITESPACE_RE,
                (True, False): _FIND_CURRENT_BIG_WORD_RE,
                (True, True): _FIND_CURRENT_BIG_WORD_INCLUDE_TRAILING_WHITESPACE_RE,
            }[(WORD, include_whitespace)]

        match_before = get_regex(include_leading_whitespace).search(text_before_cursor)
        match_after = get_regex(include_trailing_whitespace).search(text_after_cursor)

        # When there is a match before and after, and we're not looking for
        # WORDs, make sure that both the part before and after the cursor are
        # either in the [a-zA-Z_] alphabet or not. Otherwise, drop the part
        # before the cursor.
        if not WORD and match_before and match_after:
            c1 = self.text[self.cursor_position - 1]
            c2 = self.text[self.cursor_position]
            alphabet = string.ascii_letters + '0123456789_'

            if (c1 in alphabet) != (c2 in alphabet):
                match_before = None

        return (
            - match_before.end(1) if match_before else 0,
            match_after.end(1) if match_after else 0
        )
262790
def find_previous_word_ending(self, count=1, WORD=False):
        
        if count < 0:
            return self.find_next_word_ending(count=-count, WORD=WORD)

        text_before_cursor = self.text_after_cursor[:1] + self.text_before_cursor[::-1]

        regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE
        iterator = regex.finditer(text_before_cursor)

        try:
            for i, match in enumerate(iterator):
                # Take first match, unless it's the word on which we're right now.
                if i == 0 and match.start(1) == 0:
                    count += 1

                if i + 1 == count:
                    return -match.start(1) + 1
        except StopIteration:
            pass
610530
function(word, place_cursor_after_word) {
        var $inp = this.$('.inp'),
            inp_val = $inp.val(),
            caret_pos = $inp[0].selectionStart;

        // If we have the trailing ': ' after nicks, we need to check further back to find
        // the start of the current word
        var trailing_found = inp_val.substr(caret_pos-2, 2) === ': ';

        var word_start_pos = inp_val.lastIndexOf(' ', caret_pos - (trailing_found ? 2 : 1));
        word_start_pos = (word_start_pos === -1) ? 0 : word_start_pos + 1; // If no space found, start from 0. Otherwise, add 1 to include the space
        var word_end_pos = inp_val.indexOf(' ', word_start_pos);
        if (word_end_pos === -1) word_end_pos = inp_val.length;

        var start_of_inp = inp_val.substr(0, word_start_pos); // Get text before current selected word
        var rest_of_inp = inp_val.substr(word_end_pos); // Get text after current selected word
        var new_val = start_of_inp + word + rest_of_inp; // Join strings before word, the new word, and after word

        $inp.val(new_val);

        // Set the cursor to the same posiiton of the current word as was previous
        var new_position = word_start_pos + this.autocomplete.matching_against_word.length;
        if (place_cursor_after_word) {
            new_position = word_start_pos + word.length;
        }

        // Move the cursor position to the new position
        if ($inp[0].setSelectionRange) {
            $inp[0].setSelectionRange(new_position, new_position);
        } else if ($inp[0].createTextRange) { // IE8 support
            range = $inp[0].createTextRange();
            range.collapse(true);
            range.moveEnd('character', new_position);
            range.moveStart('character', new_position);
            range.select();
        }
    }
1297537
def forward_word(event):
    
    buff = event.current_buffer
    pos = buff.document.find_next_word_ending(count=event.arg)

    if pos:
        buff.cursor_position += pos
594198
public static int findWordStart(String text, int pos, String noWordSep) {
        return findWordStart(text, pos, noWordSep, true, false);
    }
85142
def get_dword_from_offset(self, offset):
        """"""

        if offset+4 > len(self.__data__):
            return None

        return self.get_dword_from_data(self.__data__[offset:offset+4], 0)