本文整理汇总了Python中GPS.set_last_command方法的典型用法代码示例。如果您正苦于以下问题:Python GPS.set_last_command方法的具体用法?Python GPS.set_last_command怎么用?Python GPS.set_last_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GPS
的用法示例。
在下文中一共展示了GPS.set_last_command方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_line
# 需要导入模块: import GPS [as 别名]
# 或者: from GPS import set_last_command [as 别名]
def delete_line():
""" Remove the lines that include the current selection. If there is
no selection, remove the line at the cursor position.
"""
buffer = GPS.EditorBuffer.get()
cpos = buffer.current_view().cursor()
append = GPS.last_command() == "delete line"
if append:
GPS.set_last_command ("delete line")
start = buffer.selection_start().beginning_of_line()
end = buffer.selection_end().end_of_line()
buffer.delete (start, end)
示例2: kill_line
# 需要导入模块: import GPS [as 别名]
# 或者: from GPS import set_last_command [as 别名]
def kill_line (location = None, count=1):
""" Kills the end of the line on which LOCATION is.
If LOCATION is unspecified, the current cursor location in the current
editor is used.
If the line is empty or contains only white spaces, the whole line is
deleted.
This is a better emulation of Emacs's behavior than the one provided by
default by gtk+, which doesn't handle whitespaces correctly.
When called several times from the same line, entries are appended in
the clipboard.
Count is the number of lines to delete. If greater than 1, then the
whole lines are deleted, including newline characters."""
if not location:
location = GPS.EditorBuffer.get ().current_view ().cursor ()
buffer = location.buffer ()
start = location
append = GPS.last_command() == "kill-line"
GPS.set_last_command ("kill-line")
# In case the current location points to a line terminator we just cut it
if count == 1 and start.get_char() == "\n":
buffer.cut (start, start, append)
else:
bol = start
for line in range (1, count + 1):
end = bol.end_of_line ()
str = buffer.get_chars (start, end)
strip_str = str.rstrip ()
if count == 1 \
and len (str) > 0 \
and str [len (str) - 1] == '\n' and strip_str != "":
end = end.forward_char (-1)
bol = end+1
buffer.cut (start, end, append)