'Gets the region containing the current word which contains the caret
or the given selection.
The current word is defined between the nearest non-word characters to
the left and to the right of the current selected location.
Non-word characters are defined by the WORD_SEPARATOR_RX.
:param view:
the current view
:param location:
either a point or a sublime.Region that defines the caret position
or current selection'

def get_current_word(self, view, location):

    if isinstance(location, sublime.Region):
        (start, end) = (location.begin(), location.end())
    else:
        start = end = location
    start_line = view.line(start)
    end_line = view.line(end)
    line_prefix = view.substr(getRegion(start_line.begin(), start))[::(-1)]
    line_suffix = view.substr(getRegion(end, end_line.end()))
    m = self.WORD_SEPARATOR_RX.search(line_prefix)
    prefix = (m.group(1) if m else '')
    m = self.WORD_SEPARATOR_RX.search(line_suffix)
    suffix = (m.group(1) if m else '')
    return getRegion((start - len(prefix)), (end + len(suffix)))
