summaryrefslogtreecommitdiff
path: root/src/vim-latex/ftplugin/latex-suite/pytools.py
diff options
context:
space:
mode:
authorDavid Kaufmann <astra@fsinf.at>2011-11-14 02:04:57 +0100
committerDavid Kaufmann <astra@fsinf.at>2011-11-14 02:05:03 +0100
commitd14e32945633316b352efec22a1ab4ffd00cb618 (patch)
tree353b04d57ab9134d1f546440395d75754a69542f /src/vim-latex/ftplugin/latex-suite/pytools.py
parenta76ddbccedbd9873342629d07fdb0cd8ba536cc0 (diff)
downloadconfig-d14e32945633316b352efec22a1ab4ffd00cb618.tar.gz
moved sources to src
Diffstat (limited to 'src/vim-latex/ftplugin/latex-suite/pytools.py')
-rw-r--r--src/vim-latex/ftplugin/latex-suite/pytools.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/vim-latex/ftplugin/latex-suite/pytools.py b/src/vim-latex/ftplugin/latex-suite/pytools.py
new file mode 100644
index 0000000..1934e23
--- /dev/null
+++ b/src/vim-latex/ftplugin/latex-suite/pytools.py
@@ -0,0 +1,52 @@
+import string, vim, re, os, glob
+# catFile: assigns a local variable retval to the contents of a file {{{
+def catFile(filename):
+ try:
+ file = open(filename)
+ lines = ''.join(file.readlines())
+ file.close()
+ except:
+ lines = ''
+
+ # escape double quotes and backslashes before quoting the string so
+ # everything passes throught.
+ vim.command("""let retval = "%s" """ % re.sub(r'"|\\', r'\\\g<0>', lines))
+ return lines
+
+# }}}
+# isPresentInFile: check if regexp is present in the file {{{
+def isPresentInFile(regexp, filename):
+ try:
+ fp = open(filename)
+ fcontents = string.join(fp.readlines(), '')
+ fp.close()
+ if re.search(regexp, fcontents):
+ vim.command('let retval = 1')
+ return 1
+ else:
+ vim.command('let retval = 0')
+ return None
+ except:
+ vim.command('let retval = 0')
+ return None
+
+# }}}
+# deleteFile: deletes a file if present {{{
+# If the file does not exist, check if its a filepattern rather than a
+# filename. If its a pattern, then deletes all files matching the
+# pattern.
+def deleteFile(filepattern):
+ if os.path.exists(filepattern):
+ try:
+ os.remove(filepattern)
+ except:
+ vim.command('let retval = -1')
+ else:
+ if glob.glob(filepattern):
+ for filename in glob.glob(filepattern):
+ os.remove(filename)
+ else:
+ vim.command('let retval = -1')
+
+# }}}
+# vim:fdm=marker:ff=unix:noet:ts=4:sw=4:nowrap