0
Gedit 3プラグインを作成しようとしていますが、現在のカーソルの下にある単語を取得して修正したいところです。私は既存のプラグインを見てみましたが、同様のことをしているものは見つかりませんでした。カーソル以下の単語を取得してPython Geditプラグインで更新する方法
助けがあれば助かります。 gedit-improving-pluginsのラインツールのプラグインに基づいてコードに続いて
Gedit 3プラグインを作成しようとしていますが、現在のカーソルの下にある単語を取得して修正したいところです。私は既存のプラグインを見てみましたが、同様のことをしているものは見つかりませんでした。カーソル以下の単語を取得してPython Geditプラグインで更新する方法
助けがあれば助かります。 gedit-improving-pluginsのラインツールのプラグインに基づいてコードに続いて
、選択されたワードこの後
# help functions
def valid_text(start, end):
if not start or not end:
return False
if start.get_line_offset() > end.get_line_offset():
(start, end) = (end, start) # swap
text = doc.get_text(start, end, False)
for char in text:
if not re.match("\w", char):
return False
return True
def increment(index, incr):
newindex = index.copy()
newindex.set_line_offset(index.get_line_offset() + incr)
return newindex
def find_word_bound(index, step):
condition = lambda x: not index.get_line_offset() == 0 if step < 0 else lambda x: not x.ends_line()
while condition(index):
newindex = increment(index, step)
# newindex contains word?
if not valid_text(newindex, index):
break
# save new index
index = newindex
return index
# get vars
cursor = doc.get_iter_at_mark(doc.get_insert())
start = find_word_bound(cursor, -1)
end = find_word_bound(cursor, +1)
word = doc.get_text(start, end, False)
を取得し、あなたはそれを削除して(doc.delete(begin, end)
)の単語を変更することができ、カーソル(doc.place_cursor(place)
)を設定し、新しい単語をカーソルに挿入する(doc.insert_at_cursor(str)
)