[gedit] Changed environment variables to match external tools
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Subject: [gedit] Changed environment variables to match external tools
- Date: Fri, 22 May 2009 17:32:16 -0400 (EDT)
commit 3ad296abc4f048b2390e52c6cfc7b8c1f1c96f0f
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Fri May 22 23:29:43 2009 +0200
Changed environment variables to match external tools
Present variables are:
GEDIT_CURRENT_DOCUMENT_URI
GEDIT_CURRENT_DOCUMENT_NAME
GEDIT_CURRENT_DOCUMENT_SCHEME
GEDIT_CURRENT_DOCUMENT_PATH
GEDIT_CURRENT_DOCUMENT_DIR
GEDIT_CURRENT_DOCUMENT_TYPE
GEDIT_DOCUMENTS_URI
GEDIT_DOCUMENTS_PATH
GEDIT_CURRENT_WORD
GEDIT_CURRENT_LINE
GEDIT_SELECTED_TEXT
GEDIT_CURRENT_LINE_NUMBER
---
plugins/snippets/snippets/Document.py | 75 ++++++++++++++++++++++++++++++---
1 files changed, 69 insertions(+), 6 deletions(-)
diff --git a/plugins/snippets/snippets/Document.py b/plugins/snippets/snippets/Document.py
index 222deb5..16167d4 100644
--- a/plugins/snippets/snippets/Document.py
+++ b/plugins/snippets/snippets/Document.py
@@ -344,31 +344,94 @@ class Document:
start, end = buffer_line_boundary(buf)
return buf.get_text(start, end)
+
+ def env_get_current_line_number(self, buf):
+ start, end = buffer_line_boundary(buf)
- def env_get_filename(self, buf):
+ return str(start.get_line() + 1)
+
+ def env_get_document_uri(self, buf):
uri = buf.get_uri()
if uri:
- return buf.get_uri_for_display()
+ return uri
else:
return ''
- def env_get_basename(self, buf):
+ def env_get_document_name(self, buf):
+ uri = buf.get_uri()
+
+ if uri:
+ return os.path.basename(uri)
+ else:
+ return ''
+
+ def env_get_document_scheme(self, buf):
uri = buf.get_uri()
if uri:
- return os.path.basename(buf.get_uri_for_display())
+ return gio.File(uri).get_uri_scheme()
+ else:
+ return ''
+
+ def env_get_document_path(self, buf):
+ uri = buf.get_uri()
+
+ if uri and gedit.utils.uri_has_file_scheme(uri):
+ return gio.File(uri).get_path()
else:
return ''
+ def env_get_document_dir(self, buf):
+ uri = buf.get_uri()
+
+ if uri and gedit.utils.uri_has_file_scheme(uri):
+ return os.path.dirname(gio.File(uri).get_path())
+ else:
+ return ''
+
+ def env_get_document_type(self, buf):
+ typ = buf.get_mime_type()
+
+ if typ:
+ return typ
+ else:
+ return ''
+
+ def env_get_documents_uri(self, buf):
+ documents_uri = [doc.get_uri()
+ for doc in self.view.get_toplevel().get_documents()
+ if doc.get_uri() is not None]
+
+ return ' '.join(documents_uri)
+
+ def env_get_documents_path(self, buf):
+ documents_uri = [doc.get_uri()
+ for doc in self.view.get_toplevel().get_documents()
+ if doc.get_uri() is not None]
+
+ documents_path = [gio.File(uri).get_path()
+ for uri in documents_uri
+ if gedit.utils.uri_has_file_scheme(uri)]
+
+ return ' '.join(documents_path)
+
def update_environment(self):
buf = self.view.get_buffer()
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}
+ 'GEDIT_CURRENT_LINE_NUMBER': self.env_get_current_line_number,
+ 'GEDIT_CURRENT_DOCUMENT_URI': self.env_get_document_uri,
+ 'GEDIT_CURRENT_DOCUMENT_NAME': self.env_get_document_name,
+ 'GEDIT_CURRENT_DOCUMENT_SCHEME': self.env_get_document_scheme,
+ 'GEDIT_CURRENT_DOCUMENT_PATH': self.env_get_document_path,
+ 'GEDIT_CURRENT_DOCUMENT_DIR': self.env_get_document_dir,
+ 'GEDIT_CURRENT_DOCUMENT_TYPE': self.env_get_document_type,
+ 'GEDIT_DOCUMENTS_URI': self.env_get_documents_uri,
+ 'GEDIT_DOCUMENTS_PATH': self.env_get_documents_path,
+ }
for var in variables:
os.environ[var] = variables[var](buf)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]