scratchabit: "Run plugin": Switch terminology to "plugin" from "script".
[ScratchABit.git] / utils.py
blob01511efc68562b59b7c0345d32d8786ddb001352
1 import string
4 def get_word_at_pos(str, pos):
5 if pos < 0:
6 return None
7 if pos >= len(str):
8 pos = len(str) - 1
9 word_chars = string.ascii_letters + string.digits + "._"
10 if str[pos] not in word_chars:
11 return None
12 beg = pos
13 while beg >= 1 and str[beg - 1] in word_chars:
14 beg -= 1
15 end = pos
16 while end < len(str) - 1 and str[end + 1] in word_chars:
17 end += 1
18 return str[beg:end + 1]