1 # sced (SuperCollider mode for gedit)
3 # Copyright 2012 Jakob Leben
4 # Copyright 2009 Artem Popov and other contributors (see AUTHORS)
6 # sced is free software:
7 # you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 def is_block_beginning(s
):
21 s
= "".join(s
.split())
22 # FIXME: clarify this later
23 if s
== "(" or s
.startswith("(//") or s
.startswith("(/*"):
28 def find_block(doc
, where
=None):
30 i1
= doc
.get_iter_at_mark(doc
.get_insert())
34 # move backward until a block beginning is found
39 i2
.forward_to_line_end()
41 if is_block_beginning(doc
.get_text(i1
, i2
)):
44 if not i1
.backward_line():
45 raise RuntimeError("Couldn't find where code block starts!")
53 # move forward to the end of the block
55 if not i2
.forward_char():
56 raise RuntimeError("Couldn't find where code block ends!")
70 elif char
== "\n" and line_comment
:
73 if not block_comment
and not line_comment
:
82 # XXX: include 2 more characters just in case "where" is near the end
85 if where
.in_range(i1
, i2
):
88 raise RuntimeError("Couldn't find code block!")
95 if re
.match("[A-Za-z0-9_]", c
):
99 def find_word(doc
, where
=None):
101 i1
= doc
.get_iter_at_mark(doc
.get_insert())
105 i1
.backward_find_char(scpred
)
106 i1
.forward_char() # <-- FIXME: forward should not normally be required
109 i2
.forward_find_char(scpred
)