正規表現に応じて特定の単語に変更を加えるGeditのプラグインを作成しています。場合によっては、これは意図した単語を超えてタグを数文字適用しています。
したがって、match.start()およびmatch.end()によって返される値は、get_iter_at_offsetでの使用には無効です。
def on_save(self, doc, location, *args, **kwargs):
"""called when document is saved"""
for match in WORD_RE.finditer(get_text(doc)):
if not self._checker.check(match.group().strip()):
self.apply_tag(doc, match.start(), match.end())
def apply_tag(self, doc, start, end):
"""apply the tag to the text between start and end"""
istart = doc.get_iter_at_offset(start)
iend = doc.get_iter_at_offset(end)
doc.apply_tag(self._spell_error_tag, istart, iend)