[gedit] Implemented GEDIT_CURRENT_LINE environment variable
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Subject: [gedit] Implemented GEDIT_CURRENT_LINE environment variable
- Date: Sun, 10 May 2009 17:05:31 -0400 (EDT)
commit 1ca6df0d04e490e15127b666039b1bc2f6a0a39f
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Sun May 10 23:05:21 2009 +0200
Implemented GEDIT_CURRENT_LINE environment variable
This variable has the same special characteristics as GEDIT_CURRENT_WORD. So
if there is no selection, the line will be selected and replaced by the placeholder.
---
plugins/snippets/snippets/Document.py | 20 ++++++++++++++++++++
plugins/snippets/snippets/Helper.py | 8 ++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/plugins/snippets/snippets/Document.py b/plugins/snippets/snippets/Document.py
index 61ed1cb..222deb5 100644
--- a/plugins/snippets/snippets/Document.py
+++ b/plugins/snippets/snippets/Document.py
@@ -339,6 +339,11 @@ class Document:
start, end = buffer_word_boundary(buf)
return buf.get_text(start, end)
+
+ def env_get_current_line(self, buf):
+ start, end = buffer_line_boundary(buf)
+
+ return buf.get_text(start, end)
def env_get_filename(self, buf):
uri = buf.get_uri()
@@ -361,6 +366,7 @@ class Document:
variables = {'GEDIT_SELECTED_TEXT': self.env_get_selected_text,
'GEDIT_CURRENT_WORD': self.env_get_current_word,
+ 'GEDIT_CURRENT_LINE': self.env_get_current_line,
'GEDIT_FILENAME': self.env_get_filename,
'GEDIT_BASENAME': self.env_get_basename}
@@ -375,6 +381,15 @@ class Document:
return True
return False
+
+ def uses_current_line(self, snippet):
+ matches = re.findall('(\\\\*)\\$GEDIT_CURRENT_LINE', snippet['text'])
+
+ for match in matches:
+ if len(match) % 2 == 0:
+ return True
+
+ return False
def apply_snippet(self, snippet, start = None, end = None):
if not snippet.valid:
@@ -394,6 +409,11 @@ class Document:
# the current word. Set start and end to the word boundary so that
# it will be removed
start, end = buffer_word_boundary(buf)
+ elif start.equal(end) and self.uses_current_line(s):
+ # There is no tab trigger and no selection and the snippet uses
+ # the current line. Set start and end to the line boundary so that
+ # it will be removed
+ start, end = buffer_line_boundary(buf)
# Set environmental variables
self.update_environment()
diff --git a/plugins/snippets/snippets/Helper.py b/plugins/snippets/snippets/Helper.py
index 3847c39..1908527 100644
--- a/plugins/snippets/snippets/Helper.py
+++ b/plugins/snippets/snippets/Helper.py
@@ -159,6 +159,14 @@ def buffer_word_boundary(buf):
return (start, iter)
+def buffer_line_boundary(buf):
+ iter = buf.get_iter_at_mark(buf.get_insert())
+ start = iter.copy()
+ start.set_line_offset(0)
+ iter.forward_to_line_end()
+
+ return (start, iter)
+
def drop_get_uris(selection):
lines = re.split('\\s*[\\n\\r]+\\s*', selection.data.strip())
result = []
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]