Tuesday, September 11, 2012

Reference Style Links Numbers

Hello all,

I am trying to write a script in Vim that does the same thing as this Python script written by Dr Drang (www do leancrew dot com) and gets the next number of a reference link in markdown:

#!/usr/bin/python

import sys
import re

text = sys.stdin.read()
reflinks = re.findall(r'^\[(\d+)\]: ', text, re.MULTILINE)
if len(reflinks) == 0:
print 1
else:
print max(int(x) for x in reflinks) + 1

I have looked into quicklists etc. and have check out some footnote scripts written in Vimscript but I'm stumped (I am very much a beginner). Could someone suggest a way that this might be done in Vimscript or, failing that, a way to incorporate the good doctors script into Vim using the python << approach?

I have tried the following to no avail:

function! GetRefLinkNumber()
python << EOF
import vim
import re
reflinks = re.findall(r'^\[(\d+)\]: ', vim.current.buffer, re.MULTILINE)
if len(reflinks) == 0:
return 1
else:
return max(int(x) for x in reflinks) + 1
EOF
endfunction

Many thanks for any help you can provide.

Simon.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: