1
# -*- coding: utf-8 -*-
2
# Copyright © 2005 Lateef Alabi-Oki
4
# This file is part of Scribes.
6
# Scribes is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# Scribes is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Scribes; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22
This module documents functions that perform paragraph operations.
24
@author: Lateef Alabi-Oki
25
@organization: The Scribes Project
26
@copyright: Copyright © 2005 Lateef Alabi-Oki
27
@license: GNU GPLv2 or Later
28
@contact: mystilleef@gmail.com
31
def select_paragraph(textbuffer):
33
Select a paragraph, if any, on the current line.
35
@param textbuffer: The text buffer in which to select a paragraph.
36
@type textbuffer: A gtk.TextBuffer object.
38
@return: Return True if a paragraph was selected.
39
@rtype: A Boolean object.
41
from SCRIBES.cursor import get_cursor_iterator
42
cursor_position = get_cursor_iterator(textbuffer)
43
if cursor_position.starts_sentence() or cursor_position.ends_sentence() or cursor_position.inside_sentence():
44
end_position = cursor_position.copy()
45
if cursor_position.backward_line():
46
while not cursor_position.get_char() in ["\n", "\x00"]:
47
result = cursor_position.backward_line()
50
if cursor_position.get_char() in ["\n", "\x00"]:
51
cursor_position.forward_line()
53
cursor_position.backward_sentence_start()
54
if end_position.forward_line():
55
while not end_position.get_char() in ["\n", "\x00"]:
56
result = end_position.forward_line()
59
if end_position.get_char() in ["\n", "\x00"]:
60
end_position.backward_line()
61
end_position.forward_sentence_end()
63
end_position.forward_sentence_end()
64
textbuffer.select_range(cursor_position, end_position)