]>
code.delx.au - dotfiles/blob - .vim/abbrs2vim.py
3 import time
, os
, os
.path
, sys
5 # To override the defaults, set these variables
9 macros
["YDATE"] = lambda: time
.strftime("%Y-%m-%d")
10 macros
["YEAR"] = lambda: time
.strftime("%Y")
11 macros
["EMAIL"] = lambda: EMAIL
or os
.environ
.get("EMAIL", "~/.vim/abbrs2vim.py")
14 vimdir
= os
.path
.join(os
.environ
.get("HOME"), ".vim")
16 outfilename
= os
.path
.join(vimdir
, "abbrsout.vim")
17 outfile
= open(outfilename
, "w")
19 print >> sys
.stderr
, "Couldn't open output file for writing: %s" % outfilename
22 abbrsdir
= os
.path
.join(vimdir
, "abbrs")
23 if not os
.path
.isdir(abbrsdir
):
24 print >> sys
.stderr
, "Could not find directory with abbreviations: %s" % abbrsdir
27 for abbrfile
in os
.listdir(abbrsdir
):
28 abbr
= open(os
.path
.join(abbrsdir
, abbrfile
), "r").read()
29 for macro
in macros
.keys():
30 if abbr
.find(macro
) >= 0:
31 abbr
= abbr
.replace(macro
, macros
[macro
]())
32 abbr
= abbr
.replace("\n", "\r")
33 # Put into paste mode and take out of paste mode
34 abbr
= "iab %s \x1b:set paste\ri%s\x1b:set nopaste\r" % (abbrfile
.rsplit('.', 1)[0], abbr
)
35 if abbr
.find("___") >= 0:
36 # Then search for ___ to place the cursor there
37 abbr
+= "gg\r/___\x1b:nohlsearch\n"
39 # Leave the cursor in insert mode