1 import string, vim, re, os, glob
2 # catFile: assigns a local variable retval to the contents of a file {{{
6 lines = ''.join(file.readlines())
11 # escape double quotes and backslashes before quoting the string so
12 # everything passes throught.
13 vim.command("""let retval = "%s" """ % re.sub(r'"|\\', r'\\\g<0>', lines))
17 # isPresentInFile: check if regexp is present in the file {{{
18 def isPresentInFile(regexp, filename):
21 fcontents = string.join(fp.readlines(), '')
23 if re.search(regexp, fcontents):
24 vim.command('let retval = 1')
27 vim.command('let retval = 0')
30 vim.command('let retval = 0')
34 # deleteFile: deletes a file if present {{{
35 # If the file does not exist, check if its a filepattern rather than a
36 # filename. If its a pattern, then deletes all files matching the
38 def deleteFile(filepattern):
39 if os.path.exists(filepattern):
41 os.remove(filepattern)
43 vim.command('let retval = -1')
45 if glob.glob(filepattern):
46 for filename in glob.glob(filepattern):
49 vim.command('let retval = -1')
52 # vim:fdm=marker:ff=unix:noet:ts=4:sw=4:nowrap